jasoncao11 / nlp-notebook

NLP 领域常见任务的实现,包括新词发现、以及基于pytorch的词向量、中文文本分类、实体识别、摘要文本生成、句子相似度判断、三元组抽取、预训练模型等。
MIT License
510 stars 109 forks source link

Bug #4

Closed liushz closed 2 years ago

liushz commented 2 years ago
  File "/workspace/nlp-notebook/4-3.Transformer/model.py", line 256, in forward
    enc_src = self.encoder(src, src_mask)        
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/workspace/nlp-notebook/4-3.Transformer/model.py", line 35, in forward
    src = self.dropout((self.tok_embedding(src) * self.scale) + self.pos_embedding(pos))     
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/sparse.py", line 156, in forward
    return F.embedding(
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py", line 1916, in embedding
    return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
IndexError: index out of range in self

生成模型Transformer有以上错误,排除了软件包版本问题,S2S+attention也有bug,具体和之前一个issue一样,tuple和tensor的问题

liushz commented 2 years ago

解决了,输入的句子没有截断,field那加上fix_length=len

HelloWorldGitHubUser commented 2 years ago

请问fix_length=len的len应该取哪个的len呢?谢谢! @liushz @jasoncao11