本文整理汇总了Python中nltk.FreqDist.viewkeys方法的典型用法代码示例。如果您正苦于以下问题:Python FreqDist.viewkeys方法的具体用法?Python FreqDist.viewkeys怎么用?Python FreqDist.viewkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.FreqDist
的用法示例。
在下文中一共展示了FreqDist.viewkeys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_wordfrequency
# 需要导入模块: from nltk import FreqDist [as 别名]
# 或者: from nltk.FreqDist import viewkeys [as 别名]
def train_wordfrequency(n_dims = 50):
### Load data
dataloader = csv_dataloader()
dataloader.load('output/data_cache.pk')
print "Read in finished"
train_id = dataloader.id
_, pos_id, neg_id = dataloader.balance(train_id, 'full')
train_data_pos = dataloader.data_retrieve(pos_id)
train_data_neg = dataloader.data_retrieve(neg_id)
tokens = sum(dataloader.data.viewvalues(), [])
tokens_pos = sum(train_data_pos['data'].viewvalues(), [])
tokens_neg = sum(train_data_neg['data'].viewvalues(), [])
fdist_base = FreqDist(tokens)
fdist_pos = FreqDist(tokens_pos)
fdist_pos = normalize(fdist_pos, fdist_base)
fdist_neg = FreqDist(tokens_neg)
fdist_neg = normalize(fdist_neg, fdist_base)
print list(fdist_pos.viewkeys())[:100]
print list(fdist_neg.viewkeys())[:100]
labels_pos = [1] * len(tokens_pos)
labels_neg = [0] * len(tokens_neg)
labels = labels_pos + labels_neg
corpus = tokens_pos + tokens_neg