马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
源代码是以如下的形式进行参数输入的:print(generate_text(model, start_string=u"歌唱祖国:"))
generate_text函数的开始部分def generate_text(model, start_string):
# 评估步骤(用学习过的模型生成文本)
# 要生成的字符个数
num_generate = 200
# 将起始字符串转换为数字(向量化)
input_eval = [char2idx[s] 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 = [char2idx[s] for s in start_string]
File "C:/AI案例/调试/poetry_ada/gettxt.py", line 171, in <listcomp>
input_eval = [char2idx[s] for s in start_string]
KeyError: '你'
求论坛大佬帮忙看看 |