Je veux obtenir des bigrammes et des trigrammes à partir des exemples de phrases que j'ai mentionnés.Problèmes lors de l'obtention de trigrammes en utilisant Gensim
Mon code fonctionne bien pour les bigrams. Cependant, il ne tient pas compte trigrammes dans les données (par exemple, l'interaction homme-machine, qui est mentionné dans 5 lieux de mes phrases)
approche 1 Mentionnés ci-dessous est mon code en utilisant des phrases dans Gensim.
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, threshold=1, delimiter=b' ')
trigram = Phrases(bigram_phraser[sentence_stream])
for sent in sentence_stream:
bigrams_ = bigram_phraser[sent]
trigrams_ = trigram[bigrams_]
print(bigrams_)
print(trigrams_)
Approche 2 J'ai même essayé d'utiliser Phraser et phrases à la fois, mais cela n'a pas fonctionné.
from gensim.models import Phrases
from gensim.models.phrases import Phraser
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, threshold=2, delimiter=b' ')
bigram_phraser = Phraser(bigram)
trigram = Phrases(bigram_phraser[sentence_stream])
for sent in sentence_stream:
bigrams_ = bigram_phraser[sent]
trigrams_ = trigram[bigrams_]
print(bigrams_)
print(trigrams_)
S'il vous plaît aidez-moi à résoudre ce problème d'obtention de trigrammes. Je suis le example documentation de Gensim.
Merci beaucoup pour votre réponse très précieuse. À votre santé! :) En passant, pouvez-vous me dire ce qu'il se passe avec la valeur "seuil", car ce n'est pas très clair pour moi? –
De rien! Oui, j'ai édité la réponse, j'espère que maintenant c'est un peu plus clair. – stjernaluiht
Merci beaucoup! J'ai trouvé votre réponse très utile :) –