How to use 'nltk bigrams' in Python

Every line of 'nltk bigrams' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
55def _get_bigram_feats(self, unigrams):
56 if len(unigrams) > 1:
57 bigrams = map(' '.join, zip(unigrams[:-1], unigrams[1:]))
58 else:
59 bigrams = []
60 return bigrams
107def create_bigrams(words):
108 assert type(words) == list
109 skip = 0
110 join_str = " "
111 Len = len(words)
112 if Len > 1:
113 lst = []
114 for i in range(Len-1):
115 for k in range(1,skip+2):
116 if i+k < Len:
117 lst.append(join_str.join([words[i],words[i+k]]))
118 else:
119 #set it as unigram
120 lst = create_unigram(words)
121 return lst

Related snippets