Fix TF start docstrings (#18991)
* Update our TF 2.0 input format tip across all models * make style
This commit is contained in:
@@ -834,23 +834,27 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
||||
|
||||
<Tip>
|
||||
|
||||
TF 2.0 models accepts two formats as inputs:
|
||||
TensorFlow models and layers in `transformers` accept two formats as input:
|
||||
|
||||
- having all inputs as keyword arguments (like PyTorch models), or
|
||||
- having all inputs as a list, tuple or dict in the first positional arguments.
|
||||
- having all inputs as a list, tuple or dict in the first positional argument.
|
||||
|
||||
This second option is useful when using [`tf.keras.Model.fit`] method which currently requires having
|
||||
all the tensors in the first argument of the model call function: `model(inputs)`.
|
||||
The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
|
||||
and layers. Because of this support, when using methods like `model.fit()` things should "just work" for you - just
|
||||
pass your inputs and labels in any format that `model.fit()` supports! If, however, you want to use the second format outside of Keras methods like `fit()` and `predict()`, such as when creating
|
||||
your own layers or models with the Keras `Functional` API, there are three possibilities you
|
||||
can use to gather all the input Tensors in the first positional argument:
|
||||
|
||||
If you choose this second option, there are three possibilities you can use to gather all the input Tensors
|
||||
in the first positional argument :
|
||||
|
||||
- a single Tensor with `input_ids` only and nothing else: `model(inputs_ids)`
|
||||
- a single Tensor with `input_ids` only and nothing else: `model(input_ids)`
|
||||
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
|
||||
`model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
|
||||
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
|
||||
`model({"input_ids": input_ids, "token_type_ids": token_type_ids})`
|
||||
|
||||
Note that when creating models and layers with (subclassing)[https://keras.io/guides/making_new_layers_and_models_via_subclassing/]
|
||||
then you don't need to worry about any of this, as you can just pass inputs like you would to any other Python
|
||||
function!
|
||||
|
||||
</Tip>
|
||||
|
||||
Args:
|
||||
@@ -2101,16 +2105,16 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
||||
|
||||
<Tip>
|
||||
|
||||
TF 2.0 models accepts two formats as inputs:
|
||||
TensorFlow models and layers in `transformers` accept two formats as input:
|
||||
|
||||
- having all inputs as keyword arguments (like PyTorch models), or
|
||||
- having all inputs as a list, tuple or dict in the first positional arguments.
|
||||
- having all inputs as a list, tuple or dict in the first positional argument.
|
||||
|
||||
This second option is useful when using [`tf.keras.Model.fit`] method which currently requires having all
|
||||
the tensors in the first argument of the model call function: `model(inputs)`.
|
||||
|
||||
If you choose this second option, there are three possibilities you can use to gather all the input Tensors in
|
||||
the first positional argument :
|
||||
The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
|
||||
and layers. Because of this support, when using methods like `model.fit()` things should "just work" for you - just
|
||||
pass your inputs and labels in any format that `model.fit()` supports! If, however, you want to use the second format outside of Keras methods like `fit()` and `predict()`, such as when creating
|
||||
your own layers or models with the Keras `Functional` API, there are three possibilities you
|
||||
can use to gather all the input Tensors in the first positional argument:
|
||||
|
||||
- a single Tensor with `input_ids` only and nothing else: `model(input_ids)`
|
||||
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
|
||||
@@ -2118,6 +2122,10 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
||||
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
|
||||
`model({"input_ids": input_ids, "token_type_ids": token_type_ids})`
|
||||
|
||||
Note that when creating models and layers with (subclassing)[https://keras.io/guides/making_new_layers_and_models_via_subclassing/]
|
||||
then you don't need to worry about any of this, as you can just pass inputs like you would to any other Python
|
||||
function!
|
||||
|
||||
</Tip>
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user