feat: add multilanguage support to text2vec and vec2text#76
feat: add multilanguage support to text2vec and vec2text#76jasonrichdarmawan wants to merge 3 commits intofacebookresearch:mainfrom
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.
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.
| task="translation", | ||
| target_lang=target_lang, | ||
| ) | ||
| if isinstance(target_lang, str): |
There was a problem hiding this comment.
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?

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.