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

run error #7

Open
ECNUHP opened this issue Dec 31, 2019 · 4 comments
Open

run error #7

ECNUHP opened this issue Dec 31, 2019 · 4 comments

Comments

@ECNUHP
Copy link

ECNUHP commented Dec 31, 2019

Traceback (most recent call last):
File "train.py", line 299, in
main()
File "train.py", line 291, in main
max_bleu = train(model, vocab, dataloader, scheduler, optim, updates)
File "train.py", line 118, in train
outputs = model(batch, use_cuda)
File "/opt/lang.huo/miniconda3/envs/huopei/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/opt/lang.huo/mybot/question_generation/models/graph2seq.py", line 93, in forward
contexts, state, attns = self.encode(src, src_mask, concept, concept_mask, title_index, adjs)
File "/opt/lang.huo/mybot/question_generation/models/graph2seq.py", line 71, in encode
return contexts, state, attn
UnboundLocalError: local variable 'attn' referenced before assignment

出现上述错误是因为什么呢?
跪求解答

@astrodrew
Copy link

同问,而且“segged_content.txt”是如何获得的

@AbnerCode
Copy link

可以通过从json文件中抽取

@shenjian5
Copy link

shenjian5 commented Jul 20, 2020

Traceback (most recent call last):
File "train.py", line 299, in
main()
File "train.py", line 291, in main
max_bleu = train(model, vocab, dataloader, scheduler, optim, updates)
File "train.py", line 118, in train
outputs = model(batch, use_cuda)
File "/opt/lang.huo/miniconda3/envs/huopei/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/opt/lang.huo/mybot/question_generation/models/graph2seq.py", line 93, in forward
contexts, state, attns = self.encode(src, src_mask, concept, concept_mask, title_index, adjs)
File "/opt/lang.huo/mybot/question_generation/models/graph2seq.py", line 71, in encode
return contexts, state, attn
UnboundLocalError: local variable 'attn' referenced before assignment

出现上述错误是因为什么呢?
跪求解答

需要预先定义一下,大概是代码中漏定义了。
def encode(self, contents, contents_mask, concepts, concept_mask, title_index, adjs):
contexts = []
states = []
attn=[]
……

@liweitj47
Copy link
Collaborator

liweitj47 commented Jul 20, 2020 via email

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

5 participants