Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tokens=nltk.word_tokenize(corpus)
- uni=nltk.ngrams(tokens,1)
- bi=nltk.ngrams(tokens,2)
- countsU={}
- u=collections.Counter(uni)
- b=collections.Counter(bi)
- for i,j in u.most_common():
- countsU[i[0]]=j # 'TOKEN': <NUM>
- countsB = {}
- for i,j in b.most_common():
- countsB[i]=j
- t='am'
- print(countsU[t)
- Traceback (most recent call last):
- File "test.py", line 45, in <module>
- print(countsU['am'])
- KeyError: 'am'
- Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement