我目前在我的 word2vec 模型中使用 uni-gram,如下所示。
def review_to_sentences( review, tokenizer, remove_stopwords=False ):
#Returns a list of sentences, where each sentence is a list of words
#
#NLTK tokenizer to split the paragraph into sentences
raw_sentences = tokenizer.tokenize(review.strip())
sentences = []
for raw_sentence in raw_sentences:
# If a sentence is empty, skip it
if len(raw_sentence) > 0:
# Otherwise, call review_to_wordlist to get a list of words
sentences.append( review_to_wordlist( raw_sentence, \
remove_stopwords ))
#
# Return the list of sentences (each sentence is a list of words,
# so this returns a list of lists
return sentences
但是,我会错过数据集中重要的二元组和三元组。
E.g.,
"team work" -> I am currently getting it as "team", "work"
"New York" -> I am currently getting it as "New", "York"
因此,我想在我的数据集中捕获重要的二元组、三元组等,并将其输入到我的 word2vec 模型中。
我是 wordvec 的新手并且正在努力如何去做。请帮我。
原文由 user8566323 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先,您应该使用 gensim 的 Phrases 类来获取双字母组,其工作原理与文档中指出的一样
要得到 trigrams 等等,你应该使用你已经拥有的 bigram 模型并再次对其应用 Phrases,等等。例子:
还有一个很好的笔记本和视频,解释了如何使用它…. 笔记本, 视频
它最重要的部分是如何在现实生活中使用它,如下所示:
希望这对您有所帮助,但下次请向我们提供有关您使用的内容等的更多信息。
PS:现在你编辑了它,你没有做任何事情来获得二元组只是分裂它,你必须使用短语来获得像纽约这样的词作为二元组。