Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于一个app的可能bug,KeyError(source: [lang.word2index[word] for word in sentence.split(' ')]) #145

Open
JGanson opened this issue Sep 23, 2022 · 0 comments

Comments

@JGanson
Copy link

JGanson commented Sep 23, 2022

我跑的是seq2seq pytorch的。 我在跑app发现了一个问题。
跑app之前我先训练了1000遍, 确定了前1000个句子被读进去了。但是跑之后传了一个“是谁”, 他给出了keyerror“是谁”。

我找了一下发现这个问题出错在 predict函数里面的tensorfromsentence。 他把“是谁”直接传进tensorfromsentence,然后进到indexesFromSentence。这里会有一个问题:
return [lang.word2index[word] for word in sentence.split(' ')]
“是谁”在Lang dataset里面被jieba拆成“是”和“谁”, 这里sentence.split(' ')并不会把“是谁”拆开。所以我觉得在predict之前得先给input分词。

我是先把传进来的input:
input = " ".join(jieba.cut(input))
然后再运行tensorfromsentence就应该没问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant