I am currently working with nltk.book iny Python and would like to find the frequency of a specific bigram. I know there is the bigram() function that gives you the most common bigrams in the text as in this code:
>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
>>>
But what if I was searching for only a specific one like "wish for"? I couldn't find anything about that in the nltk documentation so far.
If you can return a list of tuples, you can use
in:Then if you're looking for the frequency of specific bigrams, it might be helpful to build a Counter:
Output:
Finally, if you want to understand this frequency in terms of how many bigrams are possible, you could divide by the number of possible bigrams:
Output: