nlp bigram code example
Example 1: nltk bigrams
>>> import nltk
>>> from nltk.tokenize import word_tokenize
>>> text = "to be or not to be"
>>> tokens = nltk.word_tokenize(text)
>>> bigrm = nltk.bigrams(tokens)
>>> print(*map(' '.join, bigrm), sep=', ')
to be, be or, or not, not to, to be
Example 2: nltk bigrams
bigrm = list(nltk.bigrams(text.split()))