栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Gensim:TypeError:doc2bow期望输入的是Unicode标记数组,而不是单个字符串

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Gensim:TypeError:doc2bow期望输入的是Unicode标记数组,而不是单个字符串

在dictionary.py中,初始化函数为:

def __init__(self, documents=None):    self.token2id = {} # token -> tokenId    self.id2token = {} # reverse mapping for token2id; only formed on request, to save memory    self.dfs = {} # document frequencies: tokenId -> in how many documents this token appeared    self.num_docs = 0 # number of documents processed    self.num_pos = 0 # total number of corpus positions    self.num_nnz = 0 # total number of non-zeroes in the BOW matrix    if documents is not None:        self.add_documents(documents)

函数add_documents从文档集合构建字典。每个文档都是令牌列表:

def add_documents(self, documents):    for docno, document in enumerate(documents):        if docno % 10000 == 0: logger.info("adding document #%i to %s" % (docno, self))        _ = self.doc2bow(document, allow_update=True) # ignore the result, here we only care about updating token ids    logger.info("built %s from %i documents (total %i corpus positions)" %      (self, self.num_docs, self.num_pos))

因此,如果以此方式初始化Dictionary,则必须传递文档,但不能传递单个文档。例如,

dic = corpora.Dictionary([a.split()])

还可以



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/639744.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号