guillaume-be / rust-bert

Rust native ready-to-use NLP pipelines and transformer-based models (BERT, DistilBERT, GPT2,...)
https://docs.rs/crate/rust-bert
Apache License 2.0
2.67k stars 216 forks source link

M2M100 - English to ChineseMandarin ONNX Model #463

Open chriskyndrid opened 3 months ago

chriskyndrid commented 3 months ago

I'm attempting to translate from English to ChineseMandarin. The target languages in the rust_bert crate indicate ChineseMandarin is a supported language. Additionally the documentation on hugging fast also indicates it's a supported language and even provides an example of the translation. However, the get_iso_639_1_code routine explcitly returns Language::ChineseMandarin => return None, for callers. Swapping to Language::Chinese which maps to 'zh', which I believe is the accurate code, returns an error that the language isn't valid. Thus, the ChineseMandarin language passes the validity check, but doesn't end up with an ISO code, so translation fails at:


         let language_code = target_language.get_iso_639_1_code().ok_or_else(|| {
                            RustBertError::ValueError(format!(
                                "This language has no ISO639-I language code representation. \
                            languages supported by the model: {supported_target_languages:?}"
                            ))
                        })?;

I believe the ISO check here should support ChineseMandarin and map to "zh" in the call to fetch the ISO code.