我正在尝试评估与文本正文中出现的特定单词相关的情绪。目前我正在使用 IBM Watson 的目标情感分析 (natural_language_understanding.analyze)。但是,如果我有两个目标词“苹果”和“橙子”,以及句子“我喜欢苹果,但我不喜欢橙子。”,分析器将为两个目标给出相同的分数,因为程序最终使用目标来识别文本中的句子,然后提供该句子的情感。是否有一种替代方案可以提供目标级情感,而不是句子级情感,从而为“苹果”生成正数值分数,为“橙子”生成负数值分数?
我已经研究过使用IBM面向方面的情感分析页面中的sentiment-targeted_bert_multi_stock,但是,它似乎只提供情感_正向、情感_中性或情感_负向的标签作为输出。
目标级别情绪或目标情绪分析 (TSA) 可通过 Watson NLP 获得。
有一些现有的模型可以重用,基于 IBM 的 slate,例如:
import watson_nlp
# Load the model using its name
model_name = 'targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled-cpu'
tsa_model = watson_nlp.load(model_name)
# Run the model on an input text
text = "I like apples but I do not like oranges."
tsa_predictions = tsa_model.run(text)
# For visualization or further analysis, convert the output to a DataFrame
from watson_nlp.pandas.converters.sentiment import targets_sentiment_to_pandas
target_mentions = targets_sentiment_to_pandas(text, tsa_predictions)
print(target_mentions)
将输出:
Watson NLP 中 TSA 的完整文档请参阅此处。
在 IBM 产品中
TSA 可通过 IBM 的 WatsonX(请参阅此处)和 Cloud Pak for Data(请参阅此处)中的Watson Studio 获得。该文档显示在目标情绪提取下。 这些产品附带的 NLP 运行时支持两种开箱即用的 TSA 模型,一种适用于具有 GPU 的环境,另一种适用于 CPU 优化。这些模型可以在基于笔记本的环境中使用,例如使用上面的代码示例。