Skip to content

Commit 672cc4e

Browse files
committed
Pack & pad tensors to the LSTM
1 parent 0ee6195 commit 672cc4e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

stanza/models/tokenization/model.py

+4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def forward(self, x, feats, lengths):
4848
feats = self.dropout_feat(feats)
4949

5050
emb = torch.cat([emb, feats], 2)
51+
emb = pack_padded_sequence(emb, lengths, batch_first=True)
5152
inp, _ = self.rnn(emb)
53+
inp, _ = pad_packed_sequence(inp, batch_first=True)
5254

5355
if self.args['conv_res'] is not None:
5456
conv_input = emb.transpose(1, 2).contiguous()
@@ -75,7 +77,9 @@ def forward(self, x, feats, lengths):
7577
inp2 = inp
7678
if self.args['hier_invtemp'] > 0:
7779
inp2 = inp2 * (1 - self.toknoise(torch.sigmoid(-tok0 * self.args['hier_invtemp'])))
80+
inp2 = pack_padded_sequence(inp2, lengths, batch_first=True)
7881
inp2, _ = self.rnn2(inp2)
82+
inp2, _ = pad_packed_sequence(inp2, batch_first=True)
7983

8084
inp2 = self.dropout(inp2)
8185

0 commit comments

Comments
 (0)