Improved Documentation for Encoder Decoder models
Author: Threepointone4
Pull request: yes


# What does this PR do?
This PR improves the documentation of encoder decoder model.

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
       Issues [link](https://github.com/huggingface/transformers/issues/16135)


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@patrickvonplaten 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @



 -->


Comments:
_The documentation is not available anymore as the PR was closed or merged._

> Very nice! Thanks for taking the initiative here @Threepointone4. Left some suggestions to make the text a bit clearer :-) Let me know what you think!

These make sense, Thanks for the edits. 


@patrickvonplaten what are the next steps in this ? Let me know if i have to add anything.

@Threepointone4, I commited all the suggestions after having read your comment. I think we are close to merging this PR now :-) 

Could you please in a last step add this file to our documentation tests? Those ensure that the code actually runs correctly.
All you have to do is to add the name of the doc file to this file: https://github.com/huggingface/transformers/blob/38ddab10da90e64297a37c0719ed9309e693317a/utils/documentation_tests.txt#L10 

For more information on the doc tests you can read this document: 
https://github.com/huggingface/transformers/tree/main/docs#testing-documentation-examples

At the moment it seems like the doc tests would fail with the following error message:

```
109 ...     return_tensors="pt",                                                                                                                                                                                                              
110 ... ).input_ids                                                                                                                                                                                                                           
111                                                                                                                                                                                                                                           
112 >>> labels = tokenizer(                                                                                                                                                                                                                   
113 ...     "the eiffel tower surpassed the washington monument to become the tallest structure in the world. it was the first structure to reach a height of 300 metres in paris in 1930. it is now taller than the chrysler building by 5. 2
 metres ( 17 ft ) and is the second tallest free - standing structure in paris.",                                                                                                                                                             
114 ...     return_tensors="pt",                                                                                       
115 ... ).input_ids                                                                                                                                                                                                                           
116                                                                                                                    
117 >>> # the forward function automatically creates the correct decoder_input_ids                                                                                                                                                            
118 >>> loss = model(input_ids=input_ids, labels=labels).loss                                                                                                                                                                                 
UNEXPECTED EXCEPTION: ValueError("Make sure to set the decoder_start_token_id attribute of the model's configuration.")  
```

Could you try to correct it? :-)

> At the moment it seems like the doc tests would fail with the following error message:
> 
> ```
> 109 ...     return_tensors="pt",                                                                                                                                                                                                              
> 110 ... ).input_ids                                                                                                                                                                                                                           
> 111                                                                                                                                                                                                                                           
> 112 >>> labels = tokenizer(                                                                                                                                                                                                                   
> 113 ...     "the eiffel tower surpassed the washington monument to become the tallest structure in the world. it was the first structure to reach a height of 300 metres in paris in 1930. it is now taller than the chrysler building by 5. 2
>  metres ( 17 ft ) and is the second tallest free - standing structure in paris.",                                                                                                                                                             
> 114 ...     return_tensors="pt",                                                                                       
> 115 ... ).input_ids                                                                                                                                                                                                                           
> 116                                                                                                                    
> 117 >>> # the forward function automatically creates the correct decoder_input_ids                                                                                                                                                            
> 118 >>> loss = model(input_ids=input_ids, labels=labels).loss                                                                                                                                                                                 
> UNEXPECTED EXCEPTION: ValueError("Make sure to set the decoder_start_token_id attribute of the model's configuration.")  
> ```
> 
> Could you try to correct it? :-)

Hey @Threepointone4, 

Thanks a lot for having added the doc to the doc tests. Could you quickly check that they work as expected? E.g. I'm currently getting the above error when running the docs. Thanks!

> > At the moment it seems like the doc tests would fail with the following error message:
> > ```
> > 109 ...     return_tensors="pt",                                                                                                                                                                                                              
> > 110 ... ).input_ids                                                                                                                                                                                                                           
> > 111                                                                                                                                                                                                                                           
> > 112 >>> labels = tokenizer(                                                                                                                                                                                                                   
> > 113 ...     "the eiffel tower surpassed the washington monument to become the tallest structure in the world. it was the first structure to reach a height of 300 metres in paris in 1930. it is now taller than the chrysler building by 5. 2
> >  metres ( 17 ft ) and is the second tallest free - standing structure in paris.",                                                                                                                                                             
> > 114 ...     return_tensors="pt",                                                                                       
> > 115 ... ).input_ids                                                                                                                                                                                                                           
> > 116                                                                                                                    
> > 117 >>> # the forward function automatically creates the correct decoder_input_ids                                                                                                                                                            
> > 118 >>> loss = model(input_ids=input_ids, labels=labels).loss                                                                                                                                                                                 
> > UNEXPECTED EXCEPTION: ValueError("Make sure to set the decoder_start_token_id attribute of the model's configuration.")  
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Could you try to correct it? :-)
> 
> Hey @Threepointone4,
> 
> Thanks a lot for having added the doc to the doc tests. Could you quickly check that they work as expected? E.g. I'm currently getting the above error when running the docs. Thanks!

@patrickvonplaten  
I am currently running this cmd 
` pytest --doctest-modules docs/source/en/model_doc/encoder-decoder.mdx -sv --doctest-glob="*.mdx"
`
Is this proper way to do that?  I am getting different error, so just double checking .

Hey @Threepointone4,

Yes that's the correct command, but note that you need to run this command before-hand: 
```python utils/prepare_for_doc_test.py src docs```
and then you can run:
```pytest --doctest-modules docs/source/en/model_doc/encoder-decoder.mdx -sv --doctest-glob="*.mdx"```
After the command you should run: 
```python utils/prepare_for_doc_test.py src docs --remove_new_line``` once more
to re-convert the example doc strings correctly :-)

What's easier however is to do the following, add the following code into a `doc_test` file:
```
#!/usr/bin/env bash
doc_file=${1}

python utils/prepare_for_doc_test.py src docs &>/dev/null
pytest -sv --doctest-modules ${doc_file} --doctest-continue-on-failure --doctest-glob="*.mdx"
python utils/prepare_for_doc_test.py src docs --remove_new_line &>/dev/null
```

and then run:
`doc_test <path/to/python/file>` -> this will automatically prepare the doc tests before hand :-)

@patrickvonplaten Sorry for the delay. 
I have ran the cmd's you have shared and was able to reproduce the error in my local.
```
model.config.decoder_start_token_id = tokenizer.cls_token_id
model.config.pad_token_id = tokenizer.pad_token_id
```
These are changes i need to add right ? I will re-base also with original repository. 

@patrickvonplaten  what are the next steps in this ? Let me know if i have to add anything. 



Hey @Threepointone4,

It sadly looks a bit like the git history was messed up in this PR (maybe a `git rebase` was incorrectly used?)

@patrickvonplaten  I accidentally git rebase with the branch and main separately and pushed it. Can that be an issue ? 
I was waiting for your input on this. 

I see! Sorry it's quite hard to recover the PR from this :sweat_smile: Could you maybe copy-paste the files that were changed to a new PR and close this one? :-)

> I see! Sorry it's quite hard to recover the PR from this sweat_smile Could you maybe copy-paste the files that were changed to a new PR and close this one? :-)

Sure @patrickvonplaten , I will do that it will be easier.
Link for the new PR : [link](https://github.com/huggingface/transformers/pull/17815)

Thanks a lot!