首页 PaddleHub 帖子详情
return_numpy = True
收藏
快速回复
PaddleHub 问答预训练模型 2223 1
return_numpy = True
收藏
快速回复
PaddleHub 问答预训练模型 2223 1

各位老师好,我提一个问题,就是使用padddle hub module word2ec_skipgram==1.0.0 model 时,github里的就算语句相似度的程序,总有一个BUG,return_numpy = True,ValueError: `type` to initialized an Operator can not be None.不知怎么回事,哪位老师知道,多谢各位老师

import paddle.fluid as fluid
import paddlehub as hub

raw_data = ["驾驶违章一次扣12分用两个驾驶证处理可以吗",
"一次性扣12分的违章,能用不满十二分的驾驶证扣分吗",
"水果放冰箱里储存好吗", "中国银行纪念币网上怎么预约",
"电脑反应很慢怎么办", "反应速度慢,电脑总是卡是怎么回事"]
max_seq_len = 50

module = hub.Module(name="word2vec_skipgram", version='1.1.0')
inputs, outputs, program = module.context(trainable=False,max_seq_len= max_seq_len)

word_ids = inputs["text"]
embedding = outputs["emb"]

tokenizer = hub.CustomTokenizer(vocab_file=module.get_vocab_path())


place = fluid.CPUPlace()
exe = fluid.Executor(place)
feeder = fluid.DataFeeder(feed_list=[word_ids], place=place)

for data in raw_data:
data_dict = tokenizer.encode(text=data, max_seq_len=max_seq_len)
text = data_dict['text']

vecs, = exe.run(
program,
feed=feeder.feed([[text]]),
fetch_list=[embedding.name],
return_numpy=True)
print("The input text is {}, and the embeddings are ".format(data))
print(vecs)

0
收藏
回复
全部评论(1)
时间顺序
散列哈希函数
#2 回复于2021-07

将module = hub.Module(name="word2vec_skipgram", version='1.1.0')修改为

module = hub.Module(name="word2vec_skipgram")

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户