Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit b362c31

Browse files
ArmenAgfacebook-github-bot
authored andcommitted
Fix bug in copy_unk (#964)
Summary: Pull Request resolved: #964 When the copy_unk flag is set to true. Any unk that is produced in the output of the Seq2Seq model is replaced by the token that was mapped to unk from the utterance. This is a easy way to get gains since outputs with unk are always wrong. Looking at the old code for copying the unk token we see that TorchScript optimizes out the actual search of the unk token in utterance: {F207887831} This diff updates the code to produce the correct TorchScript Graph {F207888470} Reviewed By: arbabu123 Differential Revision: D17213086 fbshipit-source-id: ebbfc52dcd703939316b15250110271336ef131d
1 parent 9fc6aa4 commit b362c31

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pytext/utils/torch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def lookup_words_1d(
123123

124124
@torch.jit.script_method
125125
def lookup_word(self, idx: int, possible_unk_token: Optional[str] = None):
126-
if idx < len(self.vocab):
126+
if idx < len(self.vocab) and idx != self.unk_idx:
127127
return self.vocab[idx]
128128
else:
129129
return (

0 commit comments

Comments
 (0)