pythonnlpsentiment-analysistextblob

How to determine 'did' or 'did not' on something


What's the straightforward way to distinguish between this two:

  1. the movie received critical acclaim
  2. the movie did not attain critical acclaim.

Seems to me 'sentiment analysis' of nlp could do it for me. So I'm using Textblob sentiment analysis. But both sentences' polarity is 0.0.


Solution

  • For simple in your case, you can use flair which is based on LSTM model, that takes sequences of words into account for prediction.

    1. installing flair

    !pip3 install flair
    

    2. code

    import flair
    flair_sentiment = flair.models.TextClassifier.load('en-sentiment')
    
    sentence1 = 'the movie received critical acclaim'
    sentence2 = 'the movie did not attain critical acclaim'
    
    s1 = flair.data.Sentence(sentence1)
    flair_sentiment.predict(s1)
    s1_sentiment = s1.labels
    print(s1_sentiment)
    
    s2 = flair.data.Sentence(sentence2)
    flair_sentiment.predict(s2)
    s2_sentiment = s2.labels
    print(s2_sentiment)
    

    3. result

    print(s1_sentiment)
    [POSITIVE (0.9995)]
    
    print(s2_sentiment)
    [NEGATIVE (0.9985)]
    

    For more details about flair, you can visit this github repo.