牛津大学自然语言处理模型(自然语言处理第十六讲)

牛津大学自然语言处理模型(自然语言处理第十六讲)(1)

代码解读:

text = ['I use this thing to play WoW classic and it does a great job',

'The sound is awful . . . very low',

'so far works great for the price',

'it is a basic computer but does what i need it to']

准备处理的对象是一个列表,每个元素是一个字符串

from textblob import TextBlob

调用textblob模块,运行代码前需要安装这个模块: pip install textblob

polarNote = []

创建一个空的列表polarNote,用来存储每个字符串情感分析的结果

for line in text:

遍历列表text中的每个字符串

blob = TextBlob(line)

用TextBlob函数对每个字符串line进行处理

polarNote.append(blob.sentiment)

将处理的结果添加至列表polarNote中去

combine = list(zip(polarNote, text))

将情感分析结果和相应的字符串保存为列表combine的一个元素

print(combine)

输出结果:

结果如下:

[(Sentiment(polarity=0.35555555555555557, subjectivity=0.638888888888889), 'I use this thing to play WoW classic and it does a great job'), (Sentiment(polarity=-0.19999999999999998, subjectivity=0.5966666666666667), 'The sound is awful . . . very low'), (Sentiment(polarity=0.45, subjectivity=0.875), 'so far works great for the price'), (Sentiment(polarity=0.0, subjectivity=0.125), 'it is a basic computer but does what i need it to')]

极性(polarity)是在-1 1之间变化的值。 它向我们展示了给出的句子是正面还是负面

牛津大学自然语言处理模型(自然语言处理第十六讲)(2)

主观性(subjectivity)是另一个介于0到1之间的值,它向我们显示了句子是关于事实还是观点(客观还是主观)。

牛津大学自然语言处理模型(自然语言处理第十六讲)(3)

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页