ValueError: 需要至少一个数组在 Top2Vec Error

问题描述

docs = ['非必需消费品、医疗保健和科技是首选的中国股票行业。',“在中国振兴国内消费政策的支持下,可自由支配的消费者仍然具有吸引力。进一步货币和财政刺激的前景应该会加强中国的消费主题。”, “在对医疗保健服务和药物的需求增加的背景下,医疗保健部门应该成为冠状病毒爆发的主要受益者。”, “随着中国继续从冠状病毒爆发中恢复过来,科技行业应该会受益于对云服务和硬件需求的增加。”, '中国非必需消费品板块是首选。根据我们的评估,该行业在未来 6-12 个月内的表现可能会跑赢 MSCI 中国指数。']

model = Top2Vec(docs,embedding_model = 'universal-sentence-encoder')

在运行上述命令时,我收到一个错误,该错误在调试时不清晰可见,可能是错误的根本原因是什么?

错误

2021-01-19 05:17:08,541 - top2vec - INFO - 训练前处理文件 INFO:top2vec:训练前处理文件 2021-01-19 05:17:08,562 - top2vec - INFO - 下载通用句子编码器模型 信息:top2vec:下载通用句子编码器模型 2021-01-19 05:17:13,250 - top2vec - INFO - 创建联合文档/词嵌入 信息:top2vec:创建联合文档/词嵌入 警告:tensorflow:最近 6 次调用 中的 5 次触发了 tf.function 回溯。跟踪是昂贵的,过多的跟踪可能是由于 (1) 在循环中重复创建 @tf.function,(2) 传递不同形状的张量,(3) 传递 Python 对象而不是张量。对于(1),请在循环之外定义您的@tf.function。对于 (2),@tf.function 有 Experiment_relax_shapes=True 选项,可以放宽参数形状,避免不必要的回溯。对于 (3),请参阅 https://www.tensorflow.org/guide/function#controlling_retracinghttps://www.tensorflow.org/api_docs/python/tf/function 了解更多详情。 警告:tensorflow:最近 6 次对 调用中有 5 次触发了 tf.function 回溯。跟踪是昂贵的,并且过多的跟踪可能是由于 (1) 在循环中重复创建 @tf.function,(2) 传递具有不同形状的张量,(3) 传递 Python 对象而不是张量。对于(1),请在循环之外定义您的@tf.function。对于 (2),@tf.function 有 Experiment_relax_shapes=True 选项,可以放宽参数形状,避免不必要的回溯。对于 (3),请参阅 https://www.tensorflow.org/guide/function#controlling_retracinghttps://www.tensorflow.org/api_docs/python/tf/function 了解更多详情。 2021-01-19 05:17:13,548 - top2vec - INFO - 创建文档的低维嵌入 信息:top2vec:创建文档的低维嵌入 2021-01-19 05:17:15,809 - top2vec - INFO - 查找文档的密集区域 信息:top2vec:查找文档的密集区域 2021-01-19 05:17:15,823 - top2vec - INFO - 寻找话题 信息:top2vec:查找主题

ValueError Traceback(最近一次调用最后一次) 在 () ----> 1 模型 = Top2Vec(docs,embedding_model = 'universal-sentence-encoder')

2 帧 array_function internals> in vstack(*args,**kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in vstack(tup) 第281话 第282话 --> 283 返回 _nx.concatenate(arrs,0) 284 285

array_function internals> in concatenate(*args,**kwargs)

ValueError: 需要至少一个数组来连接

解决方法

您需要使用更多的文档和独特的词才能找到至少 2 个主题。举个例子,我只是将你的列表乘以 10 就可以了:

from top2vec import Top2Vec

docs = ['Consumer discretionary,healthcare and technology are preferred China equity  sectors.','Consumer discretionary remains attractive,supported by China’s policy to revitalize domestic consumption. Prospects of further monetary and fiscal stimulus  should reinforce the Chinese consumption theme.','The healthcare sector should be a key beneficiary of the coronavirus outbreak,on the back of increased demand for healthcare services and drugs.','The technology sector should benefit from increased demand for cloud services  and hardware demand as China continues to recover from the coronavirus  outbreak.','China consumer discretionary sector is preferred. In our assessment,the sector  is likely to outperform the MSCI China Index in the coming 6-12 months.']

docs = docs*10 
model = Top2Vec(docs,embedding_model='universal-sentence-encoder')
print(model)

我有几个(30)个长达 130 000 个字符的长文档,所以我只是将它们每 5000 个字符拆分成更小的文档:


docs_split = []
for doc in docs:
    skip_n = 5000
    for i in range(0,130000,skip_n):
        docs_split.append(doc[i:i+skip_n])