python - 获取名称错误名称'sentence_stream'未定义
问题描述
我想使用三元组和二元组,因为我不想只使用一元组。
bigramer = gensim.models.Phrases(sentences)
model = Word2Vec(bigramer[sentences], workers=num_workers, \
size=num_features, min_count = min_word_count, \
window = context, sample = downsampling)
from nltk import bigrams
from nltk import trigrams
from gensim.models import Phrases
from gensim.models.phrases import Phraser
trigrams = Phrases(bigrams[sentence_stream])
但是,我遇到了这个错误。
NameErrorTraceback (most recent call last)
<ipython-input-161-15b0101c13b1> in <module>()
----> 1 trigrams = Phrases(bigrams[sentence_stream])
NameError: name 'sentence_stream' is not defined
解决方案
我已经通过将代码重写为:
bigram = Phrases(sentences, min_count=1, threshold=1)
print list(bigram[sentences])
trigram = Phrases(bigram[sentences],min_count=1, threshold=1)
print list(trigram[bigram[sentences]])
推荐阅读
- python - Python(17874,0x111e92dc0)malloc:无法分配区域
- neo4j - 三重存储或图形数据库更适合这个应用程序?
- autodesk-forge - 为什么 Autodesk Forge 的“workflowAttribute”没有出现在模型衍生工作的 webhook 更新中?
- java - 如何找到这个递归函数的递归关系?
- python - IBM Power9 ppc64le 上的 Tensorflow - 可以删除 libtensorflow.so 吗?
- google-api - Google Drive 评论 API 在没有评论时显示未解决的评论
- python - Solve_ivp 输出,进入轨道图?
- ruby - Ruby 强参数:Integer 的 NoMethodError 未定义方法允许
- python-3.x - 使用 BeautifulSoup 进行网页抓取
- android - Xamarin.Forms Android 应用程序上未显示启动屏幕,其中 VPN 和工作配置文件上的托管设备