auto.md 8.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<!--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.
11
12
13
14

鈿狅笍 Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

15
16
17
18
19
20
21
22
23
24
25
26
27
-->

# Auto Classes

In many cases, the architecture you want to use can be guessed from the name or the path of the pretrained model you
are supplying to the `from_pretrained()` method. AutoClasses are here to do this job for you so that you
automatically retrieve the relevant model given the name/path to the pretrained weights/config/vocabulary.

Instantiating one of [`AutoConfig`], [`AutoModel`], and
[`AutoTokenizer`] will directly create a class of the relevant architecture. For instance


```python
Sylvain Gugger's avatar
Style  
Sylvain Gugger committed
28
model = AutoModel.from_pretrained("bert-base-cased")
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
```

will create a model that is an instance of [`BertModel`].

There is one class of `AutoModel` for each task, and for each backend (PyTorch, TensorFlow, or Flax).

## Extending the Auto Classes

Each of the auto classes has a method to be extended with your custom classes. For instance, if you have defined a
custom class of model `NewModel`, make sure you have a `NewModelConfig` then you can add those to the auto
classes like this:

```python
from transformers import AutoConfig, AutoModel

AutoConfig.register("new-model", NewModelConfig)
AutoModel.register(NewModelConfig, NewModel)
```

You will then be able to use the auto classes like you would usually do!

<Tip warning={true}>

If your `NewModelConfig` is a subclass of [`~transformer.PretrainedConfig`], make sure its
`model_type` attribute is set to the same key you use when registering the config (here `"new-model"`).

Likewise, if your `NewModel` is a subclass of [`PreTrainedModel`], make sure its
`config_class` attribute is set to the same class you use when registering the model (here
`NewModelConfig`).

</Tip>

## AutoConfig

[[autodoc]] AutoConfig

## AutoTokenizer

[[autodoc]] AutoTokenizer

## AutoFeatureExtractor

[[autodoc]] AutoFeatureExtractor

amyeroberts's avatar
amyeroberts committed
73
74
75
76
## AutoImageProcessor

[[autodoc]] AutoImageProcessor

77
78
79
80
## AutoProcessor

[[autodoc]] AutoProcessor

81
82
83
84
85
## Generic model classes

The following auto classes are available for instantiating a base model class without a specific head.

### AutoModel
86
87
88

[[autodoc]] AutoModel

89
90
91
92
93
94
95
96
97
98
99
100
101
### TFAutoModel

[[autodoc]] TFAutoModel

### FlaxAutoModel

[[autodoc]] FlaxAutoModel

## Generic pretraining classes

The following auto classes are available for instantiating a model with a pretraining head.

### AutoModelForPreTraining
102
103
104

[[autodoc]] AutoModelForPreTraining

105
### TFAutoModelForPreTraining
106

107
[[autodoc]] TFAutoModelForPreTraining
108

109
### FlaxAutoModelForPreTraining
110

111
[[autodoc]] FlaxAutoModelForPreTraining
112

113
## Natural Language Processing
114

115
The following auto classes are available for the following natural language processing tasks.
116

117
### AutoModelForCausalLM
118

119
[[autodoc]] AutoModelForCausalLM
120

121
### TFAutoModelForCausalLM
122

123
[[autodoc]] TFAutoModelForCausalLM
124

125
### FlaxAutoModelForCausalLM
126

127
[[autodoc]] FlaxAutoModelForCausalLM
128

129
### AutoModelForMaskedLM
130

131
[[autodoc]] AutoModelForMaskedLM
132

133
### TFAutoModelForMaskedLM
134

135
[[autodoc]] TFAutoModelForMaskedLM
136

137
### FlaxAutoModelForMaskedLM
138

139
[[autodoc]] FlaxAutoModelForMaskedLM
140

141
142
143
144
### AutoModelForMaskGeneration

[[autodoc]] AutoModelForMaskGeneration

145
146
147
148
### TFAutoModelForMaskGeneration

[[autodoc]] TFAutoModelForMaskGeneration

149
### AutoModelForSeq2SeqLM
150

151
[[autodoc]] AutoModelForSeq2SeqLM
152

153
### TFAutoModelForSeq2SeqLM
154

155
[[autodoc]] TFAutoModelForSeq2SeqLM
156

157
### FlaxAutoModelForSeq2SeqLM
158

159
[[autodoc]] FlaxAutoModelForSeq2SeqLM
160

161
### AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
162

163
[[autodoc]] AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
164

165
### TFAutoModelForSequenceClassification
166

167
[[autodoc]] TFAutoModelForSequenceClassification
168

169
### FlaxAutoModelForSequenceClassification
170

171
[[autodoc]] FlaxAutoModelForSequenceClassification
172

173
### AutoModelForMultipleChoice
174

175
[[autodoc]] AutoModelForMultipleChoice
176

177
### TFAutoModelForMultipleChoice
178

179
[[autodoc]] TFAutoModelForMultipleChoice
180

181
### FlaxAutoModelForMultipleChoice
182

183
[[autodoc]] FlaxAutoModelForMultipleChoice
184

185
### AutoModelForNextSentencePrediction
186

187
[[autodoc]] AutoModelForNextSentencePrediction
188

189
### TFAutoModelForNextSentencePrediction
190

191
[[autodoc]] TFAutoModelForNextSentencePrediction
192

193
### FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
194

195
[[autodoc]] FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
196

197
### AutoModelForTokenClassification
198

199
[[autodoc]] AutoModelForTokenClassification
200

201
### TFAutoModelForTokenClassification
202

203
[[autodoc]] TFAutoModelForTokenClassification
204

205
### FlaxAutoModelForTokenClassification
206

207
[[autodoc]] FlaxAutoModelForTokenClassification
208

209
### AutoModelForQuestionAnswering
210

211
[[autodoc]] AutoModelForQuestionAnswering
212

213
### TFAutoModelForQuestionAnswering
214

215
[[autodoc]] TFAutoModelForQuestionAnswering
216

217
### FlaxAutoModelForQuestionAnswering
218

219
[[autodoc]] FlaxAutoModelForQuestionAnswering
220

221
222
223
224
225
226
227
228
### AutoModelForTextEncoding

[[autodoc]] AutoModelForTextEncoding

### TFAutoModelForTextEncoding

[[autodoc]] TFAutoModelForTextEncoding

229
## Computer vision
230

231
The following auto classes are available for the following computer vision tasks.
232

233
### AutoModelForDepthEstimation
234

235
[[autodoc]] AutoModelForDepthEstimation
236

237
238
239
240
241
### AutoModelForImageClassification

[[autodoc]] AutoModelForImageClassification

### TFAutoModelForImageClassification
242
243
244

[[autodoc]] TFAutoModelForImageClassification

245
### FlaxAutoModelForImageClassification
246

247
[[autodoc]] FlaxAutoModelForImageClassification
248

249
### AutoModelForVideoClassification
250

251
[[autodoc]] AutoModelForVideoClassification
252

253
### AutoModelForMaskedImageModeling
254

255
[[autodoc]] AutoModelForMaskedImageModeling
256

257
258
259
260
### TFAutoModelForMaskedImageModeling

[[autodoc]] TFAutoModelForMaskedImageModeling

261
### AutoModelForObjectDetection
262

263
[[autodoc]] AutoModelForObjectDetection
264

265
### AutoModelForImageSegmentation
266

267
[[autodoc]] AutoModelForImageSegmentation
268

269
### AutoModelForSemanticSegmentation
270

271
[[autodoc]] AutoModelForSemanticSegmentation
272

273
### TFAutoModelForSemanticSegmentation
274

275
[[autodoc]] TFAutoModelForSemanticSegmentation
276

277
### AutoModelForInstanceSegmentation
278

279
[[autodoc]] AutoModelForInstanceSegmentation
280

281
282
283
284
### AutoModelForUniversalSegmentation

[[autodoc]] AutoModelForUniversalSegmentation

285
286
287
288
289
290
291
292
### AutoModelForZeroShotImageClassification

[[autodoc]] AutoModelForZeroShotImageClassification

### TFAutoModelForZeroShotImageClassification

[[autodoc]] TFAutoModelForZeroShotImageClassification

293
### AutoModelForZeroShotObjectDetection
294

295
[[autodoc]] AutoModelForZeroShotObjectDetection
296

297
## Audio
298

299
The following auto classes are available for the following audio tasks.
300

301
### AutoModelForAudioClassification
302

303
[[autodoc]] AutoModelForAudioClassification
304

305
### AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
306

307
308
309
310
[[autodoc]] TFAutoModelForAudioClassification

### TFAutoModelForAudioFrameClassification

311
[[autodoc]] AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
312

313
### AutoModelForCTC
314

315
[[autodoc]] AutoModelForCTC
316

317
### AutoModelForSpeechSeq2Seq
318

319
[[autodoc]] AutoModelForSpeechSeq2Seq
320

321
### TFAutoModelForSpeechSeq2Seq
322

323
[[autodoc]] TFAutoModelForSpeechSeq2Seq
324

325
326
327
328
### FlaxAutoModelForSpeechSeq2Seq

[[autodoc]] FlaxAutoModelForSpeechSeq2Seq

329
### AutoModelForAudioXVector
330

331
[[autodoc]] AutoModelForAudioXVector
332

333
334
335
336
337
338
339
340
### AutoModelForTextToSpectrogram

[[autodoc]] AutoModelForTextToSpectrogram

### AutoModelForTextToWaveform

[[autodoc]] AutoModelForTextToWaveform

341
## Multimodal
342

343
The following auto classes are available for the following multimodal tasks.
344

345
### AutoModelForTableQuestionAnswering
346

347
[[autodoc]] AutoModelForTableQuestionAnswering
348

349
### TFAutoModelForTableQuestionAnswering
350

351
[[autodoc]] TFAutoModelForTableQuestionAnswering
352

353
### AutoModelForDocumentQuestionAnswering
354

355
[[autodoc]] AutoModelForDocumentQuestionAnswering
356

357
### TFAutoModelForDocumentQuestionAnswering
358

359
[[autodoc]] TFAutoModelForDocumentQuestionAnswering
360

361
### AutoModelForVisualQuestionAnswering
362

363
[[autodoc]] AutoModelForVisualQuestionAnswering
364

365
### AutoModelForVision2Seq
366

367
368
369
370
371
[[autodoc]] AutoModelForVision2Seq

### TFAutoModelForVision2Seq

[[autodoc]] TFAutoModelForVision2Seq
372

373
### FlaxAutoModelForVision2Seq
374
375

[[autodoc]] FlaxAutoModelForVision2Seq