"model/models/qwen25vl/model_text.go" did not exist on "7bae7fa5ce6a83cfecde12015a7c43dfa3e8bffc"
philosophy.rst 5.28 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.

Sylvain Gugger's avatar
Sylvain Gugger committed
13
Philosophy
Sylvain Gugger's avatar
Sylvain Gugger committed
14
=======================================================================================================================
Sylvain Gugger's avatar
Sylvain Gugger committed
15

Sylvain Gugger's avatar
Sylvain Gugger committed
16
馃 Transformers is an opinionated library built for:
Sylvain Gugger's avatar
Sylvain Gugger committed
17
18
19
20
21
22
23
24
25
26

- NLP researchers and educators seeking to use/study/extend large-scale transformers models
- hands-on practitioners who want to fine-tune those models and/or serve them in production
- engineers who just want to download a pretrained model and use it to solve a given NLP task.

The library was designed with two strong goals in mind:

- Be as easy and fast to use as possible:

    - We strongly limited the number of user-facing abstractions to learn, in fact, there are almost no abstractions,
Sylvain Gugger's avatar
Sylvain Gugger committed
27
      just three standard classes required to use each model: :doc:`configuration <main_classes/configuration>`,
Sylvain Gugger's avatar
Sylvain Gugger committed
28
29
30
      :doc:`models <main_classes/model>` and :doc:`tokenizer <main_classes/tokenizer>`.
    - All of these classes can be initialized in a simple and unified way from pretrained instances by using a common
      :obj:`from_pretrained()` instantiation method which will take care of downloading (if needed), caching and
Sylvain Gugger's avatar
Sylvain Gugger committed
31
32
33
      loading the related class instance and associated data (configurations' hyper-parameters, tokenizers' vocabulary,
      and models' weights) from a pretrained checkpoint provided on `Hugging Face Hub
      <https://huggingface.co/models>`__ or your own saved checkpoint.
Sylvain Gugger's avatar
Sylvain Gugger committed
34
    - On top of those three base classes, the library provides two APIs: :func:`~transformers.pipeline` for quickly
Sylvain Gugger's avatar
Sylvain Gugger committed
35
      using a model (plus its associated tokenizer and configuration) on a given task and
Sylvain Gugger's avatar
Sylvain Gugger committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
      :func:`~transformers.Trainer`/:func:`~transformers.TFTrainer` to quickly train or fine-tune a given model.
    - As a consequence, this library is NOT a modular toolbox of building blocks for neural nets. If you want to
      extend/build-upon the library, just use regular Python/PyTorch/TensorFlow/Keras modules and inherit from the base
      classes of the library to reuse functionalities like model loading/saving.

- Provide state-of-the-art models with performances as close as possible to the original models:

    - We provide at least one example for each architecture which reproduces a result provided by the official authors
      of said architecture.
    - The code is usually as close to the original code base as possible which means some PyTorch code may be not as
      *pytorchic* as it could be as a result of being converted TensorFlow code and vice versa.

A few other goals:

- Expose the models' internals as consistently as possible:

    - We give access, using a single API, to the full hidden-states and attention weights.
    - Tokenizer and base model's API are standardized to easily switch between models.

- Incorporate a subjective selection of promising tools for fine-tuning/investigating these models:

    - A simple/consistent way to add new tokens to the vocabulary and embeddings for fine-tuning.
    - Simple ways to mask and prune transformer heads.

Stas Bekman's avatar
Stas Bekman committed
60
- Switch easily between PyTorch and TensorFlow 2.0, allowing training using one framework and inference using another.
Sylvain Gugger's avatar
Sylvain Gugger committed
61
62

Main concepts
Sylvain Gugger's avatar
Sylvain Gugger committed
63
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sylvain Gugger's avatar
Sylvain Gugger committed
64

Stas Bekman's avatar
Stas Bekman committed
65
The library is built around three types of classes for each model:
Sylvain Gugger's avatar
Sylvain Gugger committed
66

Sylvain Gugger's avatar
Sylvain Gugger committed
67
68
69
70
- **Model classes** such as :class:`~transformers.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
  library.
Sylvain Gugger's avatar
Sylvain Gugger committed
71
72
73
74
75
76
77
78
79
- **Configuration classes** such as :class:`~transformers.BertConfig`, which store all the parameters required to build
  a model. 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).
- **Tokenizer classes** such as :class:`~transformers.BertTokenizer`, which store the vocabulary for each model and
  provide methods for encoding/decoding strings in a list of token embeddings indices to be fed to a model.

All these classes can be instantiated from pretrained instances and saved locally using two methods:

Stas Bekman's avatar
Stas Bekman committed
80
- :obj:`from_pretrained()` lets you instantiate a model/configuration/tokenizer from a pretrained version either
Sylvain Gugger's avatar
Sylvain Gugger committed
81
82
  provided by the library itself (the supported models are provided in the list :doc:`here <pretrained_models>` or
  stored locally (or on a server) by the user,
Stas Bekman's avatar
Stas Bekman committed
83
- :obj:`save_pretrained()` lets you save a model/configuration/tokenizer locally so that it can be reloaded using
Sylvain Gugger's avatar
Sylvain Gugger committed
84
85
  :obj:`from_pretrained()`.