问题描述
我正在尝试使用节模型预测“兴奋”,colab 笔记本和 aws ec2 API 中使用了相同的函数。当我尝试预测这个词时,我在 colab notebook 中得到了“positive”标签,在 django 的应用程序 API 中得到了“neutral”标签。
我检查了两种环境中的 Stanza 版本,并且都在使用:
Name: stanza
Version: 1.2
Summary: A Python NLP Library for Many Human Languages,by the Stanford NLP Group
Home-page: https://github.com/stanfordnlp/stanza
Author: Stanford Natural Language Processing Group
Author-email: jebolton@stanford.edu
License: Apache License 2.0
Location: /usr/local/lib/python3.7/dist-packages
Requires: numpy,requests,tqdm,torch,protobuf
required-by:
但是,我不确定是否相同的一件事是文件夹 stanza_resources(如果两者的版本相同,这应该是相同的?)。
功能:
!pip3 install stanza
import stanza
stanza.download('en',package='ewt',processors='tokenize,sentiment,pos',verbose=True)
stanza.download('en',package='default',sentiment',verbose=True)
stanza.download(lang="en",package=None,processors={"pos":"combined"})
stNLP = stanza.Pipeline(processors='tokenize,lang='en',use_gpu=True)
def stanza_predict(text):
'''
:param text: text to be predicted
:param verbose: 0 or 1. Verbosity mode. 0 = to predict text,1 = to predict labels.
:return: POSITIVE or NEGATIVE prediction
'''
data = stNLP(text)
sentiment_map = {'0': 'NEGATIVE','1': 'NEUTRAL','2': 'POSITIVE'}
#print(data)
for sentence in data.sentences:
pred_sentiment = sentence.sentiment
if pred_sentiment == 0:
pred = sentiment_map['0']
elif pred_sentiment == 1:
pred = sentiment_map['1']
elif pred_sentiment == 2:
pred = sentiment_map['2']
return pred
# Expected output (as the colab notebook):
stanza_predict('excited')
output: 'POSITIVE'
具有不同预测和相同节版本的图像:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)