I have trained a transformer NMT-model (Version of opennmt-py is v3.4), and tried to extract the attention of source and output.
I set --attn_debug
to inference, which meets
File "/xxx/anaconda3/envs/opennmt3/lib/python3.8/site-packages/onmt/translate/translator.py", line 861, in _translate_batch_with_strategy
decode_strategy.advance(log_probs, attn)
File "/xxx/anaconda3/envs/opennmt3/lib/python3.8/site-packages/onmt/translate/beam_search.py", line 352, in advance
current_attn = attn.index_select(0, self.select_indices)
AttributeError: 'NoneType' object has no attribute 'index_select'
When I debug the function of _decode_and_generate
, I found the value of dec_attn
is {‘std’: None}.
Looking forward for help.
def _decode_and_generate(
self,
decoder_in,
enc_out,
batch,
src_len,
src_map=None,
step=None,
batch_offset=None,
):
if self.copy_attn:
# Turn any copied words into UNKs.
decoder_in = decoder_in.masked_fill(
decoder_in.gt(self._tgt_vocab_len - 1), self._tgt_unk_idx
)
# Decoder forward, takes [batch, tgt_len, nfeats] as input
# and [batch, src_len, hidden] as enc_out
# in case of inference tgt_len = 1, batch = beam times batch_size
# in case of Gold Scoring tgt_len = actual length, batch = 1 batch
dec_out, dec_attn = self.model.decoder(
decoder_in,
enc_out,
src_len=src_len,
step=step,
with_align=self.global_scorer.has_cov_pen,
)