Created
February 4, 2012 17:40
-
-
Save ConstantineLignos/1739135 to your computer and use it in GitHub Desktop.
Compute the probability mass assigned to the most frequent tokens using the Brown corpus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import nltk | |
TOP_PERCENT = .01 | |
def prob_mass_top(counts, n): | |
return sum(count for word, count in counts.most_common(n)) / float(sum(count.values())) | |
count = Counter(word.lower() for word in nltk.corpus.brown.words()) | |
print "Top %d%% of types account for %2.1f%% of tokens" % \ | |
(TOP_PERCENT * 100, prob_mass_top(count, int(len(count) * TOP_PERCENT)) * 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment