python - Error getting trigrams using gemsim's Phrases -
i want extract bigrams , trigrams of given sentences.
from gensim.models import phrases documents = ["the mayor of new york there", "human computer interaction great , new subject", "machine learning can useful sometimes","new york mayor present", "i love machine learning because new subject area", "human computer interaction helps people user friendly applications"] sentence_stream = [doc.split(" ") doc in documents] bigram = phrases(sentence_stream, min_count=1, threshold=2, delimiter=b' ') trigram = phrases(bigram(sentence_stream, min_count=1, threshold=2, delimiter=b' ')) sent in sentence_stream: #print(sent) bigrams_ = bigram[sent] trigrams_ = trigram[bigrams_] print(bigrams_) print(trigrams_)
the code works fine bigrams , capture 'new york' , 'machine learning' ad bigrams.
however, following error when try insert trigrams.
typeerror: 'phrases' object not callable
please let me know, how correct code.
i following example documentation of gensim.
according docs, can do:
from gensim.models.phrases import phraser phrases = phrases(sentence_stream) bigram = phraser(p) trigram = phrases(bigram[sentence_stream])
bigram
, being phrases
object, cannot called again, doing so.
Comments
Post a Comment