自然语言处理与知识图谱week7 | 情感分析

这篇博客探讨了自然语言处理中情感分析的主题,包括相关的问题、答案和示例代码,同时也提到了其他相关问题。
摘要由CSDN通过智能技术生成

题目

在这里插入图片描述


问题

在这里插入图片描述


答案

在这里插入图片描述


代码

#!/usr/bin/python3
#-*-coding:GBK -*-
from nltk.probability import FreqDist

neg_str = ['just plain boring ', 'entirely predictable and lacks energy ', 
			'no surprises and very few laughs']
pos_str = ['very powerful ','the most fun film of the summer']
connect_neg_str = ' '.join(neg_str)
connect_pos_str = ' '.join(pos_str)

def count_freq(words):
    "[('the', 2), ('very', 1), ...]"
    fdist = FreqDist(words.split())
    tops = fdist.most_common(50)
    return tops

def count_len(words):
    "words单词数"
    l = words.split()
    return len(l)

def get_V_n_P():
    V = len(count_freq(connect_neg_str + ' ' + connect_pos_str)) # 当前训练文本的词汇量
    print('|V| = %d'%V, end = ", ") 
    n_neg = count_len(connect_neg_str) # neg_str的单词数(算重复)
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值