@@ -14,29 +14,28 @@ specific language governing permissions and limitations under the License.
14
14
15
15
🤗 Transformers is an opinionated library built for:
16
16
17
- - NLP researchers and educators seeking to use/ study/ extend large-scale transformers models
18
- - hands-on practitioners who want to fine-tune those models and/ or serve them in production
19
- - engineers who just want to download a pretrained model and use it to solve a given NLP task.
17
+ - machine learning researchers and educators seeking to use, study or extend large-scale Transformers models.
18
+ - hands-on practitioners who want to fine-tune those models or serve them in production, or both.
19
+ - engineers who just want to download a pretrained model and use it to solve a given machine learning task.
20
20
21
21
The library was designed with two strong goals in mind:
22
22
23
- - Be as easy and fast to use as possible:
23
+ 1. Be as easy and fast to use as possible:
24
24
25
25
- We strongly limited the number of user-facing abstractions to learn, in fact, there are almost no abstractions,
26
26
just three standard classes required to use each model: [configuration](main_classes/configuration),
27
- [models](main_classes/model) and [tokenizer](main_classes/tokenizer).
27
+ [models](main_classes/model), and a preprocessing class ( [tokenizer](main_classes/tokenizer) for NLP, [feature extractor](main_classes/feature_extractor) for vision and audio, and [processor](main_classes/processors) for multimodal inputs ).
28
28
- All of these classes can be initialized in a simple and unified way from pretrained instances by using a common
29
- `from_pretrained()` instantiation method which will take care of downloading (if needed), caching and
30
- loading the related class instance and associated data (configurations' hyper-parameters , tokenizers' vocabulary,
29
+ `from_pretrained()` method which downloads (if needed), caches and
30
+ loads the related class instance and associated data (configurations' hyperparameters , tokenizers' vocabulary,
31
31
and models' weights) from a pretrained checkpoint provided on [Hugging Face Hub](https://huggingface.co/models) or your own saved checkpoint.
32
32
- On top of those three base classes, the library provides two APIs: [`pipeline`] for quickly
33
- using a model (plus its associated tokenizer and configuration) on a given task and
34
- [`Trainer`]/`Keras.fit` to quickly train or fine-tune a given model.
33
+ using a model for inference on a given task and [`Trainer`] to quickly train or fine-tune a PyTorch model (all TensorFlow models are compatible with `Keras.fit`).
35
34
- As a consequence, this library is NOT a modular toolbox of building blocks for neural nets. If you want to
36
- extend/ build- upon the library, just use regular Python/ PyTorch/ TensorFlow/ Keras modules and inherit from the base
37
- classes of the library to reuse functionalities like model loading/ saving.
35
+ extend or build upon the library, just use regular Python, PyTorch, TensorFlow, Keras modules and inherit from the base
36
+ classes of the library to reuse functionalities like model loading and saving. If you'd like to learn more about our coding philosophy for models, check out our [Repeat Yourself](https://huggingface.co/blog/transformers-design-philosophy) blog post .
38
37
39
- - Provide state-of-the-art models with performances as close as possible to the original models:
38
+ 2. Provide state-of-the-art models with performances as close as possible to the original models:
40
39
41
40
- We provide at least one example for each architecture which reproduces a result provided by the official authors
42
41
of said architecture.
@@ -48,33 +47,29 @@ A few other goals:
48
47
- Expose the models' internals as consistently as possible:
49
48
50
49
- We give access, using a single API, to the full hidden-states and attention weights.
51
- - Tokenizer and base model's API are standardized to easily switch between models.
50
+ - The preprocessing classes and base model APIs are standardized to easily switch between models.
52
51
53
- - Incorporate a subjective selection of promising tools for fine-tuning/ investigating these models:
52
+ - Incorporate a subjective selection of promising tools for fine-tuning and investigating these models:
54
53
55
- - A simple/ consistent way to add new tokens to the vocabulary and embeddings for fine-tuning.
56
- - Simple ways to mask and prune transformer heads.
54
+ - A simple and consistent way to add new tokens to the vocabulary and embeddings for fine-tuning.
55
+ - Simple ways to mask and prune Transformer heads.
57
56
58
- - Switch easily between PyTorch and TensorFlow 2.0, allowing training using one framework and inference using another.
57
+ - Easily switch between PyTorch, TensorFlow 2.0 and Flax , allowing training with one framework and inference with another.
59
58
60
59
## Main concepts
61
60
62
61
The library is built around three types of classes for each model:
63
62
64
- - **Model classes** such as [`BertModel`], which are 30+ PyTorch models ([torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)) or Keras models ([tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)) that work with the pretrained weights provided in the
65
- library.
66
- - **Configuration classes** such as [`BertConfig`], which store all the parameters required to build
67
- a model. You don't always need to instantiate these yourself. In particular, if you are using a pretrained model
68
- without any modification, creating the model will automatically take care of instantiating the configuration (which
69
- is part of the model).
70
- - **Tokenizer classes** such as [`BertTokenizer`], which store the vocabulary for each model and
71
- provide methods for encoding/decoding strings in a list of token embeddings indices to be fed to a model.
63
+ - **Model classes** can be PyTorch models ([torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)), Keras models ([tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)) or JAX/Flax models ([flax.linen.Module](https://flax.readthedocs.io/en/latest/api_reference/flax.linen.html)) that work with the pretrained weights provided in the library.
64
+ - **Configuration classes** store the hyperparameters required to build a model (such as the number of layers and hidden size). You don't always need to instantiate these yourself. In particular, if you are using a pretrained model without any modification, creating the model will automatically take care of instantiating the configuration (which is part of the model).
65
+ - **Preprocessing classes** convert the raw data into a format accepted by the model. A [tokenizer](main_classes/tokenizer) stores the vocabulary for each model and provide methods for encoding and decoding strings in a list of token embedding indices to be fed to a model. [Feature extractors](main_classes/feature_extractor) preprocess audio or vision inputs, and a [processor](main_classes/processors) handles multimodal inputs.
72
66
73
- All these classes can be instantiated from pretrained instances and saved locally using two methods:
67
+ All these classes can be instantiated from pretrained instances, saved locally, and shared on the Hub with three methods:
74
68
75
- - `from_pretrained()` lets you instantiate a model/ configuration/tokenizer from a pretrained version either
69
+ - `from_pretrained()` lets you instantiate a model, configuration, and preprocessing class from a pretrained version either
76
70
provided by the library itself (the supported models can be found on the [Model Hub](https://huggingface.co/models)) or
77
- stored locally (or on a server) by the user,
78
- - `save_pretrained()` lets you save a model/ configuration/tokenizer locally so that it can be reloaded using
71
+ stored locally (or on a server) by the user.
72
+ - `save_pretrained()` lets you save a model, configuration, and preprocessing class locally so that it can be reloaded using
79
73
`from_pretrained()`.
74
+ - `push_to_hub()` lets you share a model, configuration, and a preprocessing class to the Hub, so it is easily accessible to everyone.
80
75
0 commit comments