pipelines.rst 5.51 KB
Newer Older
Sylvain Gugger's avatar
Sylvain Gugger committed
1
2
3
4
5
6
7
8
9
10
11
12
.. 
    Copyright 2020 The HuggingFace Team. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
    the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
    an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
    specific language governing permissions and limitations under the License.

Lysandre Debut's avatar
Lysandre Debut committed
13
Pipelines
Sylvain Gugger's avatar
Sylvain Gugger committed
14
-----------------------------------------------------------------------------------------------------------------------
Lysandre Debut's avatar
Lysandre Debut committed
15

Sylvain Gugger's avatar
Sylvain Gugger committed
16
17
The pipelines are a great and easy way to use models for inference. These pipelines are objects that abstract most of
the complex code from the library, offering a simple API dedicated to several tasks, including Named Entity
Sylvain Gugger's avatar
Sylvain Gugger committed
18
19
Recognition, Masked Language Modeling, Sentiment Analysis, Feature Extraction and Question Answering. See the
:doc:`task summary <../task_summary>` for examples of use.
Lysandre Debut's avatar
Lysandre Debut committed
20
21
22

There are two categories of pipeline abstractions to be aware about:

Sylvain Gugger's avatar
Sylvain Gugger committed
23
24
25
26
27
28
29
30
31
32
33
34
- The :func:`~transformers.pipeline` which is the most powerful object encapsulating all other pipelines.
- The other task-specific pipelines:

    - :class:`~transformers.ConversationalPipeline`
    - :class:`~transformers.FeatureExtractionPipeline`
    - :class:`~transformers.FillMaskPipeline`
    - :class:`~transformers.QuestionAnsweringPipeline`
    - :class:`~transformers.SummarizationPipeline`
    - :class:`~transformers.TextClassificationPipeline`
    - :class:`~transformers.TextGenerationPipeline`
    - :class:`~transformers.TokenClassificationPipeline`
    - :class:`~transformers.TranslationPipeline`
35
    - :class:`~transformers.ZeroShotClassificationPipeline`
36
    - :class:`~transformers.Text2TextGenerationPipeline`
Lysandre Debut's avatar
Lysandre Debut committed
37
38

The pipeline abstraction
Sylvain Gugger's avatar
Sylvain Gugger committed
39
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lysandre Debut's avatar
Lysandre Debut committed
40

Sylvain Gugger's avatar
Sylvain Gugger committed
41
42
The `pipeline` abstraction is a wrapper around all the other available pipelines. It is instantiated as any other
pipeline but requires an additional argument which is the `task`.
Lysandre Debut's avatar
Lysandre Debut committed
43

Sylvain Gugger's avatar
Sylvain Gugger committed
44
.. autofunction:: transformers.pipeline
Lysandre Debut's avatar
Lysandre Debut committed
45
46
47


The task specific pipelines
Sylvain Gugger's avatar
Sylvain Gugger committed
48
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lysandre Debut's avatar
Lysandre Debut committed
49

Sylvain Gugger's avatar
Sylvain Gugger committed
50
ConversationalPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
51
=======================================================================================================================
Lysandre Debut's avatar
Lysandre Debut committed
52

Sylvain Gugger's avatar
Sylvain Gugger committed
53
.. autoclass:: transformers.Conversation
Lysandre Debut's avatar
Lysandre Debut committed
54

Sylvain Gugger's avatar
Sylvain Gugger committed
55
56
57
58
59
.. autoclass:: transformers.ConversationalPipeline
    :special-members: __call__
    :members:

FeatureExtractionPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
60
=======================================================================================================================
Lysandre Debut's avatar
Lysandre Debut committed
61

Sylvain Gugger's avatar
Sylvain Gugger committed
62
63
64
.. autoclass:: transformers.FeatureExtractionPipeline
    :special-members: __call__
    :members:
Lysandre Debut's avatar
Lysandre Debut committed
65
66

FillMaskPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
67
=======================================================================================================================
Lysandre Debut's avatar
Lysandre Debut committed
68
69

.. autoclass:: transformers.FillMaskPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
70
71
    :special-members: __call__
    :members:
Lysandre Debut's avatar
Lysandre Debut committed
72

Sylvain Gugger's avatar
Sylvain Gugger committed
73
NerPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
74
=======================================================================================================================
Lysandre Debut's avatar
Lysandre Debut committed
75

76
77
78
.. autoclass:: transformers.NerPipeline

See :class:`~transformers.TokenClassificationPipeline` for all details.
Lysandre Debut's avatar
Lysandre Debut committed
79
80

QuestionAnsweringPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
81
=======================================================================================================================
Lysandre Debut's avatar
Lysandre Debut committed
82
83

.. autoclass:: transformers.QuestionAnsweringPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
84
85
    :special-members: __call__
    :members:
86
87

SummarizationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
88
=======================================================================================================================
89
90

.. autoclass:: transformers.SummarizationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
91
92
    :special-members: __call__
    :members:
93

Sylvain Gugger's avatar
Sylvain Gugger committed
94
TextClassificationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
95
=======================================================================================================================
Sylvain Gugger's avatar
Sylvain Gugger committed
96
97
98
99

.. autoclass:: transformers.TextClassificationPipeline
    :special-members: __call__
    :members:
100
101

TextGenerationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
102
=======================================================================================================================
103
104

.. autoclass:: transformers.TextGenerationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
105
106
    :special-members: __call__
    :members:
107

108
Text2TextGenerationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
109
=======================================================================================================================
110
111
112
113
114

.. autoclass:: transformers.Text2TextGenerationPipeline
    :special-members: __call__
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
115
TokenClassificationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
116
=======================================================================================================================
117

Sylvain Gugger's avatar
Sylvain Gugger committed
118
119
120
121
.. autoclass:: transformers.TokenClassificationPipeline
    :special-members: __call__
    :members:

122
123
124
125
126
127
128
TranslationPipeline
=======================================================================================================================

.. autoclass:: transformers.TranslationPipeline
    :special-members: __call__
    :members:

129
ZeroShotClassificationPipeline
Sylvain Gugger's avatar
Sylvain Gugger committed
130
=======================================================================================================================
131
132
133
134
135

.. autoclass:: transformers.ZeroShotClassificationPipeline
    :special-members: __call__
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
136
Parent class: :obj:`Pipeline`
Sylvain Gugger's avatar
Sylvain Gugger committed
137
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sylvain Gugger's avatar
Sylvain Gugger committed
138
139
140

.. autoclass:: transformers.Pipeline
    :members: