逻辑回归和情感分析
我需要有关以下代码的帮助,到处都写着“您的代码在这里”。 任何帮助表示赞赏。 谢谢你!
#使用词典创建两个词典特征。 特征“POSLEX”,其值指示有多少标记属于正向词典。 特征“NEGLEX”,其值指示有多少标记属于否定词典。
def two_lexicon_features(tokens):
feats = {'POSLEX': 0, 'NEGLEX': 0}
# YOUR CODE HERE
return feats
#如果正向词典中的单词(例如“like”)在文档中出现 N 次(例如 5 次),则为与该值关联的该单词添加正向词典特征“POSLEX_word”(例如 {'POSLEX_like' : 5 }。 类似地,如果否定词典中的单词(例如“dislike”)在文档中出现 N 次(例如 5 次),则为与该值关联的该单词添加否定词典特征“NEGLEX_word”(例如 {'NEGLEX_dislike' : 5}
def lexicon_features(tokens):
feats = {}
# YOUR CODE HERE
# Assume the positive and negative lexicons are available in poslex and neglex, respectively.
return feats
#添加一个特征'DOC_LEN',其值为文档长度的自然对数(使用math.log计算对数)
import math
def len_feature(tokens):
feat = {'DOC_LEN': 'YOUR CODE HERE'}
return feat
#添加一个功能“DEICTIC_COUNT”,用于计算文档中第一人称代词和第二人称代词的数量。
def deictic_feature(tokens):
pronouns = set(('i', 'my', 'me', 'we', 'us', 'our', 'you', 'your'))
count = 0
# YOUR CODE HERE
return {'DEICTIC_COUNT': count}
I need help with the following code everywhere that says "YOUR CODE HERE".
Any help is appreciated.
Thank you!
#Use the lexicons to create two lexicon features.
A feature 'POSLEX' whose value indicates how many tokens belong to the positive lexicon.
A feature 'NEGLEX' whose value indicates how many tokens belong to the negative lexicon.
def two_lexicon_features(tokens):
feats = {'POSLEX': 0, 'NEGLEX': 0}
# YOUR CODE HERE
return feats
#If a word from the positive lexicon (e.g. 'like') appears N times in the document (e.g. 5 times), add a positive lexicon feature 'POSLEX_word' for that word that is associated that value (e.g. {'POSLEX_like' : 5}.
Similarly, if a word from the negative lexicon (e.g. 'dislike') appears N times in the document (e.g. 5 times), add a negative lexicon feature 'NEGLEX_word' for that word that is associated that value (e.g. {'NEGLEX_dislike' : 5}
def lexicon_features(tokens):
feats = {}
# YOUR CODE HERE
# Assume the positive and negative lexicons are available in poslex and neglex, respectively.
return feats
#Add a feature 'DOC_LEN' whose value is the natural logarithm of the document length (use math.log to compute logarithms)
import math
def len_feature(tokens):
feat = {'DOC_LEN': 'YOUR CODE HERE'}
return feat
#Add a feature 'DEICTIC_COUNT' that counts the number of 1st and 2nd person pronouns in the document.
def deictic_feature(tokens):
pronouns = set(('i', 'my', 'me', 'we', 'us', 'our', 'you', 'your'))
count = 0
# YOUR CODE HERE
return {'DEICTIC_COUNT': count}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论