Unverified Commit 87e6e4fe authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Doc styler v2 (#14950)

* New doc styler

* Fix issue with args at the start

* Code sample fixes

* Style code examples in MDX

* Fix more patterns

* Typo

* Typo

* More patterns

* Do without black for now

* Get more info in error

* Docstring style

* Re-enable check

* Quality

* Fix add_end_docstring decorator

* Fix docstring
parent c1138273
...@@ -224,9 +224,7 @@ def ensure_model_and_config_inputs_match( ...@@ -224,9 +224,7 @@ def ensure_model_and_config_inputs_match(
) -> Tuple[bool, List[str]]: ) -> Tuple[bool, List[str]]:
""" """
:param model_inputs: :param model_inputs: :param config_inputs: :return:
:param config_inputs:
:return:
""" """
forward_parameters = signature(model.forward).parameters forward_parameters = signature(model.forward).parameters
model_inputs_set = set(model_inputs) model_inputs_set = set(model_inputs)
......
...@@ -271,7 +271,8 @@ def get_scheduler( ...@@ -271,7 +271,8 @@ def get_scheduler(
class AdamW(Optimizer): class AdamW(Optimizer):
""" """
Implements Adam algorithm with weight decay fix as introduced in [Decoupled Weight Decay Regularization](https://arxiv.org/abs/1711.05101). Implements Adam algorithm with weight decay fix as introduced in [Decoupled Weight Decay
Regularization](https://arxiv.org/abs/1711.05101).
Parameters: Parameters:
params (`Iterable[nn.parameter.Parameter]`): params (`Iterable[nn.parameter.Parameter]`):
...@@ -427,7 +428,8 @@ class Adafactor(Optimizer): ...@@ -427,7 +428,8 @@ class Adafactor(Optimizer):
Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None) Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None)
``` ```
When using `lr=None` with [`Trainer`] you will most likely need to use [`~optimization.AdafactorSchedule`] scheduler as following: When using `lr=None` with [`Trainer`] you will most likely need to use [`~optimization.AdafactorSchedule`]
scheduler as following:
```python ```python
from transformers.optimization import Adafactor, AdafactorSchedule from transformers.optimization import Adafactor, AdafactorSchedule
...@@ -611,9 +613,8 @@ class Adafactor(Optimizer): ...@@ -611,9 +613,8 @@ class Adafactor(Optimizer):
class AdafactorSchedule(LambdaLR): class AdafactorSchedule(LambdaLR):
""" """
Since [`~optimization.Adafactor`] performs its own scheduling, if the training loop relies on a Since [`~optimization.Adafactor`] performs its own scheduling, if the training loop relies on a scheduler (e.g.,
scheduler (e.g., for logging), this class creates a proxy object that retrieves the current lr values from the for logging), this class creates a proxy object that retrieves the current lr values from the optimizer.
optimizer.
It returns `initial_lr` during startup and the actual `lr` during stepping. It returns `initial_lr` during startup and the actual `lr` during stepping.
""" """
......
...@@ -153,7 +153,8 @@ class AdamWeightDecay(tf.keras.optimizers.Adam): ...@@ -153,7 +153,8 @@ class AdamWeightDecay(tf.keras.optimizers.Adam):
""" """
Adam enables L2 weight decay and clip_by_global_norm on gradients. Just adding the square of the weights to the Adam enables L2 weight decay and clip_by_global_norm on gradients. Just adding the square of the weights to the
loss function is *not* the correct way of using L2 regularization/weight decay with Adam, since that will interact loss function is *not* the correct way of using L2 regularization/weight decay with Adam, since that will interact
with the m and v parameters in strange ways as shown in [Decoupled Weight Decay Regularization](https://arxiv.org/abs/1711.05101). with the m and v parameters in strange ways as shown in [Decoupled Weight Decay
Regularization](https://arxiv.org/abs/1711.05101).
Instead we want ot decay the weights in a manner that doesn't interact with the m/v parameters. This is equivalent Instead we want ot decay the weights in a manner that doesn't interact with the m/v parameters. This is equivalent
to adding the square of the weights to the loss with plain (non-momentum) SGD. to adding the square of the weights to the loss with plain (non-momentum) SGD.
...@@ -168,7 +169,8 @@ class AdamWeightDecay(tf.keras.optimizers.Adam): ...@@ -168,7 +169,8 @@ class AdamWeightDecay(tf.keras.optimizers.Adam):
epsilon (`float`, *optional*, defaults to 1e-7): epsilon (`float`, *optional*, defaults to 1e-7):
The epsilon parameter in Adam, which is a small constant for numerical stability. The epsilon parameter in Adam, which is a small constant for numerical stability.
amsgrad (`bool`, *optional*, default to *False*): amsgrad (`bool`, *optional*, default to *False*):
Whether to apply AMSGrad variant of this algorithm or not, see [On the Convergence of Adam and Beyond](https://arxiv.org/abs/1904.09237). Whether to apply AMSGrad variant of this algorithm or not, see [On the Convergence of Adam and
Beyond](https://arxiv.org/abs/1904.09237).
weight_decay_rate (`float`, *optional*, defaults to 0): weight_decay_rate (`float`, *optional*, defaults to 0):
The weight decay to apply. The weight decay to apply.
include_in_weight_decay (`List[str]`, *optional*): include_in_weight_decay (`List[str]`, *optional*):
...@@ -180,10 +182,10 @@ class AdamWeightDecay(tf.keras.optimizers.Adam): ...@@ -180,10 +182,10 @@ class AdamWeightDecay(tf.keras.optimizers.Adam):
name (`str`, *optional*, defaults to 'AdamWeightDecay'): name (`str`, *optional*, defaults to 'AdamWeightDecay'):
Optional name for the operations created when applying gradients. Optional name for the operations created when applying gradients.
kwargs: kwargs:
Keyword arguments. Allowed to be {`clipnorm`, `clipvalue`, `lr`, `decay`}. `clipnorm` is clip Keyword arguments. Allowed to be {`clipnorm`, `clipvalue`, `lr`, `decay`}. `clipnorm` is clip gradients by
gradients by norm; `clipvalue` is clip gradients by value, `decay` is included for backward norm; `clipvalue` is clip gradients by value, `decay` is included for backward compatibility to allow time
compatibility to allow time inverse decay of learning rate. `lr` is included for backward compatibility, inverse decay of learning rate. `lr` is included for backward compatibility, recommended to use
recommended to use `learning_rate` instead. `learning_rate` instead.
""" """
def __init__( def __init__(
......
...@@ -338,8 +338,8 @@ def check_task(task: str) -> Tuple[Dict, Any]: ...@@ -338,8 +338,8 @@ def check_task(task: str) -> Tuple[Dict, Any]:
- `"zero-shot-classification"` - `"zero-shot-classification"`
Returns: Returns:
(task_defaults`dict`, task_options: (`tuple`, None)) The actual dictionary required to initialize the (task_defaults`dict`, task_options: (`tuple`, None)) The actual dictionary required to initialize the pipeline
pipeline and some extra task options for parametrized tasks like "translation_XX_to_YY" and some extra task options for parametrized tasks like "translation_XX_to_YY"
""" """
...@@ -387,8 +387,7 @@ def pipeline( ...@@ -387,8 +387,7 @@ def pipeline(
The task defining which pipeline will be returned. Currently accepted tasks are: The task defining which pipeline will be returned. Currently accepted tasks are:
- `"audio-classification"`: will return a [`AudioClassificationPipeline`]. - `"audio-classification"`: will return a [`AudioClassificationPipeline`].
- `"automatic-speech-recognition"`: will return a - `"automatic-speech-recognition"`: will return a [`AutomaticSpeechRecognitionPipeline`].
[`AutomaticSpeechRecognitionPipeline`].
- `"conversational"`: will return a [`ConversationalPipeline`]. - `"conversational"`: will return a [`ConversationalPipeline`].
- `"feature-extraction"`: will return a [`FeatureExtractionPipeline`]. - `"feature-extraction"`: will return a [`FeatureExtractionPipeline`].
- `"fill-mask"`: will return a [`FillMaskPipeline`]:. - `"fill-mask"`: will return a [`FillMaskPipeline`]:.
...@@ -399,8 +398,7 @@ def pipeline( ...@@ -399,8 +398,7 @@ def pipeline(
- `"text-classification"` (alias `"sentiment-analysis"` available): will return a - `"text-classification"` (alias `"sentiment-analysis"` available): will return a
[`TextClassificationPipeline`]. [`TextClassificationPipeline`].
- `"text-generation"`: will return a [`TextGenerationPipeline`]:. - `"text-generation"`: will return a [`TextGenerationPipeline`]:.
- `"token-classification"` (alias `"ner"` available): will return a - `"token-classification"` (alias `"ner"` available): will return a [`TokenClassificationPipeline`].
[`TokenClassificationPipeline`].
- `"translation"`: will return a [`TranslationPipeline`]. - `"translation"`: will return a [`TranslationPipeline`].
- `"translation_xx_to_yy"`: will return a [`TranslationPipeline`]. - `"translation_xx_to_yy"`: will return a [`TranslationPipeline`].
- `"summarization"`: will return a [`SummarizationPipeline`]. - `"summarization"`: will return a [`SummarizationPipeline`].
...@@ -408,45 +406,43 @@ def pipeline( ...@@ -408,45 +406,43 @@ def pipeline(
model (`str` or [`PreTrainedModel`] or [`TFPreTrainedModel`], *optional*): model (`str` or [`PreTrainedModel`] or [`TFPreTrainedModel`], *optional*):
The model that will be used by the pipeline to make predictions. This can be a model identifier or an The model that will be used by the pipeline to make predictions. This can be a model identifier or an
actual instance of a pretrained model inheriting from [`PreTrainedModel`] (for PyTorch) actual instance of a pretrained model inheriting from [`PreTrainedModel`] (for PyTorch) or
or [`TFPreTrainedModel`] (for TensorFlow). [`TFPreTrainedModel`] (for TensorFlow).
If not provided, the default for the `task` will be loaded. If not provided, the default for the `task` will be loaded.
config (`str` or [`PretrainedConfig`], *optional*): config (`str` or [`PretrainedConfig`], *optional*):
The configuration that will be used by the pipeline to instantiate the model. This can be a model The configuration that will be used by the pipeline to instantiate the model. This can be a model
identifier or an actual pretrained model configuration inheriting from identifier or an actual pretrained model configuration inheriting from [`PretrainedConfig`].
[`PretrainedConfig`].
If not provided, the default configuration file for the requested model will be used. That means that if If not provided, the default configuration file for the requested model will be used. That means that if
`model` is given, its default configuration will be used. However, if `model` is not supplied, `model` is given, its default configuration will be used. However, if `model` is not supplied, this
this `task`'s default model's config is used instead. `task`'s default model's config is used instead.
tokenizer (`str` or [`PreTrainedTokenizer`], *optional*): tokenizer (`str` or [`PreTrainedTokenizer`], *optional*):
The tokenizer that will be used by the pipeline to encode data for the model. This can be a model The tokenizer that will be used by the pipeline to encode data for the model. This can be a model
identifier or an actual pretrained tokenizer inheriting from [`PreTrainedTokenizer`]. identifier or an actual pretrained tokenizer inheriting from [`PreTrainedTokenizer`].
If not provided, the default tokenizer for the given `model` will be loaded (if it is a string). If If not provided, the default tokenizer for the given `model` will be loaded (if it is a string). If `model`
`model` is not specified or not a string, then the default tokenizer for `config` is loaded (if is not specified or not a string, then the default tokenizer for `config` is loaded (if it is a string).
it is a string). However, if `config` is also not given or not a string, then the default tokenizer However, if `config` is also not given or not a string, then the default tokenizer for the given `task`
for the given `task` will be loaded. will be loaded.
feature_extractor (`str` or [`PreTrainedFeatureExtractor`], *optional*): feature_extractor (`str` or [`PreTrainedFeatureExtractor`], *optional*):
The feature extractor that will be used by the pipeline to encode data for the model. This can be a model The feature extractor that will be used by the pipeline to encode data for the model. This can be a model
identifier or an actual pretrained feature extractor inheriting from identifier or an actual pretrained feature extractor inheriting from [`PreTrainedFeatureExtractor`].
[`PreTrainedFeatureExtractor`].
Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal
models. Multi-modal models will also require a tokenizer to be passed. models. Multi-modal models will also require a tokenizer to be passed.
If not provided, the default feature extractor for the given `model` will be loaded (if it is a If not provided, the default feature extractor for the given `model` will be loaded (if it is a string). If
string). If `model` is not specified or not a string, then the default feature extractor for `model` is not specified or not a string, then the default feature extractor for `config` is loaded (if it
`config` is loaded (if it is a string). However, if `config` is also not given or not a string, is a string). However, if `config` is also not given or not a string, then the default feature extractor
then the default feature extractor for the given `task` will be loaded. for the given `task` will be loaded.
framework (`str`, *optional*): framework (`str`, *optional*):
The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
must be installed. installed.
If no framework is specified, will default to the one currently installed. If no framework is specified and If no framework is specified, will default to the one currently installed. If no framework is specified and
both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is
is provided. provided.
revision(`str`, *optional*, defaults to `"main"`): revision(`str`, *optional*, defaults to `"main"`):
When passing a task name or a string model identifier: The specific model version to use. It can be a When passing a task name or a string model identifier: The specific model version to use. It can be a
branch name, a tag name, or a commit id, since we use a git-based system for storing models and other branch name, a tag name, or a commit id, since we use a git-based system for storing models and other
...@@ -454,11 +450,12 @@ def pipeline( ...@@ -454,11 +450,12 @@ def pipeline(
use_fast (`bool`, *optional*, defaults to `True`): use_fast (`bool`, *optional*, defaults to `True`):
Whether or not to use a Fast tokenizer if possible (a [`PreTrainedTokenizerFast`]). Whether or not to use a Fast tokenizer if possible (a [`PreTrainedTokenizerFast`]).
use_auth_token (`str` or *bool*, *optional*): use_auth_token (`str` or *bool*, *optional*):
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
generated when running `transformers-cli login` (stored in `~/.huggingface`). when running `transformers-cli login` (stored in `~/.huggingface`). revision(`str`, *optional*, defaults to
revision(`str`, *optional*, defaults to `"main"`): `"main"`):
model_kwargs: model_kwargs:
Additional dictionary of keyword arguments passed along to the model's `from_pretrained(..., **model_kwargs)` function. Additional dictionary of keyword arguments passed along to the model's `from_pretrained(...,
**model_kwargs)` function.
kwargs: kwargs:
Additional keyword arguments passed along to the specific pipeline init (see the documentation for the Additional keyword arguments passed along to the specific pipeline init (see the documentation for the
corresponding pipeline class for possible values). corresponding pipeline class for possible values).
......
...@@ -66,14 +66,15 @@ def ffmpeg_read(bpayload: bytes, sampling_rate: int) -> np.array: ...@@ -66,14 +66,15 @@ def ffmpeg_read(bpayload: bytes, sampling_rate: int) -> np.array:
@add_end_docstrings(PIPELINE_INIT_ARGS) @add_end_docstrings(PIPELINE_INIT_ARGS)
class AudioClassificationPipeline(Pipeline): class AudioClassificationPipeline(Pipeline):
""" """
Audio classification pipeline using any `AutoModelForAudioClassification`. This pipeline predicts the class of Audio classification pipeline using any `AutoModelForAudioClassification`. This pipeline predicts the class of a
a raw waveform or an audio file. In case of an audio file, ffmpeg should be installed to support multiple audio raw waveform or an audio file. In case of an audio file, ffmpeg should be installed to support multiple audio
formats. formats.
This pipeline can currently be loaded from [`pipeline`] using the following task identifier: This pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"audio-classification"`. `"audio-classification"`.
See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=audio-classification). See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=audio-classification).
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -92,16 +93,16 @@ class AudioClassificationPipeline(Pipeline): ...@@ -92,16 +93,16 @@ class AudioClassificationPipeline(Pipeline):
**kwargs, **kwargs,
): ):
""" """
Classify the sequence(s) given as inputs. See the [`AutomaticSpeechRecognitionPipeline`] Classify the sequence(s) given as inputs. See the [`AutomaticSpeechRecognitionPipeline`] documentation for more
documentation for more information. information.
Args: Args:
inputs (`np.ndarray` or `bytes` or `str`): inputs (`np.ndarray` or `bytes` or `str`):
The inputs is either a raw waveform (`np.ndarray` of shape (n, ) of type `np.float32` or The inputs is either a raw waveform (`np.ndarray` of shape (n, ) of type `np.float32` or `np.float64`)
`np.float64`) at the correct sampling rate (no further check will be done) or a `str` that is at the correct sampling rate (no further check will be done) or a `str` that is the filename of the
the filename of the audio file, the file will be read at the correct sampling rate to get the waveform audio file, the file will be read at the correct sampling rate to get the waveform using *ffmpeg*. This
using *ffmpeg*. This requires *ffmpeg* to be installed on the system. If *inputs* is `bytes` it is requires *ffmpeg* to be installed on the system. If *inputs* is `bytes` it is supposed to be the
supposed to be the content of an audio file and is interpreted by *ffmpeg* in the same way. content of an audio file and is interpreted by *ffmpeg* in the same way.
top_k (`int`, *optional*, defaults to None): top_k (`int`, *optional*, defaults to None):
The number of top labels that will be returned by the pipeline. If the provided number is *None* or The number of top labels that will be returned by the pipeline. If the provided number is *None* or
higher than the number of labels available in the model configuration, it will default to the number of higher than the number of labels available in the model configuration, it will default to the number of
......
...@@ -81,20 +81,19 @@ class AutomaticSpeechRecognitionPipeline(Pipeline): ...@@ -81,20 +81,19 @@ class AutomaticSpeechRecognitionPipeline(Pipeline):
The feature extractor that will be used by the pipeline to encode waveform for the model. The feature extractor that will be used by the pipeline to encode waveform for the model.
model ([`PreTrainedModel`] or [`TFPreTrainedModel`]): model ([`PreTrainedModel`] or [`TFPreTrainedModel`]):
The model that will be used by the pipeline to make predictions. This needs to be a model inheriting The model that will be used by the pipeline to make predictions. This needs to be a model inheriting
from [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] from [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow.
for TensorFlow.
tokenizer ([`PreTrainedTokenizer`]): tokenizer ([`PreTrainedTokenizer`]):
The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from
[`PreTrainedTokenizer`]. [`PreTrainedTokenizer`].
modelcard (`str` or [`ModelCard`], *optional*): modelcard (`str` or [`ModelCard`], *optional*):
Model card attributed to the model for this pipeline. Model card attributed to the model for this pipeline.
framework (`str`, *optional*): framework (`str`, *optional*):
The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must
framework must be installed. be installed.
If no framework is specified, will default to the one currently installed. If no framework is specified If no framework is specified, will default to the one currently installed. If no framework is specified
and both frameworks are installed, will default to the framework of the `model`, or to PyTorch if and both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no
no model is provided. model is provided.
device (`int`, *optional*, defaults to -1): device (`int`, *optional*, defaults to -1):
Device ordinal for CPU/GPU supports. Setting this to -1 will leverage CPU, a positive will run the Device ordinal for CPU/GPU supports. Setting this to -1 will leverage CPU, a positive will run the
model on the associated CUDA device id. model on the associated CUDA device id.
...@@ -114,16 +113,16 @@ class AutomaticSpeechRecognitionPipeline(Pipeline): ...@@ -114,16 +113,16 @@ class AutomaticSpeechRecognitionPipeline(Pipeline):
**kwargs, **kwargs,
): ):
""" """
Classify the sequence(s) given as inputs. See the [`AutomaticSpeechRecognitionPipeline`] Classify the sequence(s) given as inputs. See the [`AutomaticSpeechRecognitionPipeline`] documentation for more
documentation for more information. information.
Args: Args:
inputs (`np.ndarray` or `bytes` or `str`): inputs (`np.ndarray` or `bytes` or `str`):
The inputs is either a raw waveform (`np.ndarray` of shape (n, ) of type `np.float32` or The inputs is either a raw waveform (`np.ndarray` of shape (n, ) of type `np.float32` or `np.float64`)
`np.float64`) at the correct sampling rate (no further check will be done) or a `str` that is at the correct sampling rate (no further check will be done) or a `str` that is the filename of the
the filename of the audio file, the file will be read at the correct sampling rate to get the waveform audio file, the file will be read at the correct sampling rate to get the waveform using *ffmpeg*. This
using *ffmpeg*. This requires *ffmpeg* to be installed on the system. If *inputs* is `bytes` it is requires *ffmpeg* to be installed on the system. If *inputs* is `bytes` it is supposed to be the
supposed to be the content of an audio file and is interpreted by *ffmpeg* in the same way. content of an audio file and is interpreted by *ffmpeg* in the same way.
Return: Return:
A `dict` with the following keys: A `dict` with the following keys:
......
...@@ -152,16 +152,15 @@ def infer_framework_load_model( ...@@ -152,16 +152,15 @@ def infer_framework_load_model(
""" """
Select framework (TensorFlow or PyTorch) to use from the `model` passed. Returns a tuple (framework, model). Select framework (TensorFlow or PyTorch) to use from the `model` passed. Returns a tuple (framework, model).
If `model` is instantiated, this function will just infer the framework from the model class. Otherwise If `model` is instantiated, this function will just infer the framework from the model class. Otherwise `model` is
`model` is actually a checkpoint name and this method will try to instantiate it using `model_classes`. actually a checkpoint name and this method will try to instantiate it using `model_classes`. Since we don't want to
Since we don't want to instantiate the model twice, this model is returned for use by the pipeline. instantiate the model twice, this model is returned for use by the pipeline.
If both frameworks are installed and available for `model`, PyTorch is selected. If both frameworks are installed and available for `model`, PyTorch is selected.
Args: Args:
model (`str`, [`PreTrainedModel`] or [`TFPreTrainedModel`]): model (`str`, [`PreTrainedModel`] or [`TFPreTrainedModel`]):
The model to infer the framework from. If `str`, a checkpoint name. The model to infer the framewrok The model to infer the framework from. If `str`, a checkpoint name. The model to infer the framewrok from.
from.
config ([`AutoConfig`]): config ([`AutoConfig`]):
The config associated with the model to help using the correct class The config associated with the model to help using the correct class
model_classes (dictionary `str` to `type`, *optional*): model_classes (dictionary `str` to `type`, *optional*):
...@@ -169,7 +168,8 @@ def infer_framework_load_model( ...@@ -169,7 +168,8 @@ def infer_framework_load_model(
task (`str`): task (`str`):
The task defining which pipeline will be returned. The task defining which pipeline will be returned.
model_kwargs: model_kwargs:
Additional dictionary of keyword arguments passed along to the model's `from_pretrained(..., **model_kwargs)` function. Additional dictionary of keyword arguments passed along to the model's `from_pretrained(...,
**model_kwargs)` function.
Returns: Returns:
`Tuple`: A tuple framework, model. `Tuple`: A tuple framework, model.
...@@ -248,22 +248,22 @@ def infer_framework_from_model( ...@@ -248,22 +248,22 @@ def infer_framework_from_model(
""" """
Select framework (TensorFlow or PyTorch) to use from the `model` passed. Returns a tuple (framework, model). Select framework (TensorFlow or PyTorch) to use from the `model` passed. Returns a tuple (framework, model).
If `model` is instantiated, this function will just infer the framework from the model class. Otherwise If `model` is instantiated, this function will just infer the framework from the model class. Otherwise `model` is
`model` is actually a checkpoint name and this method will try to instantiate it using `model_classes`. actually a checkpoint name and this method will try to instantiate it using `model_classes`. Since we don't want to
Since we don't want to instantiate the model twice, this model is returned for use by the pipeline. instantiate the model twice, this model is returned for use by the pipeline.
If both frameworks are installed and available for `model`, PyTorch is selected. If both frameworks are installed and available for `model`, PyTorch is selected.
Args: Args:
model (`str`, [`PreTrainedModel`] or [`TFPreTrainedModel`]): model (`str`, [`PreTrainedModel`] or [`TFPreTrainedModel`]):
The model to infer the framework from. If `str`, a checkpoint name. The model to infer the framewrok The model to infer the framework from. If `str`, a checkpoint name. The model to infer the framewrok from.
from.
model_classes (dictionary `str` to `type`, *optional*): model_classes (dictionary `str` to `type`, *optional*):
A mapping framework to class. A mapping framework to class.
task (`str`): task (`str`):
The task defining which pipeline will be returned. The task defining which pipeline will be returned.
model_kwargs: model_kwargs:
Additional dictionary of keyword arguments passed along to the model's `from_pretrained(..., **model_kwargs)` function. Additional dictionary of keyword arguments passed along to the model's `from_pretrained(...,
**model_kwargs)` function.
Returns: Returns:
`Tuple`: A tuple framework, model. `Tuple`: A tuple framework, model.
...@@ -389,8 +389,8 @@ class PipelineDataFormat: ...@@ -389,8 +389,8 @@ class PipelineDataFormat:
- CSV - CSV
- stdin/stdout (pipe) - stdin/stdout (pipe)
`PipelineDataFormat` also includes some utilities to work with multi-columns like mapping from datasets `PipelineDataFormat` also includes some utilities to work with multi-columns like mapping from datasets columns to
columns to pipelines keyword arguments through the `dataset_kwarg_1=dataset_column_1` format. pipelines keyword arguments through the `dataset_kwarg_1=dataset_column_1` format.
Args: Args:
output_path (`str`, *optional*): Where to save the outgoing data. output_path (`str`, *optional*): Where to save the outgoing data.
...@@ -432,8 +432,7 @@ class PipelineDataFormat: ...@@ -432,8 +432,7 @@ class PipelineDataFormat:
@abstractmethod @abstractmethod
def save(self, data: Union[dict, List[dict]]): def save(self, data: Union[dict, List[dict]]):
""" """
Save the provided data object with the representation for the current Save the provided data object with the representation for the current [`~pipelines.PipelineDataFormat`].
[`~pipelines.PipelineDataFormat`].
Args: Args:
data (`dict` or list of `dict`): The data to store. data (`dict` or list of `dict`): The data to store.
...@@ -467,8 +466,7 @@ class PipelineDataFormat: ...@@ -467,8 +466,7 @@ class PipelineDataFormat:
overwrite=False, overwrite=False,
) -> "PipelineDataFormat": ) -> "PipelineDataFormat":
""" """
Creates an instance of the right subclass of [`~pipelines.PipelineDataFormat`] depending on Creates an instance of the right subclass of [`~pipelines.PipelineDataFormat`] depending on `format`.
`format`.
Args: Args:
format: (`str`): format: (`str`):
...@@ -527,8 +525,7 @@ class CsvPipelineDataFormat(PipelineDataFormat): ...@@ -527,8 +525,7 @@ class CsvPipelineDataFormat(PipelineDataFormat):
def save(self, data: List[dict]): def save(self, data: List[dict]):
""" """
Save the provided data object with the representation for the current Save the provided data object with the representation for the current [`~pipelines.PipelineDataFormat`].
[`~pipelines.PipelineDataFormat`].
Args: Args:
data (`List[dict]`): The data to store. data (`List[dict]`): The data to store.
...@@ -649,20 +646,19 @@ PIPELINE_INIT_ARGS = r""" ...@@ -649,20 +646,19 @@ PIPELINE_INIT_ARGS = r"""
Arguments: Arguments:
model ([`PreTrainedModel`] or [`TFPreTrainedModel`]): model ([`PreTrainedModel`] or [`TFPreTrainedModel`]):
The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from
[`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow.
TensorFlow.
tokenizer ([`PreTrainedTokenizer`]): tokenizer ([`PreTrainedTokenizer`]):
The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from
[`PreTrainedTokenizer`]. [`PreTrainedTokenizer`].
modelcard (`str` or [`ModelCard`], *optional*): modelcard (`str` or [`ModelCard`], *optional*):
Model card attributed to the model for this pipeline. Model card attributed to the model for this pipeline.
framework (`str`, *optional*): framework (`str`, *optional*):
The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
must be installed. installed.
If no framework is specified, will default to the one currently installed. If no framework is specified and If no framework is specified, will default to the one currently installed. If no framework is specified and
both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is
is provided. provided.
task (`str`, defaults to `""`): task (`str`, defaults to `""`):
A task-identifier for the pipeline. A task-identifier for the pipeline.
num_workers (`int`, *optional*, defaults to 8): num_workers (`int`, *optional*, defaults to 8):
...@@ -670,7 +666,8 @@ PIPELINE_INIT_ARGS = r""" ...@@ -670,7 +666,8 @@ PIPELINE_INIT_ARGS = r"""
workers to be used. workers to be used.
batch_size (`int`, *optional*, defaults to 1): batch_size (`int`, *optional*, defaults to 1):
When the pipeline will use *DataLoader* (when passing a dataset, on GPU for a Pytorch model), the size of When the pipeline will use *DataLoader* (when passing a dataset, on GPU for a Pytorch model), the size of
the batch to use, for inference this is not always beneficial, please read [Batching with pipelines](https://huggingface.co/transformers/main_classes/pipelines.html#pipeline-batching) . the batch to use, for inference this is not always beneficial, please read [Batching with
pipelines](https://huggingface.co/transformers/main_classes/pipelines.html#pipeline-batching) .
args_parser ([`~pipelines.ArgumentHandler`], *optional*): args_parser ([`~pipelines.ArgumentHandler`], *optional*):
Reference to the object in charge of parsing supplied pipeline parameters. Reference to the object in charge of parsing supplied pipeline parameters.
device (`int`, *optional*, defaults to -1): device (`int`, *optional*, defaults to -1):
...@@ -702,10 +699,9 @@ class Pipeline(_ScikitCompat): ...@@ -702,10 +699,9 @@ class Pipeline(_ScikitCompat):
Pipeline supports running on CPU or GPU through the device argument (see below). Pipeline supports running on CPU or GPU through the device argument (see below).
Some pipeline, like for instance [`FeatureExtractionPipeline`] (`'feature-extraction'`) Some pipeline, like for instance [`FeatureExtractionPipeline`] (`'feature-extraction'`) output large tensor object
output large tensor object as nested-lists. In order to avoid dumping such large structure as textual data we as nested-lists. In order to avoid dumping such large structure as textual data we provide the `binary_output`
provide the `binary_output` constructor argument. If set to `True`, the output will be stored in the constructor argument. If set to `True`, the output will be stored in the pickle format.
pickle format.
""" """
default_input_names = None default_input_names = None
...@@ -815,7 +811,8 @@ class Pipeline(_ScikitCompat): ...@@ -815,7 +811,8 @@ class Pipeline(_ScikitCompat):
Ensure PyTorch tensors are on the specified device. Ensure PyTorch tensors are on the specified device.
Args: Args:
inputs (keyword arguments that should be `torch.Tensor`, the rest is ignored): The tensors to place on `self.device`. inputs (keyword arguments that should be `torch.Tensor`, the rest is ignored):
The tensors to place on `self.device`.
Recursive on lists **only**. Recursive on lists **only**.
Return: Return:
......
...@@ -19,17 +19,15 @@ logger = logging.get_logger(__name__) ...@@ -19,17 +19,15 @@ logger = logging.get_logger(__name__)
class Conversation: class Conversation:
""" """
Utility class containing a conversation and its history. This class is meant to be used as an input to the Utility class containing a conversation and its history. This class is meant to be used as an input to the
[`ConversationalPipeline`]. The conversation contains a number of utility function to manage the [`ConversationalPipeline`]. The conversation contains a number of utility function to manage the addition of new
addition of new user input and generated model responses. A conversation needs to contain an unprocessed user input user input and generated model responses. A conversation needs to contain an unprocessed user input before being
before being passed to the [`ConversationalPipeline`]. This user input is either created when passed to the [`ConversationalPipeline`]. This user input is either created when the class is instantiated, or by
the class is instantiated, or by calling `conversational_pipeline.append_response("input")` after a calling `conversational_pipeline.append_response("input")` after a conversation turn.
conversation turn.
Arguments: Arguments:
text (`str`, *optional*): text (`str`, *optional*):
The initial user input to start the conversation. If not provided, a user input needs to be provided The initial user input to start the conversation. If not provided, a user input needs to be provided
manually using the [`~Conversation.add_user_input`] method before the conversation can manually using the [`~Conversation.add_user_input`] method before the conversation can begin.
begin.
conversation_id (`uuid.UUID`, *optional*): conversation_id (`uuid.UUID`, *optional*):
Unique identifier for the conversation. If not provided, a random UUID4 id will be assigned to the Unique identifier for the conversation. If not provided, a random UUID4 id will be assigned to the
conversation. conversation.
...@@ -84,8 +82,7 @@ class Conversation: ...@@ -84,8 +82,7 @@ class Conversation:
def add_user_input(self, text: str, overwrite: bool = False): def add_user_input(self, text: str, overwrite: bool = False):
""" """
Add a user input to the conversation for the next round. This populates the internal `new_user_input` Add a user input to the conversation for the next round. This populates the internal `new_user_input` field.
field.
Args: Args:
text (`str`): The user input for the next conversation round. text (`str`): The user input for the next conversation round.
...@@ -109,8 +106,8 @@ class Conversation: ...@@ -109,8 +106,8 @@ class Conversation:
def mark_processed(self): def mark_processed(self):
""" """
Mark the conversation as processed (moves the content of `new_user_input` to `past_user_inputs`) and Mark the conversation as processed (moves the content of `new_user_input` to `past_user_inputs`) and empties
empties the `new_user_input` field. the `new_user_input` field.
""" """
if self.new_user_input: if self.new_user_input:
self.past_user_inputs.append(self.new_user_input) self.past_user_inputs.append(self.new_user_input)
...@@ -129,8 +126,8 @@ class Conversation: ...@@ -129,8 +126,8 @@ class Conversation:
""" """
Iterates over all blobs of the conversation. Iterates over all blobs of the conversation.
Returns: Iterator of (is_user, text_chunk) in chronological order of the conversation. `is_user` is a Returns: Iterator of (is_user, text_chunk) in chronological order of the conversation. `is_user` is a `bool`,
`bool`, `text_chunks` is a `str`. `text_chunks` is a `str`.
""" """
for user_input, generated_response in zip(self.past_user_inputs, self.generated_responses): for user_input, generated_response in zip(self.past_user_inputs, self.generated_responses):
yield True, user_input yield True, user_input
...@@ -168,12 +165,13 @@ class ConversationalPipeline(Pipeline): ...@@ -168,12 +165,13 @@ class ConversationalPipeline(Pipeline):
""" """
Multi-turn conversational pipeline. Multi-turn conversational pipeline.
This conversational pipeline can currently be loaded from [`pipeline`] using the following task This conversational pipeline can currently be loaded from [`pipeline`] using the following task identifier:
identifier: `"conversational"`. `"conversational"`.
The models that this pipeline can use are models that have been fine-tuned on a multi-turn conversational task, The models that this pipeline can use are models that have been fine-tuned on a multi-turn conversational task,
currently: *'microsoft/DialoGPT-small'*, *'microsoft/DialoGPT-medium'*, *'microsoft/DialoGPT-large'*. See the currently: *'microsoft/DialoGPT-small'*, *'microsoft/DialoGPT-medium'*, *'microsoft/DialoGPT-large'*. See the
up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=conversational). up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=conversational).
Usage: Usage:
...@@ -232,8 +230,8 @@ class ConversationalPipeline(Pipeline): ...@@ -232,8 +230,8 @@ class ConversationalPipeline(Pipeline):
corresponding to your framework [here](./model#generative-models)). corresponding to your framework [here](./model#generative-models)).
Returns: Returns:
[`Conversation`] or a list of [`Conversation`]: Conversation(s) with [`Conversation`] or a list of [`Conversation`]: Conversation(s) with updated generated responses for those
updated generated responses for those containing a new user input. containing a new user input.
""" """
# XXX: num_workers==0 is required to be backward compatible # XXX: num_workers==0 is required to be backward compatible
# Otherwise the threads will require a Conversation copy. # Otherwise the threads will require a Conversation copy.
......
...@@ -9,8 +9,8 @@ class FeatureExtractionPipeline(Pipeline): ...@@ -9,8 +9,8 @@ class FeatureExtractionPipeline(Pipeline):
Feature extraction pipeline using no model head. This pipeline extracts the hidden states from the base Feature extraction pipeline using no model head. This pipeline extracts the hidden states from the base
transformer, which can be used as features in downstream tasks. transformer, which can be used as features in downstream tasks.
This feature extraction pipeline can currently be loaded from [`pipeline`] using the task This feature extraction pipeline can currently be loaded from [`pipeline`] using the task identifier:
identifier: `"feature-extraction"`. `"feature-extraction"`.
All models may be used for this pipeline. See a list of all models, including community-contributed models on All models may be used for this pipeline. See a list of all models, including community-contributed models on
[huggingface.co/models](https://huggingface.co/models). [huggingface.co/models](https://huggingface.co/models).
...@@ -18,20 +18,19 @@ class FeatureExtractionPipeline(Pipeline): ...@@ -18,20 +18,19 @@ class FeatureExtractionPipeline(Pipeline):
Arguments: Arguments:
model ([`PreTrainedModel`] or [`TFPreTrainedModel`]): model ([`PreTrainedModel`] or [`TFPreTrainedModel`]):
The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from
[`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow.
TensorFlow.
tokenizer ([`PreTrainedTokenizer`]): tokenizer ([`PreTrainedTokenizer`]):
The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from
[`PreTrainedTokenizer`]. [`PreTrainedTokenizer`].
modelcard (`str` or [`ModelCard`], *optional*): modelcard (`str` or [`ModelCard`], *optional*):
Model card attributed to the model for this pipeline. Model card attributed to the model for this pipeline.
framework (`str`, *optional*): framework (`str`, *optional*):
The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
must be installed. installed.
If no framework is specified, will default to the one currently installed. If no framework is specified and If no framework is specified, will default to the one currently installed. If no framework is specified and
both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is
is provided. provided.
task (`str`, defaults to `""`): task (`str`, defaults to `""`):
A task-identifier for the pipeline. A task-identifier for the pipeline.
args_parser ([`~pipelines.ArgumentHandler`], *optional*): args_parser ([`~pipelines.ArgumentHandler`], *optional*):
......
...@@ -35,8 +35,8 @@ class FillMaskPipeline(Pipeline): ...@@ -35,8 +35,8 @@ class FillMaskPipeline(Pipeline):
Masked language modeling prediction pipeline using any `ModelWithLMHead`. See the [masked language modeling Masked language modeling prediction pipeline using any `ModelWithLMHead`. See the [masked language modeling
examples](../task_summary#masked-language-modeling) for more information. examples](../task_summary#masked-language-modeling) for more information.
This mask filling pipeline can currently be loaded from [`pipeline`] using the following task This mask filling pipeline can currently be loaded from [`pipeline`] using the following task identifier:
identifier: `"fill-mask"`. `"fill-mask"`.
The models that this pipeline can use are models that have been trained with a masked language modeling objective, The models that this pipeline can use are models that have been trained with a masked language modeling objective,
which includes the bi-directional models in the library. See the up-to-date list of available models on which includes the bi-directional models in the library. See the up-to-date list of available models on
...@@ -45,8 +45,8 @@ class FillMaskPipeline(Pipeline): ...@@ -45,8 +45,8 @@ class FillMaskPipeline(Pipeline):
<Tip> <Tip>
This pipeline only works for inputs with exactly one token masked. Experimental: We added support for multiple This pipeline only works for inputs with exactly one token masked. Experimental: We added support for multiple
masks. The returned values are raw model output, and correspond to disjoint probabilities where one might masks. The returned values are raw model output, and correspond to disjoint probabilities where one might expect
expect joint probabilities (See [discussion](https://github.com/huggingface/transformers/pull/10222)). joint probabilities (See [discussion](https://github.com/huggingface/transformers/pull/10222)).
</Tip>""" </Tip>"""
......
...@@ -19,13 +19,14 @@ logger = logging.get_logger(__name__) ...@@ -19,13 +19,14 @@ logger = logging.get_logger(__name__)
@add_end_docstrings(PIPELINE_INIT_ARGS) @add_end_docstrings(PIPELINE_INIT_ARGS)
class ImageClassificationPipeline(Pipeline): class ImageClassificationPipeline(Pipeline):
""" """
Image classification pipeline using any `AutoModelForImageClassification`. This pipeline predicts the class of Image classification pipeline using any `AutoModelForImageClassification`. This pipeline predicts the class of an
an image. image.
This image classification pipeline can currently be loaded from [`pipeline`] using the following This image classification pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"image-classification"`. `"image-classification"`.
See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=image-classification). See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=image-classification).
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
...@@ -29,13 +29,14 @@ Predictions = List[Prediction] ...@@ -29,13 +29,14 @@ Predictions = List[Prediction]
@add_end_docstrings(PIPELINE_INIT_ARGS) @add_end_docstrings(PIPELINE_INIT_ARGS)
class ImageSegmentationPipeline(Pipeline): class ImageSegmentationPipeline(Pipeline):
""" """
Image segmentation pipeline using any `AutoModelForImageSegmentation`. This pipeline predicts masks of objects Image segmentation pipeline using any `AutoModelForImageSegmentation`. This pipeline predicts masks of objects and
and their classes. their classes.
This image segmntation pipeline can currently be loaded from [`pipeline`] using the following This image segmntation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"image-segmentation"`. `"image-segmentation"`.
See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=image-segmentation). See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=image-segmentation).
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
...@@ -24,11 +24,11 @@ Predictions = List[Prediction] ...@@ -24,11 +24,11 @@ Predictions = List[Prediction]
@add_end_docstrings(PIPELINE_INIT_ARGS) @add_end_docstrings(PIPELINE_INIT_ARGS)
class ObjectDetectionPipeline(Pipeline): class ObjectDetectionPipeline(Pipeline):
""" """
Object detection pipeline using any `AutoModelForObjectDetection`. This pipeline predicts bounding boxes of Object detection pipeline using any `AutoModelForObjectDetection`. This pipeline predicts bounding boxes of objects
objects and their classes. and their classes.
This object detection pipeline can currently be loaded from [`pipeline`] using the following task This object detection pipeline can currently be loaded from [`pipeline`] using the following task identifier:
identifier: `"object-detection"`. `"object-detection"`.
See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=object-detection). See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=object-detection).
""" """
......
...@@ -34,8 +34,8 @@ class QuestionAnsweringArgumentHandler(ArgumentHandler): ...@@ -34,8 +34,8 @@ class QuestionAnsweringArgumentHandler(ArgumentHandler):
QuestionAnsweringPipeline requires the user to provide multiple arguments (i.e. question & context) to be mapped to QuestionAnsweringPipeline requires the user to provide multiple arguments (i.e. question & context) to be mapped to
internal [`SquadExample`]. internal [`SquadExample`].
QuestionAnsweringArgumentHandler manages all the possible to create a [`SquadExample`] from the QuestionAnsweringArgumentHandler manages all the possible to create a [`SquadExample`] from the command-line
command-line supplied arguments. supplied arguments.
""" """
def normalize(self, item): def normalize(self, item):
...@@ -101,13 +101,15 @@ class QuestionAnsweringArgumentHandler(ArgumentHandler): ...@@ -101,13 +101,15 @@ class QuestionAnsweringArgumentHandler(ArgumentHandler):
@add_end_docstrings(PIPELINE_INIT_ARGS) @add_end_docstrings(PIPELINE_INIT_ARGS)
class QuestionAnsweringPipeline(ChunkPipeline): class QuestionAnsweringPipeline(ChunkPipeline):
""" """
Question Answering pipeline using any `ModelForQuestionAnswering`. See the [question answering examples](../task_summary#question-answering) for more information. Question Answering pipeline using any `ModelForQuestionAnswering`. See the [question answering
examples](../task_summary#question-answering) for more information.
This question answering pipeline can currently be loaded from [`pipeline`] using the following This question answering pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"question-answering"`. `"question-answering"`.
The models that this pipeline can use are models that have been fine-tuned on a question answering task. See the The models that this pipeline can use are models that have been fine-tuned on a question answering task. See the
up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=question-answering). up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=question-answering).
""" """
default_input_names = "question,context" default_input_names = "question,context"
...@@ -143,8 +145,8 @@ class QuestionAnsweringPipeline(ChunkPipeline): ...@@ -143,8 +145,8 @@ class QuestionAnsweringPipeline(ChunkPipeline):
question: Union[str, List[str]], context: Union[str, List[str]] question: Union[str, List[str]], context: Union[str, List[str]]
) -> Union[SquadExample, List[SquadExample]]: ) -> Union[SquadExample, List[SquadExample]]:
""" """
QuestionAnsweringPipeline leverages the [`SquadExample`] internally. This helper method QuestionAnsweringPipeline leverages the [`SquadExample`] internally. This helper method encapsulate all the
encapsulate all the logic for converting question(s) and context(s) to [`SquadExample`]. logic for converting question(s) and context(s) to [`SquadExample`].
We currently support extractive question answering. We currently support extractive question answering.
...@@ -153,8 +155,7 @@ class QuestionAnsweringPipeline(ChunkPipeline): ...@@ -153,8 +155,7 @@ class QuestionAnsweringPipeline(ChunkPipeline):
context (`str` or `List[str]`): The context(s) in which we will look for the answer. context (`str` or `List[str]`): The context(s) in which we will look for the answer.
Returns: Returns:
One or a list of [`SquadExample`]: The corresponding [`SquadExample`] One or a list of [`SquadExample`]: The corresponding [`SquadExample`] grouping question and context.
grouping question and context.
""" """
if isinstance(question, list): if isinstance(question, list):
return [SquadExample(None, q, c, None, None, None) for q, c in zip(question, context)] return [SquadExample(None, q, c, None, None, None) for q, c in zip(question, context)]
...@@ -207,11 +208,11 @@ class QuestionAnsweringPipeline(ChunkPipeline): ...@@ -207,11 +208,11 @@ class QuestionAnsweringPipeline(ChunkPipeline):
args ([`SquadExample`] or a list of [`SquadExample`]): args ([`SquadExample`] or a list of [`SquadExample`]):
One or several [`SquadExample`] containing the question and context. One or several [`SquadExample`] containing the question and context.
X ([`SquadExample`] or a list of [`SquadExample`], *optional*): X ([`SquadExample`] or a list of [`SquadExample`], *optional*):
One or several [`SquadExample`] containing the question and context (will be treated One or several [`SquadExample`] containing the question and context (will be treated the same way as if
the same way as if passed as the first positional argument). passed as the first positional argument).
data ([`SquadExample`] or a list of [`SquadExample`], *optional*): data ([`SquadExample`] or a list of [`SquadExample`], *optional*):
One or several [`SquadExample`] containing the question and context (will be treated One or several [`SquadExample`] containing the question and context (will be treated the same way as if
the same way as if passed as the first positional argument). passed as the first positional argument).
question (`str` or `List[str]`): question (`str` or `List[str]`):
One or several question(s) (must be used in conjunction with the `context` argument). One or several question(s) (must be used in conjunction with the `context` argument).
context (`str` or `List[str]`): context (`str` or `List[str]`):
...@@ -237,8 +238,7 @@ class QuestionAnsweringPipeline(ChunkPipeline): ...@@ -237,8 +238,7 @@ class QuestionAnsweringPipeline(ChunkPipeline):
A `dict` or a list of `dict`: Each result comes as a dictionary with the following keys: A `dict` or a list of `dict`: Each result comes as a dictionary with the following keys:
- **score** (`float`) -- The probability associated to the answer. - **score** (`float`) -- The probability associated to the answer.
- **start** (`int`) -- The character start index of the answer (in the tokenized version of the - **start** (`int`) -- The character start index of the answer (in the tokenized version of the input).
input).
- **end** (`int`) -- The character end index of the answer (in the tokenized version of the input). - **end** (`int`) -- The character end index of the answer (in the tokenized version of the input).
- **answer** (`str`) -- The answer to the question. - **answer** (`str`) -- The answer to the question.
""" """
......
...@@ -85,11 +85,12 @@ class TableQuestionAnsweringPipeline(Pipeline): ...@@ -85,11 +85,12 @@ class TableQuestionAnsweringPipeline(Pipeline):
Table Question Answering pipeline using a `ModelForTableQuestionAnswering`. This pipeline is only available in Table Question Answering pipeline using a `ModelForTableQuestionAnswering`. This pipeline is only available in
PyTorch. PyTorch.
This tabular question answering pipeline can currently be loaded from [`pipeline`] using the This tabular question answering pipeline can currently be loaded from [`pipeline`] using the following task
following task identifier: `"table-question-answering"`. identifier: `"table-question-answering"`.
The models that this pipeline can use are models that have been fine-tuned on a tabular question answering task. The models that this pipeline can use are models that have been fine-tuned on a tabular question answering task.
See the up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=table-question-answering). See the up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=table-question-answering).
""" """
default_input_names = "table,query" default_input_names = "table,query"
...@@ -287,29 +288,29 @@ class TableQuestionAnsweringPipeline(Pipeline): ...@@ -287,29 +288,29 @@ class TableQuestionAnsweringPipeline(Pipeline):
padding (`bool`, `str` or [`~file_utils.PaddingStrategy`], *optional*, defaults to `False`): padding (`bool`, `str` or [`~file_utils.PaddingStrategy`], *optional*, defaults to `False`):
Activates and controls padding. Accepts the following values: Activates and controls padding. Accepts the following values:
- `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
single sequence if provided). sequence if provided).
- `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
maximum acceptable input length for the model if that argument is not provided. acceptable input length for the model if that argument is not provided.
- `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
different lengths). lengths).
truncation (`bool`, `str` or [`TapasTruncationStrategy`], *optional*, defaults to `False`): truncation (`bool`, `str` or [`TapasTruncationStrategy`], *optional*, defaults to `False`):
Activates and controls truncation. Accepts the following values: Activates and controls truncation. Accepts the following values:
- `True` or `'drop_rows_to_fit'`: Truncate to a maximum length specified with the argument - `True` or `'drop_rows_to_fit'`: Truncate to a maximum length specified with the argument `max_length`
`max_length` or to the maximum acceptable input length for the model if that argument is not or to the maximum acceptable input length for the model if that argument is not provided. This will
provided. This will truncate row by row, removing rows from the table. truncate row by row, removing rows from the table.
- `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
sequence lengths greater than the model maximum admissible input size). greater than the model maximum admissible input size).
Return: Return:
A dictionary or a list of dictionaries containing results: Each result is a dictionary with the following A dictionary or a list of dictionaries containing results: Each result is a dictionary with the following
keys: keys:
- **answer** (`str`) -- The answer of the query given the table. If there is an aggregator, the answer - **answer** (`str`) -- The answer of the query given the table. If there is an aggregator, the answer will
will be preceded by `AGGREGATOR >`. be preceded by `AGGREGATOR >`.
- **coordinates** (`List[Tuple[int, int]]`) -- Coordinates of the cells of the answers. - **coordinates** (`List[Tuple[int, int]]`) -- Coordinates of the cells of the answers.
- **cells** (`List[str]`) -- List of strings made up of the answer cell values. - **cells** (`List[str]`) -- List of strings made up of the answer cell values.
- **aggregator** (`str`) -- If the model has an aggregator, this returns the aggregator. - **aggregator** (`str`) -- If the model has an aggregator, this returns the aggregator.
......
...@@ -27,11 +27,12 @@ class Text2TextGenerationPipeline(Pipeline): ...@@ -27,11 +27,12 @@ class Text2TextGenerationPipeline(Pipeline):
""" """
Pipeline for text to text generation using seq2seq models. Pipeline for text to text generation using seq2seq models.
This Text2TextGenerationPipeline pipeline can currently be loaded from [`pipeline`] using the This Text2TextGenerationPipeline pipeline can currently be loaded from [`pipeline`] using the following task
following task identifier: `"text2text-generation"`. identifier: `"text2text-generation"`.
The models that this pipeline can use are models that have been fine-tuned on a translation task. See the The models that this pipeline can use are models that have been fine-tuned on a translation task. See the
up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=text2text-generation). up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=text2text-generation).
Usage: Usage:
...@@ -119,9 +120,9 @@ class Text2TextGenerationPipeline(Pipeline): ...@@ -119,9 +120,9 @@ class Text2TextGenerationPipeline(Pipeline):
clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`): clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
Whether or not to clean up the potential extra spaces in the text output. Whether or not to clean up the potential extra spaces in the text output.
truncation (`TruncationStrategy`, *optional*, defaults to `TruncationStrategy.DO_NOT_TRUNCATE`): truncation (`TruncationStrategy`, *optional*, defaults to `TruncationStrategy.DO_NOT_TRUNCATE`):
The truncation strategy for the tokenization within the pipeline. The truncation strategy for the tokenization within the pipeline. `TruncationStrategy.DO_NOT_TRUNCATE`
`TruncationStrategy.DO_NOT_TRUNCATE` (default) will never truncate, but it is sometimes desirable (default) will never truncate, but it is sometimes desirable to truncate the input to fit the model's
to truncate the input to fit the model's max_length instead of throwing an error down the line. max_length instead of throwing an error down the line.
generate_kwargs: generate_kwargs:
Additional keyword arguments to pass along to the generate method of the model (see the generate method Additional keyword arguments to pass along to the generate method of the model (see the generate method
corresponding to your framework [here](./model#generative-models)). corresponding to your framework [here](./model#generative-models)).
...@@ -130,8 +131,8 @@ class Text2TextGenerationPipeline(Pipeline): ...@@ -130,8 +131,8 @@ class Text2TextGenerationPipeline(Pipeline):
A list or a list of list of `dict`: Each result comes as a dictionary with the following keys: A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:
- **generated_text** (`str`, present when `return_text=True`) -- The generated text. - **generated_text** (`str`, present when `return_text=True`) -- The generated text.
- **generated_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) - **generated_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The token
-- The token ids of the generated text. ids of the generated text.
""" """
result = super().__call__(*args, **kwargs) result = super().__call__(*args, **kwargs)
...@@ -175,8 +176,8 @@ class SummarizationPipeline(Text2TextGenerationPipeline): ...@@ -175,8 +176,8 @@ class SummarizationPipeline(Text2TextGenerationPipeline):
""" """
Summarize news articles and other documents. Summarize news articles and other documents.
This summarizing pipeline can currently be loaded from [`pipeline`] using the following task This summarizing pipeline can currently be loaded from [`pipeline`] using the following task identifier:
identifier: `"summarization"`. `"summarization"`.
The models that this pipeline can use are models that have been fine-tuned on a summarization task, which is The models that this pipeline can use are models that have been fine-tuned on a summarization task, which is
currently, '*bart-large-cnn*', '*t5-small*', '*t5-base*', '*t5-large*', '*t5-3b*', '*t5-11b*'. See the up-to-date currently, '*bart-large-cnn*', '*t5-small*', '*t5-base*', '*t5-large*', '*t5-3b*', '*t5-11b*'. See the up-to-date
...@@ -217,10 +218,9 @@ class SummarizationPipeline(Text2TextGenerationPipeline): ...@@ -217,10 +218,9 @@ class SummarizationPipeline(Text2TextGenerationPipeline):
Return: Return:
A list or a list of list of `dict`: Each result comes as a dictionary with the following keys: A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:
- **summary_text** (`str`, present when `return_text=True`) -- The summary of the corresponding - **summary_text** (`str`, present when `return_text=True`) -- The summary of the corresponding input.
input. - **summary_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The token
- **summary_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- ids of the summary.
The token ids of the summary.
""" """
return super().__call__(*args, **kwargs) return super().__call__(*args, **kwargs)
...@@ -243,8 +243,8 @@ class TranslationPipeline(Text2TextGenerationPipeline): ...@@ -243,8 +243,8 @@ class TranslationPipeline(Text2TextGenerationPipeline):
""" """
Translates from one language to another. Translates from one language to another.
This translation pipeline can currently be loaded from [`pipeline`] using the following task This translation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
identifier: `"translation_xx_to_yy"`. `"translation_xx_to_yy"`.
The models that this pipeline can use are models that have been fine-tuned on a translation task. See the The models that this pipeline can use are models that have been fine-tuned on a translation task. See the
up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=translation). up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=translation).
...@@ -318,7 +318,7 @@ class TranslationPipeline(Text2TextGenerationPipeline): ...@@ -318,7 +318,7 @@ class TranslationPipeline(Text2TextGenerationPipeline):
A list or a list of list of `dict`: Each result comes as a dictionary with the following keys: A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:
- **translation_text** (`str`, present when `return_text=True`) -- The translation. - **translation_text** (`str`, present when `return_text=True`) -- The translation.
- **translation_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) - **translation_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The
-- The token ids of the translation. token ids of the translation.
""" """
return super().__call__(*args, **kwargs) return super().__call__(*args, **kwargs)
...@@ -37,8 +37,8 @@ class ClassificationFunction(ExplicitEnum): ...@@ -37,8 +37,8 @@ class ClassificationFunction(ExplicitEnum):
function_to_apply (`str`, *optional*, defaults to `"default"`): function_to_apply (`str`, *optional*, defaults to `"default"`):
The function to apply to the model outputs in order to retrieve the scores. Accepts four different values: The function to apply to the model outputs in order to retrieve the scores. Accepts four different values:
- `"default"`: if the model has a single label, will apply the sigmoid function on the output. If the - `"default"`: if the model has a single label, will apply the sigmoid function on the output. If the model
model has several labels, will apply the softmax function on the output. has several labels, will apply the softmax function on the output.
- `"sigmoid"`: Applies the sigmoid function on the output. - `"sigmoid"`: Applies the sigmoid function on the output.
- `"softmax"`: Applies the softmax function on the output. - `"softmax"`: Applies the softmax function on the output.
- `"none"`: Does not apply any function on the output. - `"none"`: Does not apply any function on the output.
...@@ -49,15 +49,15 @@ class TextClassificationPipeline(Pipeline): ...@@ -49,15 +49,15 @@ class TextClassificationPipeline(Pipeline):
Text classification pipeline using any `ModelForSequenceClassification`. See the [sequence classification Text classification pipeline using any `ModelForSequenceClassification`. See the [sequence classification
examples](../task_summary#sequence-classification) for more information. examples](../task_summary#sequence-classification) for more information.
This text classification pipeline can currently be loaded from [`pipeline`] using the following This text classification pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"sentiment-analysis"` (for classifying sequences according to positive or negative `"sentiment-analysis"` (for classifying sequences according to positive or negative sentiments).
sentiments).
If multiple classification labels are available (`model.config.num_labels >= 2`), the pipeline will run a If multiple classification labels are available (`model.config.num_labels >= 2`), the pipeline will run a softmax
softmax over the results. If there is a single label, the pipeline will run a sigmoid over the result. over the results. If there is a single label, the pipeline will run a sigmoid over the result.
The models that this pipeline can use are models that have been fine-tuned on a sequence classification task. See The models that this pipeline can use are models that have been fine-tuned on a sequence classification task. See
the up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=text-classification). the up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=text-classification).
""" """
return_all_scores = False return_all_scores = False
......
...@@ -18,8 +18,8 @@ class TextGenerationPipeline(Pipeline): ...@@ -18,8 +18,8 @@ class TextGenerationPipeline(Pipeline):
Language generation pipeline using any `ModelWithLMHead`. This pipeline predicts the words that will follow a Language generation pipeline using any `ModelWithLMHead`. This pipeline predicts the words that will follow a
specified text prompt. specified text prompt.
This language generation pipeline can currently be loaded from [`pipeline`] using the following This language generation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"text-generation"`. `"text-generation"`.
The models that this pipeline can use are models that have been trained with an autoregressive language modeling The models that this pipeline can use are models that have been trained with an autoregressive language modeling
objective, which includes the uni-directional models in the library (e.g. gpt2). See the list of available models objective, which includes the uni-directional models in the library (e.g. gpt2). See the list of available models
...@@ -141,8 +141,8 @@ class TextGenerationPipeline(Pipeline): ...@@ -141,8 +141,8 @@ class TextGenerationPipeline(Pipeline):
return_text (`bool`, *optional*, defaults to `True`): return_text (`bool`, *optional*, defaults to `True`):
Whether or not to include the decoded texts in the outputs. Whether or not to include the decoded texts in the outputs.
return_full_text (`bool`, *optional*, defaults to `True`): return_full_text (`bool`, *optional*, defaults to `True`):
If set to `False` only added text is returned, otherwise the full text is returned Only meaningful If set to `False` only added text is returned, otherwise the full text is returned Only meaningful if
if *return_text* is set to True. *return_text* is set to True.
clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`): clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
Whether or not to clean up the potential extra spaces in the text output. Whether or not to clean up the potential extra spaces in the text output.
prefix (`str`, *optional*): prefix (`str`, *optional*):
...@@ -165,8 +165,8 @@ class TextGenerationPipeline(Pipeline): ...@@ -165,8 +165,8 @@ class TextGenerationPipeline(Pipeline):
A list or a list of list of `dict`: Each result comes as a dictionary with the following keys: A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:
- **generated_text** (`str`, present when `return_text=True`) -- The generated text. - **generated_text** (`str`, present when `return_text=True`) -- The generated text.
- **generated_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) - **generated_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The token
-- The token ids of the generated text. ids of the generated text.
""" """
return super().__call__(text_inputs, **kwargs) return super().__call__(text_inputs, **kwargs)
......
...@@ -59,8 +59,8 @@ class AggregationStrategy(ExplicitEnum): ...@@ -59,8 +59,8 @@ class AggregationStrategy(ExplicitEnum):
ignore_labels (`List[str]`, defaults to `["O"]`): ignore_labels (`List[str]`, defaults to `["O"]`):
A list of labels to ignore. A list of labels to ignore.
grouped_entities (`bool`, *optional*, defaults to `False`): grouped_entities (`bool`, *optional*, defaults to `False`):
DEPRECATED, use `aggregation_strategy` instead. Whether or not to group the tokens corresponding to DEPRECATED, use `aggregation_strategy` instead. Whether or not to group the tokens corresponding to the
the same entity together in the predictions or not. same entity together in the predictions or not.
aggregation_strategy (`str`, *optional*, defaults to `"none"`): aggregation_strategy (`str`, *optional*, defaults to `"none"`):
The strategy to fuse (or not) tokens based on the model prediction. The strategy to fuse (or not) tokens based on the model prediction.
...@@ -73,14 +73,14 @@ class AggregationStrategy(ExplicitEnum): ...@@ -73,14 +73,14 @@ class AggregationStrategy(ExplicitEnum):
"NAME"}]. Look for FIRST, MAX, AVERAGE for ways to mitigate that and disambiguate words (on languages "NAME"}]. Look for FIRST, MAX, AVERAGE for ways to mitigate that and disambiguate words (on languages
that support that meaning, which is basically tokens separated by a space). These mitigations will that support that meaning, which is basically tokens separated by a space). These mitigations will
only work on real words, "New york" might still be tagged with two different entities. only work on real words, "New york" might still be tagged with two different entities.
- "first" : (works only on word based models) Will use the `SIMPLE` strategy except that words, - "first" : (works only on word based models) Will use the `SIMPLE` strategy except that words, cannot
cannot end up with different tags. Words will simply use the tag of the first token of the word when end up with different tags. Words will simply use the tag of the first token of the word when there
there is ambiguity. is ambiguity.
- "average" : (works only on word based models) Will use the `SIMPLE` strategy except that words, - "average" : (works only on word based models) Will use the `SIMPLE` strategy except that words,
cannot end up with different tags. scores will be averaged first across tokens, and then the maximum cannot end up with different tags. scores will be averaged first across tokens, and then the maximum
label is applied. label is applied.
- "max" : (works only on word based models) Will use the `SIMPLE` strategy except that words, - "max" : (works only on word based models) Will use the `SIMPLE` strategy except that words, cannot
cannot end up with different tags. Word entity will simply be the token with the maximum score. end up with different tags. Word entity will simply be the token with the maximum score.
""", """,
) )
class TokenClassificationPipeline(Pipeline): class TokenClassificationPipeline(Pipeline):
...@@ -88,12 +88,12 @@ class TokenClassificationPipeline(Pipeline): ...@@ -88,12 +88,12 @@ class TokenClassificationPipeline(Pipeline):
Named Entity Recognition pipeline using any `ModelForTokenClassification`. See the [named entity recognition Named Entity Recognition pipeline using any `ModelForTokenClassification`. See the [named entity recognition
examples](../task_summary#named-entity-recognition) for more information. examples](../task_summary#named-entity-recognition) for more information.
This token recognition pipeline can currently be loaded from [`pipeline`] using the following This token recognition pipeline can currently be loaded from [`pipeline`] using the following task identifier:
task identifier: `"ner"` (for predicting the classes of tokens in a sequence: person, organisation, location `"ner"` (for predicting the classes of tokens in a sequence: person, organisation, location or miscellaneous).
or miscellaneous).
The models that this pipeline can use are models that have been fine-tuned on a token classification task. See the The models that this pipeline can use are models that have been fine-tuned on a token classification task. See the
up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=token-classification). up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=token-classification).
""" """
default_input_names = "sequences" default_input_names = "sequences"
...@@ -166,20 +166,20 @@ class TokenClassificationPipeline(Pipeline): ...@@ -166,20 +166,20 @@ class TokenClassificationPipeline(Pipeline):
One or several texts (or one list of texts) for token classification. One or several texts (or one list of texts) for token classification.
Return: Return:
A list or a list of list of `dict`: Each result comes as a list of dictionaries (one for each token in A list or a list of list of `dict`: Each result comes as a list of dictionaries (one for each token in the
the corresponding input, or each entity if this pipeline was instantiated with an aggregation_strategy) corresponding input, or each entity if this pipeline was instantiated with an aggregation_strategy) with
with the following keys: the following keys:
- **word** (`str`) -- The token/word classified. - **word** (`str`) -- The token/word classified.
- **score** (`float`) -- The corresponding probability for `entity`. - **score** (`float`) -- The corresponding probability for `entity`.
- **entity** (`str`) -- The entity predicted for that token/word (it is named *entity_group* when - **entity** (`str`) -- The entity predicted for that token/word (it is named *entity_group* when
*aggregation_strategy* is not `"none"`. *aggregation_strategy* is not `"none"`.
- **index** (`int`, only present when `aggregation_strategy="none"`) -- The index of the - **index** (`int`, only present when `aggregation_strategy="none"`) -- The index of the corresponding
corresponding token in the sentence. token in the sentence.
- **start** (`int`, *optional*) -- The index of the start of the corresponding entity in the sentence. - **start** (`int`, *optional*) -- The index of the start of the corresponding entity in the sentence. Only
Only exists if the offsets are available within the tokenizer exists if the offsets are available within the tokenizer
- **end** (`int`, *optional*) -- The index of the end of the corresponding entity in the sentence. - **end** (`int`, *optional*) -- The index of the end of the corresponding entity in the sentence. Only
Only exists if the offsets are available within the tokenizer exists if the offsets are available within the tokenizer
""" """
_inputs, offset_mapping = self._args_parser(inputs, **kwargs) _inputs, offset_mapping = self._args_parser(inputs, **kwargs)
......
...@@ -143,8 +143,8 @@ class ZeroShotClassificationPipeline(ChunkPipeline): ...@@ -143,8 +143,8 @@ class ZeroShotClassificationPipeline(ChunkPipeline):
**kwargs, **kwargs,
): ):
""" """
Classify the sequence(s) given as inputs. See the [`ZeroShotClassificationPipeline`] Classify the sequence(s) given as inputs. See the [`ZeroShotClassificationPipeline`] documentation for more
documentation for more information. information.
Args: Args:
sequences (`str` or `List[str]`): sequences (`str` or `List[str]`):
...@@ -155,13 +155,13 @@ class ZeroShotClassificationPipeline(ChunkPipeline): ...@@ -155,13 +155,13 @@ class ZeroShotClassificationPipeline(ChunkPipeline):
hypothesis_template (`str`, *optional*, defaults to `"This example is {}."`): hypothesis_template (`str`, *optional*, defaults to `"This example is {}."`):
The template used to turn each label into an NLI-style hypothesis. This template must include a {} or The template used to turn each label into an NLI-style hypothesis. This template must include a {} or
similar syntax for the candidate label to be inserted into the template. For example, the default similar syntax for the candidate label to be inserted into the template. For example, the default
template is `"This example is {}."` With the candidate label `"sports"`, this would be fed template is `"This example is {}."` With the candidate label `"sports"`, this would be fed into the
into the model like `"<cls> sequence to classify <sep> This example is sports . <sep>"`. The model like `"<cls> sequence to classify <sep> This example is sports . <sep>"`. The default template
default template works well in many cases, but it may be worthwhile to experiment with different works well in many cases, but it may be worthwhile to experiment with different templates depending on
templates depending on the task setting. the task setting.
multi_label (`bool`, *optional*, defaults to `False`): multi_label (`bool`, *optional*, defaults to `False`):
Whether or not multiple candidate labels can be true. If `False`, the scores are normalized such Whether or not multiple candidate labels can be true. If `False`, the scores are normalized such that
that the sum of the label likelihoods for each sequence is 1. If `True`, the labels are considered the sum of the label likelihoods for each sequence is 1. If `True`, the labels are considered
independent and probabilities are normalized for each candidate by doing a softmax of the entailment independent and probabilities are normalized for each candidate by doing a softmax of the entailment
score vs. the contradiction score. score vs. the contradiction score.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment