Update the encode function in BART hub_interface: to add an extra option for not always adding OOV tokens into vocabulary #3905
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Regarding this code line 62 in the
encode
function in BART hub_interface, in many cases (e.g. using a monolingual vocabulary reduced from an existing multilingual one), an OOV token should be aligned with<unk>
index, rather than always being added as a new token type into the vocabulary.Recent code: https://github.com/pytorch/fairseq/blob/main/fairseq/models/bart/hub_interface.py
Suggest to be as follows (https://github.com/datquocnguyen/fairseq/blob/main/fairseq/models/bart/hub_interface.py):
With this suggested code, in the case mentioned above, encoding should be
fairseq_model.encode(sentence, add_if_not_exist=False)
For mBART and the like, it still encodes and adds extra token types into the vocabulary (e.g. training for new languages) as before:
fairseq_model.encode(sentence)