Add a template for examples and apply it for mlm and plm examples (#8153)

* Add a template for example scripts and apply it to mlm

* Formatting

* Fix test

* Add plm script

* Add a template for example scripts and apply it to mlm

* Formatting

* Fix test

* Add plm script

* Add a template for example scripts and apply it to mlm

* Formatting

* Fix test

* Add plm script

* Styling
This commit is contained in:
Sylvain Gugger
2020-10-29 13:38:11 -04:00
committed by GitHub
parent 49e4fece5c
commit 691176283d
12 changed files with 1000 additions and 1741 deletions

View File

@@ -1,15 +1,22 @@
# How to add a new example script in 🤗Transformers
# How to add a new example script in 🤗 Transformers
This folder provide a template for adding a new example script implementing a training or inference task with the models in the 🤗Transformers library.
Add tests!
This folder provide a template for adding a new example script implementing a training or inference task with the
models in the 🤗 Transformers library. To use it, you will need to install cookiecutter:
```
pip install cookiecutter
```
or refer to the installation page of the [cookiecutter documentation](https://cookiecutter.readthedocs.io/).
You can then run the following command inside the `examples` folder of the transformers repo:
```
cookiecutter ../templates/adding_a_new_example_script/
```
and answer the questions asked, which will generate a new folder where you will find a pre-filled template for your
example following the best practices we recommend for them.
These folder can be put in a subdirectory under your example's name, like `examples/deebert`.
Adjust the way the data is preprocessed, the model is loaded or the Trainer is instantiated then when you're happy, add
a `README.md` in the folder (or complete the existing one if you added a script to an existing folder) telling a user
how to run your script.
Best Practices:
- use `Trainer`/`TFTrainer`
- write an @slow test that checks that your model can train on one batch and get a low loss.
- this test should use cuda if it's available. (e.g. by checking `transformers.torch_device`)
- adding an `eval_xxx.py` script that can evaluate a pretrained checkpoint.
- tweet about your new example with a carbon screenshot of how to run it and tag @huggingface
Make a PR to the 🤗 Transformers repo. Don't forget to tweet about your new example with a carbon screenshot of how to
run it and tag @huggingface!