Created
April 14, 2015 06:07
-
-
Save dyerrington/f9b9e090a250275cd35f to your computer and use it in GitHub Desktop.
Find bi-grams, filter on frequency, return PMI
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
import nltk | |
from nltk.collocations import * | |
bigram_measures = nltk.collocations.BigramAssocMeasures() | |
trigram_measures = nltk.collocations.TrigramAssocMeasures() | |
# change this to read in your data | |
finder = BigramCollocationFinder.from_words( | |
nltk.corpus.genesis.words('/var/www/htdocs/rapstats/data/albums/wutang_all.txt')) | |
# only bigrams that appear 3+ times | |
finder.apply_freq_filter(2) | |
# return the 10 n-grams with the highest PMI | |
finder.nbest(bigram_measures.pmi, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment