@@ -834,23 +834,27 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
...
@@ -834,23 +834,27 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
<Tip>
<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 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
The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
all the tensors in the first argument of the model call function: `model(inputs)`.
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
- a single Tensor with `input_ids` only and nothing else: `model(input_ids)`
in the first positional argument :
- a single Tensor with `input_ids` only and nothing else: `model(inputs_ids)`
- a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
- 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])`
`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:
- a dictionary with one or several input Tensors associated to the input names given in the docstring:
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>
</Tip>
Args:
Args:
...
@@ -2101,16 +2105,16 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
...
@@ -2101,16 +2105,16 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
<Tip>
<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 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 reason the second format is supported is that Keras methods prefer this format when passing inputs to models
the tensors in the first argument of the model call function: `model(inputs)`.
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
If you choose this second option, there are three possibilities you can use to gather all the input Tensors in
your own layers or models with the Keras `Functional` API, there are three possibilities you
the first positional argument:
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 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:
- 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):
...
@@ -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:
- a dictionary with one or several input Tensors associated to the input names given in the docstring: