各位老师好,我提一个问题,就是使用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)
将module = hub.Module(name="word2vec_skipgram", version='1.1.0')修改为
module = hub.Module(name="word2vec_skipgram")