Skip to content

Commit

Permalink
remove redundant duplicate variable when loading dictionary from file
Browse files Browse the repository at this point in the history
  • Loading branch information
lydianish authored Mar 8, 2024
1 parent 1743314 commit 5c40fd3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions fairseq/data/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,25 +259,25 @@ def add_from_file(self, f):
try:
line, field = line.rstrip().rsplit(" ", 1)
if field == "#fairseq:overwrite":
overwrite, duplicate = True, False
overwrite = True
line, field = line.rsplit(" ", 1)
elif field == "#fairseq:duplicate":
overwrite, duplicate = False, True
overwrite = False
line, field = line.rsplit(" ", 1)
else:
overwrite, duplicate = False, False
if line in self:
raise RuntimeError(
"Duplicate word found when loading Dictionary: '{}'. "
"Duplicate words can overwrite earlier ones by adding the "
"#fairseq:overwrite flag at the end of the corresponding row "
"in the dictionary file. Use the #fairseq:duplicate flag "
"to keep duplicates in the dictionary (backward compatibility "
"after bug fix). If using the Camembert model, please "
"download an updated copy of the model file.".format(word)
)
overwrite = True # default behaviour
count = int(field)
word = line
if word in self and not overwrite and not duplicate:
raise RuntimeError(
"Duplicate word found when loading Dictionary: '{}'. "
"Duplicate words can overwrite earlier ones by adding the "
"#fairseq:overwrite flag at the end of the corresponding row "
"in the dictionary file. Use the #fairseq:duplicate flag "
"to keep duplicates in the dictionary (backward compatibility "
"after bug fix). If using the Camembert model, please "
"download an updated copy of the model file.".format(word)
)
self.add_symbol(word, n=count, overwrite=overwrite)
except ValueError:
raise ValueError(
Expand Down

0 comments on commit 5c40fd3

Please sign in to comment.