如何确定某事的 'did' 或 'did not'
How to determine 'did' or 'did not' on something
区分这两者的直接方法是什么:
the movie received critical acclaim
the movie did not attain critical acclaim
.
在我看来 'sentiment analysis' 的 nlp 可以为我做这件事。所以我使用 Textblob
sentiment analysis。但是两个句子的polarity
都是0.0
.
它需要否定处理能力。例如,wink-nlp supports negation handling. You can checkout the code with this example at runkit.
对于simple,您可以使用基于LSTM的flair模型,将单词序列考虑在内进行预测。
1.安装 flair
!pip3 install flair
2。代码
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。结果
print(s1_sentiment)
[POSITIVE (0.9995)]
print(s2_sentiment)
[NEGATIVE (0.9985)]
更多关于flair的详情,您可以访问this github repo.
区分这两者的直接方法是什么:
the movie received critical acclaim
the movie did not attain critical acclaim
.
在我看来 'sentiment analysis' 的 nlp 可以为我做这件事。所以我使用 Textblob
sentiment analysis。但是两个句子的polarity
都是0.0
.
它需要否定处理能力。例如,wink-nlp supports negation handling. You can checkout the code with this example at runkit.
对于simple,您可以使用基于LSTM的flair模型,将单词序列考虑在内进行预测。
1.安装 flair
!pip3 install flair
2。代码
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。结果
print(s1_sentiment)
[POSITIVE (0.9995)]
print(s2_sentiment)
[NEGATIVE (0.9985)]
更多关于flair的详情,您可以访问this github repo.