:
from gensim.models import Phrases
documents = ["the mayor of new york was there", "human computer interaction and machine learning has now become a trending research area","human computer interaction is interesting","human computer interaction is a pretty interesting subject", "human computer interaction is a great and new subject", "machine learning can be useful sometimes","new york mayor was present", "I love machine learning because it is a new subject area", "human computer interaction helps people to get user friendly applications"]
sentence_stream = [doc.split(" ") for doc in documents]
bigram = Phrases(sentence_stream, min_count=1, delimiter=b' ')
trigram = Phrases(bigram[sentence_stream], min_count=1, delimiter=b' ')
for sent in sentence_stream:
bigrams_ = [b for b in bigram[sent] if b.count(' ') == 1]
trigrams_ = [t for t in trigram[bigram[sent]] if t.count(' ') == 2]
print(bigrams_)
print(trigrams_)
threshold = 1 bigram Phrases, , , , ( , bigram Phrases); , , , . min_count , 5, .
, , , , .
- threshold:
, a b , , :
(count(a followed by b) - min_count) * N/(count(a) * count(b)) > threshold
N - . 10 (. docs). , threshold, .
, threshold = 1, ['human computer','interaction is'] digrams 3 5 , " "; .
, threshold = 10, ['human computer interaction is'] 3 ( ); 4 , if t.count(' ') == 2. , , , 1, [ " " ] . , , .
, : , ( "" ), , , 4-...