Commit 83703cd0 authored by Julien Chaumond's avatar Julien Chaumond
Browse files

Update doc for {Summarization,Translation}Pipeline and other tweaks

parent a1b3b416
...@@ -538,6 +538,8 @@ You can create `Pipeline` objects for the following down-stream tasks: ...@@ -538,6 +538,8 @@ You can create `Pipeline` objects for the following down-stream tasks:
- `text-classification`: Initialize a `TextClassificationPipeline` directly, or see `sentiment-analysis` for an example. - `text-classification`: Initialize a `TextClassificationPipeline` directly, or see `sentiment-analysis` for an example.
- `question-answering`: Provided some context and a question refering to the context, it will extract the answer to the question in the context. - `question-answering`: Provided some context and a question refering to the context, it will extract the answer to the question in the context.
- `fill-mask`: Takes an input sequence containing a masked token (e.g. `<mask>`) and return list of most probable filled sequences, with their probabilities. - `fill-mask`: Takes an input sequence containing a masked token (e.g. `<mask>`) and return list of most probable filled sequences, with their probabilities.
- `summarization`
- `translation_xx_to_yy`
```python ```python
from transformers import pipeline from transformers import pipeline
......
---
tags:
- summarization
---
---
tags:
- summarization
---
---
tags:
- summarization
- translation
---
---
tags:
- summarization
- translation
---
---
tags:
- summarization
- translation
---
---
tags:
- summarization
- translation
---
---
tags:
- summarization
- translation
---
...@@ -564,8 +564,8 @@ class TextClassificationPipeline(Pipeline): ...@@ -564,8 +564,8 @@ class TextClassificationPipeline(Pipeline):
- "sentiment-analysis", for classifying sequences according to positive or negative sentiments. - "sentiment-analysis", for classifying sequences according to positive or negative sentiments.
The models that this pipeline can use are models that have been fine-tuned on a sequence classification task. The models that this pipeline can use are models that have been fine-tuned on a sequence classification task.
See the list of available community models fine-tuned on such a task on See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?search=&filter=text-classification>`__. `huggingface.co/models <https://huggingface.co/models?filter=text-classification>`__.
Arguments: Arguments:
model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`): model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`):
...@@ -608,8 +608,8 @@ class FillMaskPipeline(Pipeline): ...@@ -608,8 +608,8 @@ class FillMaskPipeline(Pipeline):
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. which includes the bi-directional models in the library.
See the list of available community models on See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?search=&filter=lm-head>`__. `huggingface.co/models <https://huggingface.co/models?filter=lm-head>`__.
Arguments: Arguments:
model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`): model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`):
...@@ -707,8 +707,8 @@ class NerPipeline(Pipeline): ...@@ -707,8 +707,8 @@ class NerPipeline(Pipeline):
- "ner", for predicting the classes of tokens in a sequence: person, organisation, location or miscellaneous. - "ner", for predicting the classes of tokens in a sequence: person, organisation, location or miscellaneous.
The models that this pipeline can use are models that have been fine-tuned on a token classification task. The models that this pipeline can use are models that have been fine-tuned on a token classification task.
See the list of available community models fine-tuned on such a task on See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?search=&filter=token-classification>`__. `huggingface.co/models <https://huggingface.co/models?filter=token-classification>`__.
Arguments: Arguments:
model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`): model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`):
...@@ -883,8 +883,8 @@ class QuestionAnsweringPipeline(Pipeline): ...@@ -883,8 +883,8 @@ class QuestionAnsweringPipeline(Pipeline):
- "question-answering", for answering questions given a context. - "question-answering", for answering questions given a context.
The models that this pipeline can use are models that have been fine-tuned on a question answering task. The models that this pipeline can use are models that have been fine-tuned on a question answering task.
See the list of available community models fine-tuned on such a task on See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?search=&filter=question-answering>`__. `huggingface.co/models <https://huggingface.co/models?filter=question-answering>`__.
Arguments: Arguments:
model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`): model (:obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`):
...@@ -1147,8 +1147,10 @@ class SummarizationPipeline(Pipeline): ...@@ -1147,8 +1147,10 @@ class SummarizationPipeline(Pipeline):
summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf") summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
summarizer("Sam Shleifer writes the best docstring examples in the whole world.", min_length=5, max_length=20) summarizer("Sam Shleifer writes the best docstring examples in the whole world.", min_length=5, max_length=20)
Supported Models: The models that this pipeline can use are models that have been fine-tuned on a summarization task,
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`'. which is currently, '`bart-large-cnn`', '`t5-small`', '`t5-base`', '`t5-large`', '`t5-3b`', '`t5-11b`'.
See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?filter=summarization>`__.
Arguments: Arguments:
model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`): model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`):
...@@ -1276,7 +1278,10 @@ class TranslationPipeline(Pipeline): ...@@ -1276,7 +1278,10 @@ class TranslationPipeline(Pipeline):
en_fr_translator = pipeline("translation_en_to_fr") en_fr_translator = pipeline("translation_en_to_fr")
en_fr_translator("How old are you?") en_fr_translator("How old are you?")
Supported Models: "t5-small", "t5-base", "t5-large", "t5-3b", "t5-11b" The models that this pipeline can use are models that have been fine-tuned on a translation task,
currently: "t5-small", "t5-base", "t5-large", "t5-3b", "t5-11b"
See the up-to-date list of available models on
`huggingface.co/models <https://huggingface.co/models?filter=translation>`__.
Arguments: Arguments:
model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`): model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`):
...@@ -1505,25 +1510,27 @@ def pipeline( ...@@ -1505,25 +1510,27 @@ def pipeline(
- "ner": will return a :class:`~transformers.NerPipeline` - "ner": will return a :class:`~transformers.NerPipeline`
- "question-answering": will return a :class:`~transformers.QuestionAnsweringPipeline` - "question-answering": will return a :class:`~transformers.QuestionAnsweringPipeline`
- "fill-mask": will return a :class:`~transformers.FillMaskPipeline` - "fill-mask": will return a :class:`~transformers.FillMaskPipeline`
- "summarization": will return a :class:`~transformers.SummarizationPipeline`
- "translation_xx_to_yy": will return a :class:`~transformers.TranslationPipeline`
model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`): model (:obj:`str` or :obj:`~transformers.PreTrainedModel` or :obj:`~transformers.TFPreTrainedModel`, `optional`, defaults to :obj:`None`):
The model that will be used by the pipeline to make predictions. This can be :obj:`None`, a string The model that will be used by the pipeline to make predictions. This can be :obj:`None`,
checkpoint identifier or an actual pre-trained model inheriting from a model identifier or an actual pre-trained model inheriting from
:class:`~transformers.PreTrainedModel` for PyTorch and :class:`~transformers.TFPreTrainedModel` for :class:`~transformers.PreTrainedModel` for PyTorch and :class:`~transformers.TFPreTrainedModel` for
TensorFlow. TensorFlow.
If :obj:`None`, the default of the pipeline will be loaded. If :obj:`None`, the default for this pipeline will be loaded.
config (:obj:`str` or :obj:`~transformers.PretrainedConfig`, `optional`, defaults to :obj:`None`): config (:obj:`str` or :obj:`~transformers.PretrainedConfig`, `optional`, defaults to :obj:`None`):
The configuration that will be used by the pipeline to instantiate the model. This can be :obj:`None`, The configuration that will be used by the pipeline to instantiate the model. This can be :obj:`None`,
a string checkpoint identifier or an actual pre-trained model configuration inheriting from a model identifier or an actual pre-trained model configuration inheriting from
:class:`~transformers.PretrainedConfig`. :class:`~transformers.PretrainedConfig`.
If :obj:`None`, the default of the pipeline will be loaded. If :obj:`None`, the default for this pipeline will be loaded.
tokenizer (:obj:`str` or :obj:`~transformers.PreTrainedTokenizer`, `optional`, defaults to :obj:`None`): tokenizer (:obj:`str` or :obj:`~transformers.PreTrainedTokenizer`, `optional`, defaults to :obj:`None`):
The tokenizer that will be used by the pipeline to encode data for the model. This can be :obj:`None`, The tokenizer that will be used by the pipeline to encode data for the model. This can be :obj:`None`,
a string checkpoint identifier or an actual pre-trained tokenizer inheriting from a model identifier or an actual pre-trained tokenizer inheriting from
:class:`~transformers.PreTrainedTokenizer`. :class:`~transformers.PreTrainedTokenizer`.
If :obj:`None`, the default of the pipeline will be loaded. If :obj:`None`, the default for this pipeline will be loaded.
framework (:obj:`str`, `optional`, defaults to :obj:`None`): framework (:obj:`str`, `optional`, defaults to :obj:`None`):
The framework to use, either "pt" for PyTorch or "tf" for TensorFlow. The specified framework must be The framework to use, either "pt" for PyTorch or "tf" for TensorFlow. The specified framework must be
installed. installed.
...@@ -1549,11 +1556,6 @@ def pipeline( ...@@ -1549,11 +1556,6 @@ def pipeline(
model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english") model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased") tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
pipeline('ner', model=model, tokenizer=tokenizer) pipeline('ner', model=model, tokenizer=tokenizer)
# Named entity recognition pipeline, passing a model and configuration with a HTTPS URL.
model_url = "https://s3.amazonaws.com/models.huggingface.co/bert/dbmdz/bert-large-cased-finetuned-conll03-english/pytorch_model.bin"
config_url = "https://s3.amazonaws.com/models.huggingface.co/bert/dbmdz/bert-large-cased-finetuned-conll03-english/config.json"
pipeline('ner', model=model_url, config=config_url, tokenizer='bert-base-cased')
""" """
# Retrieve the task # Retrieve the task
if task not in SUPPORTED_TASKS: if task not in SUPPORTED_TASKS:
...@@ -1579,7 +1581,7 @@ def pipeline( ...@@ -1579,7 +1581,7 @@ def pipeline(
# Impossible to guest what is the right tokenizer here # Impossible to guest what is the right tokenizer here
raise Exception( raise Exception(
"Impossible to guess which tokenizer to use. " "Impossible to guess which tokenizer to use. "
"Please provided a PretrainedTokenizer class or a path/url/shortcut name to a pretrained tokenizer." "Please provided a PretrainedTokenizer class or a path/identifier to a pretrained tokenizer."
) )
modelcard = None modelcard = None
...@@ -1623,4 +1625,4 @@ def pipeline( ...@@ -1623,4 +1625,4 @@ def pipeline(
) )
model = model_class.from_pretrained(model, config=config, **model_kwargs) model = model_class.from_pretrained(model, config=config, **model_kwargs)
return task_class(model=model, tokenizer=tokenizer, modelcard=modelcard, framework=framework, task=task, **kwargs,) return task_class(model=model, tokenizer=tokenizer, modelcard=modelcard, framework=framework, task=task, **kwargs)
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