【发布时间】:2017-12-24 11:01:48
【问题描述】:
我一直在尝试在数据集上使用 Stanford Core NLP,但它在我无法找到的某些索引处停止。 该数据集在 Kaggle 上可用:https://www.kaggle.com/PromptCloudHQ/amazon-reviews-unlocked-mobile-phones/data
这是一个通过获取单个句子的平均情感值来输出段落情感的函数。
import json
def funcSENT(paragraph):
all_scores = []
output = nlp.annotate(paragraph, properties={
"annotators": "tokenize,ssplit,parse,sentiment",
"outputFormat": "json",
# Only split the sentence at End Of Line. We assume that this method only takes in one single sentence.
#"ssplit.eolonly": "true",
# Setting enforceRequirements to skip some annotators and make the process faster
"enforceRequirements": "false"
})
all_scores = []
for i in range(0,len(output['sentences'])):
all_scores.append((int(json.loads(output['sentences'][i]['sentimentValue']))+1))
final_score = sum(all_scores)/len(all_scores)
return round(final_score)
现在我使用此代码为“评论”列中的每条评论运行此代码。
import pandas as pd
data_file = 'C:\\Users\\SONY\\Downloads\\Amazon_Unlocked_Mobile.csv'
data = pd.read_csv( data_file)
from pandas import *
i = 0
my_reviews = data['Reviews'].tolist()
senti = []
while(i<data.shape[0]):
senti.append(funcSENT(my_reviews[i]))
i=i+1
但不知何故,我得到了这个错误,我无法找到问题所在。现在已经好几个小时了,请帮忙。
[1]: https://i.stack.imgur.com/qFbCl.jpg
如何避免这个错误?
【问题讨论】:
标签: python typeerror stanford-nlp sentiment-analysis keyerror