-
Notifications
You must be signed in to change notification settings - Fork 96
feat: add multilanguage support to text2vec and vec2text #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add multilanguage support to text2vec and vec2text #76
Conversation
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
| # Multiple languages | ||
| def encode_fn(x: tuple[str, str]): | ||
| text, lang = x | ||
| tokenizer_encoder = self.tokenizer.create_encoder( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be faster if you create encoders only once per language (e.g. by caching them with lru_cache or something like that).
Ideally, you should benchmark this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| task="translation", | ||
| target_lang=target_lang, | ||
| ) | ||
| if isinstance(target_lang, str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid having two big separate branches of code, maybe we simply convert the case of single language code into the case of sequence in the very beginning, and then proceed with the same translation function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about this?

Why ?
Why do we need to implement this feature ? What is the use case ?
To train SAEs using the NLLB's mined text from the slone/nllb-200-10M-sample dataset
For example, if you do
dataset.take(2), sample 1 and sample 2 may have differentlang1andlang2. The current inference pipeline does not support thisHow ?
Document the technical decisions you made.
source_langortarget_langis not instance ofstr, then the argument is assumed asSequence, and so createtokenizerfor every sampleIf some parts are WIP, please explicit them here.
For context:
tokenizer.create_encoderevery timepredictfunction is called instead of cache it in the first place e.g. is it expensive to store thetokenizer?pytorch_lightninglibrary hasnum_workersargument and hasset_upfunction in theLightningModule. So, I assume the best practice is tokenizing should be done outside inference and generally be done in CPUWith that being said, that's why I don't touch how the tokenizer works, to avoid causing unexpected issue
Test plan
How did you test your changes ?
pytest /workspace/ALGOVERSE/UJR/jason/SONAR/tests/unit_tests/huggingface_pipelines/text.pyProblem: the unit tests failed in
test_embedding_to_text_process_batch,test_text_to_embedding_to_text_pipeline_single_sentence, andtest_text_to_embedding_to_text_pipeline_single_sentence. However, these useHFclasses i.e. not part of this PRInclude full command line to help other people reproduce if needed.