Sentiment Analysis with spaCy and TextBlob

  • Share this:

Code introduction


This function uses spaCy and TextBlob libraries to analyze the sentiment of a given text. It first loads the English model from spaCy, and then uses TextBlob to obtain the sentiment polarity of the text.


Technology Stack : spaCy, TextBlob

Code Type : Function

Code Difficulty : Intermediate


                
                    
def analyze_text_sentiment(text):
    import spacy
    from spacytextblob import TextBlob

    nlp = spacy.load('en_core_web_sm')
    doc = nlp(text)
    blob = TextBlob(doc.text)
    sentiment = blob.sentiment.polarity

    return sentiment                
              
Tags: