__init__.py 10.4 KB
Newer Older
Lysandre's avatar
Lysandre committed
1
__version__ = "2.1.1"
thomwolf's avatar
thomwolf committed
2

thomwolf's avatar
thomwolf committed
3
4
5
6
7
8
9
10
11
12
13
# Work around to update TensorFlow's absl.logging threshold which alters the
# default Python logging output behavior when present.
# see: https://github.com/abseil/abseil-py/issues/99
# and: https://github.com/tensorflow/tensorflow/issues/26691#issuecomment-500369493
try:
    import absl.logging
    absl.logging.set_verbosity('info')
    absl.logging.set_stderrthreshold('info')
    absl.logging._warn_preinit_stderr = False
except:
    pass
14

thomwolf's avatar
thomwolf committed
15
16
17
18
import logging

logger = logging.getLogger(__name__)  # pylint: disable=invalid-name

thomwolf's avatar
thomwolf committed
19
# Files and general utilities
20
from .file_utils import (TRANSFORMERS_CACHE, PYTORCH_TRANSFORMERS_CACHE, PYTORCH_PRETRAINED_BERT_CACHE,
thomwolf's avatar
thomwolf committed
21
22
23
24
25
26
27
28
29
30
31
32
33
                         cached_path, add_start_docstrings, add_end_docstrings,
                         WEIGHTS_NAME, TF2_WEIGHTS_NAME, TF_WEIGHTS_NAME, CONFIG_NAME,
                         is_tf_available, is_torch_available)

from .data import (is_sklearn_available,
                   InputExample, InputFeatures, DataProcessor,
                   glue_output_modes, glue_convert_examples_to_features,
                   glue_processors, glue_tasks_num_labels)

if is_sklearn_available():
    from .data import glue_compute_metrics

# Tokenizers
34
from .tokenization_utils import (PreTrainedTokenizer)
thomwolf's avatar
thomwolf committed
35
from .tokenization_auto import AutoTokenizer
thomwolf's avatar
thomwolf committed
36
from .tokenization_bert import BertTokenizer, BasicTokenizer, WordpieceTokenizer
thomwolf's avatar
thomwolf committed
37
from .tokenization_openai import OpenAIGPTTokenizer
38
from .tokenization_transfo_xl import (TransfoXLTokenizer, TransfoXLCorpus)
thomwolf's avatar
thomwolf committed
39
from .tokenization_gpt2 import GPT2Tokenizer
keskarnitish's avatar
keskarnitish committed
40
from .tokenization_ctrl import CTRLTokenizer
41
from .tokenization_xlnet import XLNetTokenizer, SPIECE_UNDERLINE
thomwolf's avatar
thomwolf committed
42
from .tokenization_xlm import XLMTokenizer
43
from .tokenization_roberta import RobertaTokenizer
thomwolf's avatar
thomwolf committed
44
from .tokenization_distilbert import DistilBertTokenizer
45
from .tokenization_camembert import CamembertTokenizer
46

47
# Configurations
48
from .configuration_utils import PretrainedConfig
49
50
51
52
53
from .configuration_auto import AutoConfig
from .configuration_bert import BertConfig, BERT_PRETRAINED_CONFIG_ARCHIVE_MAP
from .configuration_openai import OpenAIGPTConfig, OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP
from .configuration_transfo_xl import TransfoXLConfig, TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP
from .configuration_gpt2 import GPT2Config, GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP
keskarnitish's avatar
keskarnitish committed
54
from .configuration_ctrl import CTRLConfig, CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP
55
from .configuration_xlnet import XLNetConfig, XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP
keskarnitish's avatar
keskarnitish committed
56
from .configuration_ctrl import CTRLConfig, CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP
57
58
59
from .configuration_xlm import XLMConfig, XLM_PRETRAINED_CONFIG_ARCHIVE_MAP
from .configuration_roberta import RobertaConfig, ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP
from .configuration_distilbert import DistilBertConfig, DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP
60
from .configuration_camembert import CamembertConfig, CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP
61

62
# Modeling
thomwolf's avatar
thomwolf committed
63
if is_torch_available():
thomwolf's avatar
thomwolf committed
64
65
66
67
68
69
70
71
    from .modeling_utils import (PreTrainedModel, prune_layer, Conv1D)
    from .modeling_auto import (AutoModel, AutoModelForSequenceClassification, AutoModelForQuestionAnswering,
                                AutoModelWithLMHead)

    from .modeling_bert import (BertPreTrainedModel, BertModel, BertForPreTraining,
                                BertForMaskedLM, BertForNextSentencePrediction,
                                BertForSequenceClassification, BertForMultipleChoice,
                                BertForTokenClassification, BertForQuestionAnswering,
72
                                load_tf_weights_in_bert, BERT_PRETRAINED_MODEL_ARCHIVE_MAP)
thomwolf's avatar
thomwolf committed
73
74
75
76
    from .modeling_openai import (OpenAIGPTPreTrainedModel, OpenAIGPTModel,
                                OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel,
                                load_tf_weights_in_openai_gpt, OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_MAP)
    from .modeling_transfo_xl import (TransfoXLPreTrainedModel, TransfoXLModel, TransfoXLLMHeadModel,
77
                                    AdaptiveEmbedding,
thomwolf's avatar
thomwolf committed
78
79
80
81
                                    load_tf_weights_in_transfo_xl, TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_MAP)
    from .modeling_gpt2 import (GPT2PreTrainedModel, GPT2Model,
                                GPT2LMHeadModel, GPT2DoubleHeadsModel,
                                load_tf_weights_in_gpt2, GPT2_PRETRAINED_MODEL_ARCHIVE_MAP)
keskarnitish's avatar
keskarnitish committed
82
83
84
    from .modeling_ctrl import (CTRLPreTrainedModel, CTRLModel,
                                CTRLLMHeadModel,
                                CTRL_PRETRAINED_MODEL_ARCHIVE_MAP)
thomwolf's avatar
thomwolf committed
85
    from .modeling_xlnet import (XLNetPreTrainedModel, XLNetModel, XLNetLMHeadModel,
86
87
                                XLNetForSequenceClassification, XLNetForMultipleChoice,
                                XLNetForQuestionAnsweringSimple, XLNetForQuestionAnswering,
thomwolf's avatar
thomwolf committed
88
89
90
                                load_tf_weights_in_xlnet, XLNET_PRETRAINED_MODEL_ARCHIVE_MAP)
    from .modeling_xlm import (XLMPreTrainedModel , XLMModel,
                            XLMWithLMHeadModel, XLMForSequenceClassification,
91
92
                            XLMForQuestionAnswering, XLMForQuestionAnsweringSimple,
                            XLM_PRETRAINED_MODEL_ARCHIVE_MAP)
93
94
    from .modeling_roberta import (RobertaForMaskedLM, RobertaModel,
                                RobertaForSequenceClassification, RobertaForMultipleChoice,
Matt Maybeno's avatar
Matt Maybeno committed
95
                                RobertaForTokenClassification,
thomwolf's avatar
thomwolf committed
96
97
98
                                ROBERTA_PRETRAINED_MODEL_ARCHIVE_MAP)
    from .modeling_distilbert import (DistilBertForMaskedLM, DistilBertModel,
                                DistilBertForSequenceClassification, DistilBertForQuestionAnswering,
99
                                DistilBertForTokenClassification,
thomwolf's avatar
thomwolf committed
100
                                DISTILBERT_PRETRAINED_MODEL_ARCHIVE_MAP)
101
102
    from .modeling_camembert import (CamembertForMaskedLM, CamembertModel,
                                CamembertForSequenceClassification, CamembertForMultipleChoice,
103
                                CamembertForTokenClassification,
104
                                CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_MAP)
105
    from .modeling_encoder_decoder import PreTrainedEncoderDecoder, Model2Model
thomwolf's avatar
thomwolf committed
106
107

    # Optimization
108
109
    from .optimization import (AdamW, get_constant_schedule, get_constant_schedule_with_warmup, get_cosine_schedule_with_warmup,
                               get_cosine_with_hard_restarts_schedule_with_warmup, get_linear_schedule_with_warmup)
thomwolf's avatar
thomwolf committed
110
111
112


# TensorFlow
thomwolf's avatar
thomwolf committed
113
if is_tf_available():
thomwolf's avatar
thomwolf committed
114
    from .modeling_tf_utils import TFPreTrainedModel, TFSharedEmbeddings, TFSequenceSummary
thomwolf's avatar
thomwolf committed
115
116
117
    from .modeling_tf_auto import (TFAutoModel, TFAutoModelForSequenceClassification, TFAutoModelForQuestionAnswering,
                                   TFAutoModelWithLMHead)

118
119
    from .modeling_tf_bert import (TFBertPreTrainedModel, TFBertMainLayer, TFBertEmbeddings,
                                   TFBertModel, TFBertForPreTraining,
thomwolf's avatar
thomwolf committed
120
121
122
123
                                   TFBertForMaskedLM, TFBertForNextSentencePrediction,
                                   TFBertForSequenceClassification, TFBertForMultipleChoice,
                                   TFBertForTokenClassification, TFBertForQuestionAnswering,
                                   TF_BERT_PRETRAINED_MODEL_ARCHIVE_MAP)
thomwolf's avatar
thomwolf committed
124

thomwolf's avatar
thomwolf committed
125
    from .modeling_tf_gpt2 import (TFGPT2PreTrainedModel, TFGPT2MainLayer,
126
127
128
                                   TFGPT2Model, TFGPT2LMHeadModel, TFGPT2DoubleHeadsModel,
                                   TF_GPT2_PRETRAINED_MODEL_ARCHIVE_MAP)

129
130
131
132
    from .modeling_tf_openai import (TFOpenAIGPTPreTrainedModel, TFOpenAIGPTMainLayer,
                                     TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel,
                                     TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_MAP)

thomwolf's avatar
thomwolf committed
133
134
135
136
    from .modeling_tf_transfo_xl import (TFTransfoXLPreTrainedModel, TFTransfoXLMainLayer,
                                         TFTransfoXLModel, TFTransfoXLLMHeadModel,
                                         TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_MAP)

137
138
139
140
141
    from .modeling_tf_xlnet import (TFXLNetPreTrainedModel, TFXLNetMainLayer,
                                    TFXLNetModel, TFXLNetLMHeadModel,
                                    TFXLNetForSequenceClassification,
                                    TFXLNetForQuestionAnsweringSimple,
                                    TF_XLNET_PRETRAINED_MODEL_ARCHIVE_MAP)
142

thomwolf's avatar
thomwolf committed
143
144
145
146
147
148
    from .modeling_tf_xlm import (TFXLMPreTrainedModel, TFXLMMainLayer,
                                  TFXLMModel, TFXLMWithLMHeadModel,
                                  TFXLMForSequenceClassification,
                                  TFXLMForQuestionAnsweringSimple,
                                  TF_XLM_PRETRAINED_MODEL_ARCHIVE_MAP)

149
    from .modeling_tf_roberta import (TFRobertaPreTrainedModel, TFRobertaMainLayer,
thomwolf's avatar
thomwolf committed
150
                                      TFRobertaModel, TFRobertaForMaskedLM,
151
                                      TFRobertaForSequenceClassification,
Matt Maybeno's avatar
Matt Maybeno committed
152
                                      TFRobertaForTokenClassification,
153
154
155
156
157
                                      TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_MAP)

    from .modeling_tf_distilbert import (TFDistilBertPreTrainedModel, TFDistilBertMainLayer,
                                         TFDistilBertModel, TFDistilBertForMaskedLM,
                                         TFDistilBertForSequenceClassification,
158
                                         TFDistilBertForQuestionAnswering,
159
160
                                         TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_MAP)

thomwolf's avatar
thomwolf committed
161
162
163
164
    from .modeling_tf_ctrl import (TFCTRLPreTrainedModel, TFCTRLModel,
                                    TFCTRLLMHeadModel,
                                    TF_CTRL_PRETRAINED_MODEL_ARCHIVE_MAP)

thomwolf's avatar
thomwolf committed
165
# TF 2.0 <=> PyTorch conversion utilities
166
167
168
169
170
171
172
from .modeling_tf_pytorch_utils import (convert_tf_weight_name_to_pt_weight_name,
                                        load_pytorch_checkpoint_in_tf2_model,
                                        load_pytorch_weights_in_tf2_model,
                                        load_pytorch_model_in_tf2_model,
                                        load_tf2_checkpoint_in_pytorch_model,
                                        load_tf2_weights_in_pytorch_model,
                                        load_tf2_model_in_pytorch_model)
173
174
175
176
177

if not is_tf_available() and not is_torch_available():
    logger.warning("Neither PyTorch nor TensorFlow >= 2.0 have been found."
                   "Models won't be available and only tokenizers, configuration"
                   "and file/data utilities can be used.")