This repository was archived by the owner on Mar 20, 2026. It is now read-only.
Update the encode function in BART hub_interface: to add an extra option for not always adding OOV tokens into vocabulary - #3905
Open
datquocnguyen wants to merge 1 commit into
Open
Conversation
To provide an extra option to convert OOV tokens into <unk> rather than always adding the OOV tokens into the dictionary.
|
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
Author
|
bump |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
encodefunction 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)