How to understand decoder_start_token_id and forced_bos_token_id in mbart?
When I want to use huggingface's pretrained models such as mbart to conduct multilingual experiments, the meaning of paramaters decoder_start_token_id and forced_bos_token_id confuse me. I find codes like:
# While generating the target text set the decoder_start_token_id to the target language id. 
# The following example shows how to translate English to Romanian 
# using the facebook/mbart-large-en-ro model.
from transformers import MBartForConditionalGeneration, MBartTokenizer

tokenizer = MBartTokenizer.from_pretrained(&quot;facebook/mbart-large-en-ro&quot;, src_lang=&quot;en_XX&quot;)
article = &quot;UN Chief Says There Is No Military Solution in Syria&quot;
inputs = tokenizer(article, return_tensors=&quot;pt&quot;)
translated_tokens = model.generate(**inputs, decoder_start_token_id=tokenizer.lang_code_to_id[&quot;ro_RO&quot;])
tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]

and:
# To generate using the mBART-50 multilingual translation models, 
# eos_token_id is used as the decoder_start_token_id and the target language id is forced as the first generated token. 
# To force the target language id as the first generated token, 
# pass the forced_bos_token_id parameter to the generate method. 
# The following example shows how to translate between Hindi to French and Arabic to English 
# using the facebook/mbart-50-large-many-to-many checkpoint.
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast

article_hi = &quot;संयुक्त राष्ट्र के प्रमुख का कहना है कि सीरिया में कोई सैन्य समाधान नहीं है&quot;
article_ar = &quot;الأمين العام للأمم المتحدة يقول إنه لا يوجد حل عسكري في سوريا.&quot;

model = MBartForConditionalGeneration.from_pretrained(&quot;facebook/mbart-large-50-many-to-many-mmt&quot;)
tokenizer = MBart50TokenizerFast.from_pretrained(&quot;facebook/mbart-large-50-many-to-many-mmt&quot;)

# translate Hindi to French
tokenizer.src_lang = &quot;hi_IN&quot;
encoded_hi = tokenizer(article_hi, return_tensors=&quot;pt&quot;)
generated_tokens = model.generate(**encoded_hi, forced_bos_token_id=tokenizer.lang_code_to_id[&quot;fr_XX&quot;])
tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
# =&gt; &quot;Le chef de l 'ONU affirme qu 'il n 'y a pas de solution militaire en Syria.&quot;

# translate Arabic to English
tokenizer.src_lang = &quot;ar_AR&quot;
encoded_ar = tokenizer(article_ar, return_tensors=&quot;pt&quot;)
generated_tokens = model.generate(**encoded_ar, forced_bos_token_id=tokenizer.lang_code_to_id[&quot;en_XX&quot;])
tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
# =&gt; &quot;The Secretary-General of the United Nations says there is no military solution in Syria.&quot;

While the annotation of this two paramaters are:
decoder_start_token_id (:obj:`int`, `optional`): 
If an encoder-decoder model starts decoding with a different token than `bos`, 
the id of that token.

forced_bos_token_id (:obj:`int`, `optional`): 
The id of the token to force as the first generated token after the :obj:`decoder_start_token_id`.
Useful for multilingual models like :doc:`mBART &lt;../model_doc/mbart&gt;` where 
the first generated token needs to be the target language token.

And for different varients of mbart, such as facebook/mbart-large-cc25 and facebook/mbart-large-50, which one should we specify to generate response of specific language?

In the standard sequence-to-sequence models, the decoding starts with providing the decoder with the [bos] symbols, it generates the word w1, which is provided as the input of the decoder in the next step. and the decoder generates the word w2. This continues until the [eos] (end-of-sentence) token is generated.
[bos] w_1  w_2  w_3
  ↓    ↓    ↓    ↓
┌──────────────────┐
│     DECODER      │
└──────────────────┘
  ↓    ↓    ↓    ↓
 w_1  w_2  w_2 [eos]

With mBART, this is more tricky because you need to tell it what the target language and source language are. For the encoder and for training data, the tokenizer takes care of that and adds the language-specific tags at the end of the source sentence and at the beginning of the target sentence. The sentences are then in format (given the source has 4 words and the target 3):

source: v1 v2 v3 v4 [src_lng]
target: [tgt_lng] w1 w2 w3 [eos]

Unlike training, at inference time, the target sentence is unknown and you want to generate it. But you still need to say the decoder what it should use instead of the generic [bos] token. This where the forced_bos_token_id comes into play. It is still the tokenizer that knows the IDs of the specific tokens. Different mBARTs have different tokenizers, you should always use the language IDs for the tokenizer that matches the models.
The attributes you mention seem to do the same thing, but I would stick to forced_bos_token_id mentioned in the mBART documentation. The method APIs in HuggingFace Transformers are very permissive and some of the attributes only apply to some models and get ignored by others. I would avoid using something that is not explicitly mentioned in the documentation of the particular model.
