文本生成的输入字符错误问题
源代码是以如下的形式进行参数输入的:print(generate_text(model, start_string=u"歌唱祖国:"))
generate_text函数的开始部分
def generate_text(model, start_string):
# 评估步骤(用学习过的模型生成文本)
# 要生成的字符个数
num_generate = 200
# 将起始字符串转换为数字(向量化)
input_eval = for s in start_string]
input_eval = tf.expand_dims(input_eval, 0)
我想要将输入转为自定义输入,代码如下:
txt = input('请给诗词开个头:')
print(generate_text(model, start_string = txt))
input内容为:你好祖国
结果报错:
Traceback (most recent call last):
File "C:/AI案例/调试/poetry_ada/gettxt.py", line 202, in <module>
print(generate_text(model, start_string = txt))
File "C:/AI案例/调试/poetry_ada/gettxt.py", line 171, in generate_text
input_eval = for s in start_string]
File "C:/AI案例/调试/poetry_ada/gettxt.py", line 171, in <listcomp>
input_eval = for s in start_string]
KeyError: '你'
求论坛大佬帮忙看看 字典char2idx没有‘你’这个key,代码不全,卡不出char2idx是从哪里来的。
页:
[1]