OpenNMT-py
OpenNMT-py copied to clipboard
fix sequence_mask with None lengths
the code location: encoders/transformer.py:
class TransformerEncoder(EncoderBase):
...
def forward(self, src, lengths=None):
"""See :func:`EncoderBase.forward()`"""
self._check_args(src, lengths)
emb = self.embeddings(src)
out = emb.transpose(0, 1).contiguous()
mask = ~sequence_mask(lengths).unsqueeze(1)
# Run the forward pass of every layer of the tranformer.
for layer in self.transformer:
out = layer(out, mask)
out = self.layer_norm(out)
here when lengths is None, mask = ~sequence_mask(lengths).unsqueeze(1) will return a
AttributeError: 'NoneType' object has no attribute 'numel', so it means that I should always need to pass a lengths here to replace the default None.
Thanks for this but what's the use case // did it cause an issue // in what kind of setup?
very sorry for that, i should make a clear explain.