[英]Python NLTK: Count list of word and make probability with valid English words
[英]Python: NLTK Probability of List of words
我一直在努力計算語料庫中的單詞列表,並看到單詞列表的可能性。
我一直在計算每個單詞的頻率,然后使用EXCEL求和,但這確實需要很長時間。 我名單上的字數是幾千。
我只想總結單詞列表的出現頻率總數,然后查看單詞的概率。
genres = ['C:/A1.txt','C:/A2.txt','C:/A3.txt']
modals = ['can', 'could', 'may', 'might', 'must', 'will']
cfd = nltk.ConditionalFreqDist(
(genre, word)
for genre in genres
for word in modals)
cfd.tabulate(conditions=genres, samples=modals)
請幫幫我。 我已經花了兩天時間來解決這個問題。
提前非常感謝您!
這是我用來獲取頻率計數的函數。 它使用numpy數組。 您可以修改代碼以獲得概率。
def freqCount(y_list):
x =array(y_list)
y = bincount(x)
ii = nonzero(y)[0]
freq = zip(ii,y[ii])
f = open(fn_freq,'w')
f.write('Distribution:\n')
print
print "Distribution:"
freq_dict={}
for ff in freq:
temp = "%s %s\n" % (ff[0],ff[1])
f.write(temp)
print ff[0],ff[1]
freq_dict[ff[0]]=ff[1]
f.close()
return freq_dict
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.