-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Spanish translation of the file multilingual.mdx #16329
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a7655bc
Duplication of the source eng file
SimplyJuanjo 41fda0a
Spanish translation of the file multilingual.mdx
SimplyJuanjo 65ea0fa
Update docs/source_es/multilingual.mdx
SimplyJuanjo 5bd943d
Update docs/source_es/multilingual.mdx
SimplyJuanjo b1df2e0
Update docs/source_es/multilingual.mdx
SimplyJuanjo cdcdf68
Update docs/source_es/multilingual.mdx
SimplyJuanjo 41ad47e
Update docs/source_es/multilingual.mdx
SimplyJuanjo 62e8757
Update docs/source_es/multilingual.mdx
SimplyJuanjo a5ed421
Update docs/source_es/multilingual.mdx
SimplyJuanjo f57abb8
Fix nits and finish translation
omarespejel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| <!--Copyright 2022 The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
| --> | ||
|
|
||
| # Modelos multilingües para inferencia | ||
|
|
||
| [[open-in-colab]] | ||
|
|
||
| Existen varios modelos multilingües en los 🤗 Transformers, y su uso de inferencia difiere de los modelos monolingües. Sin embargo, no *todos* los usos de los modelos multilingües son diferentes. Algunos modelos, como [bert-base-multilingual-uncased](https://huggingface.co/bert-base-multilingual-uncased), pueden utilizarse igual que un modelo monolingüe. Esta guía le enseñará cómo utilizar modelos multilingües cuyo uso difiere en la inferencia. | ||
|
|
||
| ## XLM | ||
|
|
||
| XLM tiene diez checkpoints diferentes, de los cuales sólo uno es monolingüe. Los nueve checkpoints restantes del modelo pueden dividirse en dos categorías: los checkpoints que utilizan language embeddings y los que no. | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### XLM con language embeddings | ||
|
|
||
| Los siguientes modelos XLM usan language embeddings para especificar el lenguaje utilizado en la inferencia: | ||
|
|
||
| - `xlm-mlm-ende-1024` (Masked language modeling, English-German) | ||
| - `xlm-mlm-enfr-1024` (Masked language modeling, English-French) | ||
| - `xlm-mlm-enro-1024` (Masked language modeling, English-Romanian) | ||
| - `xlm-mlm-xnli15-1024` (Masked language modeling, XNLI languages) | ||
| - `xlm-mlm-tlm-xnli15-1024` (Masked language modeling + translation, XNLI languages) | ||
| - `xlm-clm-enfr-1024` (Causal language modeling, English-French) | ||
| - `xlm-clm-ende-1024` (Causal language modeling, English-German) | ||
|
|
||
| Los language embeddings son representados como un tensor de la mismas dimensiones que los `input_ids` pasados al modelo. Los valores de estos tensores dependen del idioma utilizado y se identifican mediante los atributos `lang2id` y `id2lang` del tokenizador. | ||
|
|
||
| En este ejemplo, cargue el checkpoint `xlm-clm-enfr-1024` (Causal language modeling, English-French): | ||
|
|
||
| ```py | ||
| >>> import torch | ||
| >>> from transformers import XLMTokenizer, XLMWithLMHeadModel | ||
|
|
||
| >>> tokenizer = XLMTokenizer.from_pretrained("xlm-clm-enfr-1024") | ||
| >>> model = XLMWithLMHeadModel.from_pretrained("xlm-clm-enfr-1024") | ||
| ``` | ||
|
|
||
| El atributo `lang2id` del tokenizador muestra los idiomas de este modelo y sus identificadors: | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```py | ||
| >>> print(tokenizer.lang2id) | ||
| {'en': 0, 'fr': 1} | ||
| ``` | ||
|
|
||
| A continuación, cree un input de ejemplo: | ||
|
|
||
| ```py | ||
| >>> input_ids = torch.tensor([tokenizer.encode("Wikipedia was used to")]) # batch size of 1 | ||
| ``` | ||
|
|
||
| Establezca el id del idioma como `"en"` y utilícelo para definir el language embedding. El language embedding es un tensor lleno de `0` ya que es el id del idioma para inglés. Este tensor debe ser del mismo tamaño que `input_ids`. | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```py | ||
| >>> language_id = tokenizer.lang2id["en"] # 0 | ||
| >>> langs = torch.tensor([language_id] * input_ids.shape[1]) # torch.tensor([0, 0, 0, ..., 0]) | ||
|
|
||
| >>> # We reshape it to be of size (batch_size, sequence_length) | ||
| >>> langs = langs.view(1, -1) # is now of shape [1, sequence_length] (we have a batch size of 1) | ||
| ``` | ||
|
|
||
| Ahora puedes pasar los `input_ids` y el language embedding al modelo: | ||
|
|
||
| ```py | ||
| >>> outputs = model(input_ids, langs=langs) | ||
| ``` | ||
|
|
||
| El script [run_generation.py](https://github.com/huggingface/transformers/tree/master/examples/pytorch/text-generation/run_generation.py) puede generar texto con language embeddings utilizando los checkpoints `xlm-clm`. | ||
|
|
||
| ### XLM sin language embeddings | ||
|
|
||
| Los siguientes modelos XLM no requieren language embeddings durante la inferencia: | ||
|
|
||
| - `xlm-mlm-17-1280` (Masked language modeling, 17 languages) | ||
| - `xlm-mlm-100-1280` (Masked language modeling, 100 languages) | ||
|
|
||
| Estos modelos se utilizan para representaciones genéricas de frases, a diferencia de los anteriores checkpoints XLM. | ||
|
|
||
| ## BERT | ||
|
|
||
| Los siguientes modelos de BERT pueden utilizarse para tareas multilingües: | ||
|
|
||
| - `bert-base-multilingual-uncased` (Masked language modeling + Next sentence prediction, 102 languages) | ||
| - `bert-base-multilingual-cased` (Masked language modeling + Next sentence prediction, 104 languages) | ||
|
|
||
| Estos modelos no requieren language embeddings durante la inferencia. Deben identificar la lengua a partir del | ||
| contexto e inferir en consecuencia. | ||
|
|
||
| ## XLM-RoBERTa | ||
|
|
||
| Los siguientes modelos de XLM-RoBERTa pueden utilizarse para tareas multilingües: | ||
|
|
||
| - `xlm-roberta-base` (Masked language modeling, 100 languages) | ||
| - `xlm-roberta-large` (Masked language modeling, 100 languages) | ||
|
|
||
| XLM-RoBERTa se entrenó con 2,5 TB de datos CommonCrawl recién creados y depurados en 100 idiomas. Proporciona fuertes ventajas sobre los modelos multilingües publicados anteriormente como mBERT o XLM en tareas posteriores como la clasificación, el etiquetado de secuencias y la respuesta a preguntas. | ||
|
|
||
| ## M2M100 | ||
|
|
||
| Los siguientes modelos de M2M100 pueden utilizarse para traducción multilingüe: | ||
|
|
||
| - `facebook/m2m100_418M` (Translation) | ||
| - `facebook/m2m100_1.2B` (Translation) | ||
|
|
||
| En este ejemplo, carga el checkpoint `facebook/m2m100_418M` para traducir del chino al inglés. Puedes establecer el idioma de origen en el tokenizador: | ||
|
|
||
| ```py | ||
| >>> from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer | ||
|
|
||
| >>> en_text = "Do not meddle in the affairs of wizards, for they are subtle and quick to anger." | ||
| >>> chinese_text = "不要插手巫師的事務, 因為他們是微妙的, 很快就會發怒." | ||
|
|
||
| >>> tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_418M", src_lang="zh") | ||
| >>> model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_418M") | ||
| ``` | ||
|
|
||
| Tokeniza el texto: | ||
|
|
||
| ```py | ||
| >>> encoded_zh = tokenizer(chinese_text, return_tensors="pt") | ||
| ``` | ||
|
|
||
| M2M100 fuerza el id del idioma de destino como el primer token generado para traducir al idioma de destino. Establezca el `forced_bos_token_id` como `en` en el método `generate` para traducir al inglés: | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```py | ||
| >>> generated_tokens = model.generate(**encoded_zh, forced_bos_token_id=tokenizer.get_lang_id("en")) | ||
| >>> tokenizer.batch_decode(generated_tokens, skip_special_tokens=True) | ||
| 'Do not interfere with the matters of the witches, because they are delicate and will soon be angry.' | ||
| ``` | ||
|
|
||
| ## MBart | ||
|
|
||
| Los siguientes modelos de MBart pueden utilizarse para traducción multilingüe: | ||
|
|
||
| - `facebook/mbart-large-50-one-to-many-mmt` (One-to-many multilingual machine translation, 50 languages) | ||
| - `facebook/mbart-large-50-many-to-many-mmt` (Many-to-many multilingual machine translation, 50 languages) | ||
| - `facebook/mbart-large-50-many-to-one-mmt` (Many-to-one multilingual machine translation, 50 languages) | ||
| - `facebook/mbart-large-50` (Multilingual translation, 50 languages) | ||
| - `facebook/mbart-large-cc25` | ||
|
|
||
| En este ejemplo, carga el checkpoint `facebook/mbart-large-50-many-to-many-mmt` para traducir el finlandés al inglés. Puedes establecer el idioma de origen en el tokenizador: | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```py | ||
| >>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | ||
|
|
||
| >>> en_text = "Do not meddle in the affairs of wizards, for they are subtle and quick to anger." | ||
| >>> fi_text = "Älä sekaannu velhojen asioihin, sillä ne ovat hienovaraisia ja nopeasti vihaisia." | ||
|
|
||
| >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-50-many-to-many-mmt", src_lang="fi_FI") | ||
| >>> model = AutoModelForSeq2SeqLM.from_pretrained("facebook/mbart-large-50-many-to-many-mmt") | ||
| ``` | ||
|
|
||
| Tokeniza el texto: | ||
|
|
||
| ```py | ||
| >>> encoded_en = tokenizer(en_text, return_tensors="pt") | ||
| ``` | ||
|
|
||
| MBart fuerza el id del idioma de destino como el primer token generado para traducir al idioma de destino. Establezca el `forced_bos_token_id` como `en` en el método `generate` para traducir al inglés: | ||
|
SimplyJuanjo marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```py | ||
| >>> generated_tokens = model.generate(**encoded_en, forced_bos_token_id=tokenizer.lang_code_to_id("en_XX")) | ||
| >>> tokenizer.batch_decode(generated_tokens, skip_special_tokens=True) | ||
| "Don't interfere with the wizard's affairs, because they are subtle, will soon get angry." | ||
| ``` | ||
|
|
||
| Si estás usando el checkpoint `facebook/mbart-large-50-many-to-one-mmt`, no necesitas forzar el id del idioma de destino como el primer token generado, de lo contrario el uso es el mismo. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.