def pmi(word1, word2, unigram_freq, bigram_freq):
    prob_word1 = unigram_freq[word1] / float(sum(unigram_freq.values()))
prob_word2 = unigram_freq[word2] / float(sum(unigram_freq.values()))
prob_word1_word2 = bigram_freq[' '.join([word1, word2])] / float(sum(
    bigram_freq.values()))
return math.log(prob_word1_word2 / float(prob_word1 * prob_word2), 2)
Python - Sentiment Analysis using Pointwise Mutual Information