Skip to content

Commit 3efcfea

Browse files
authored
Deberta_v2 tf (huggingface#13120)
* Deberta_v2 tf * added new line at the end of file, make style * +V2, typo * remove never executed branch of code * rm cmnt and fixed typo in url filter * cleanup according to review comments * added #Copied from
1 parent 286ccef commit 3efcfea

File tree

8 files changed

+2109
-3
lines changed

8 files changed

+2109
-3
lines changed

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Flax), PyTorch, and/or TensorFlow.
351351
+-----------------------------+----------------+----------------+-----------------+--------------------+--------------+
352352
| DeBERTa ||||||
353353
+-----------------------------+----------------+----------------+-----------------+--------------------+--------------+
354-
| DeBERTa-v2 |||| ||
354+
| DeBERTa-v2 |||| ||
355355
+-----------------------------+----------------+----------------+-----------------+--------------------+--------------+
356356
| DeiT ||||||
357357
+-----------------------------+----------------+----------------+-----------------+--------------------+--------------+

docs/source/model_doc/deberta_v2.rst

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ New in v2:
5858
- **900M model & 1.5B model** Two additional model sizes are available: 900M and 1.5B, which significantly improves the
5959
performance of downstream tasks.
6060

61-
This model was contributed by `DeBERTa <https://huggingface.co/DeBERTa>`__. The original code can be found `here
61+
This model was contributed by `DeBERTa <https://huggingface.co/DeBERTa>`__. This model TF 2.0 implementation was
62+
contributed by `kamalkraj <https://huggingface.co/kamalkraj>`__. The original code can be found `here
6263
<https://github.com/microsoft/DeBERTa>`__.
6364

6465

@@ -117,3 +118,45 @@ DebertaV2ForQuestionAnswering
117118

118119
.. autoclass:: transformers.DebertaV2ForQuestionAnswering
119120
:members: forward
121+
122+
123+
TFDebertaV2Model
124+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125+
126+
.. autoclass:: transformers.TFDebertaV2Model
127+
:members: call
128+
129+
130+
TFDebertaV2PreTrainedModel
131+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
.. autoclass:: transformers.TFDebertaV2PreTrainedModel
134+
:members: call
135+
136+
137+
TFDebertaV2ForMaskedLM
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
140+
.. autoclass:: transformers.TFDebertaV2ForMaskedLM
141+
:members: call
142+
143+
144+
TFDebertaV2ForSequenceClassification
145+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+
.. autoclass:: transformers.TFDebertaV2ForSequenceClassification
148+
:members: call
149+
150+
151+
TFDebertaV2ForTokenClassification
152+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153+
154+
.. autoclass:: transformers.TFDebertaV2ForTokenClassification
155+
:members: call
156+
157+
158+
TFDebertaV2ForQuestionAnswering
159+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160+
161+
.. autoclass:: transformers.TFDebertaV2ForQuestionAnswering
162+
:members: call

src/transformers/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,17 @@
13411341
"TFDebertaPreTrainedModel",
13421342
]
13431343
)
1344+
_import_structure["models.deberta_v2"].extend(
1345+
[
1346+
"TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
1347+
"TFDebertaV2ForMaskedLM",
1348+
"TFDebertaV2ForQuestionAnswering",
1349+
"TFDebertaV2ForSequenceClassification",
1350+
"TFDebertaV2ForTokenClassification",
1351+
"TFDebertaV2Model",
1352+
"TFDebertaV2PreTrainedModel",
1353+
]
1354+
)
13441355
_import_structure["models.distilbert"].extend(
13451356
[
13461357
"TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
@@ -2925,6 +2936,15 @@
29252936
TFDebertaModel,
29262937
TFDebertaPreTrainedModel,
29272938
)
2939+
from .models.deberta_v2 import (
2940+
TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
2941+
TFDebertaV2ForMaskedLM,
2942+
TFDebertaV2ForQuestionAnswering,
2943+
TFDebertaV2ForSequenceClassification,
2944+
TFDebertaV2ForTokenClassification,
2945+
TFDebertaV2Model,
2946+
TFDebertaV2PreTrainedModel,
2947+
)
29282948
from .models.distilbert import (
29292949
TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
29302950
TFDistilBertForMaskedLM,

src/transformers/models/auto/modeling_tf_auto.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
TF_MODEL_MAPPING_NAMES = OrderedDict(
3030
[
3131
# Base model mapping
32+
("deberta-v2", "TFDebertaV2Model"),
3233
("deberta", "TFDebertaModel"),
3334
("rembert", "TFRemBertModel"),
3435
("roformer", "TFRoFormerModel"),
@@ -145,6 +146,7 @@
145146
TF_MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(
146147
[
147148
# Model for Masked LM mapping
149+
("deberta-v2", "TFDebertaV2ForMaskedLM"),
148150
("deberta", "TFDebertaForMaskedLM"),
149151
("rembert", "TFRemBertForMaskedLM"),
150152
("roformer", "TFRoFormerForMaskedLM"),
@@ -185,6 +187,7 @@
185187
TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
186188
[
187189
# Model for Sequence Classification mapping
190+
("deberta-v2", "TFDebertaV2ForSequenceClassification"),
188191
("deberta", "TFDebertaForSequenceClassification"),
189192
("rembert", "TFRemBertForSequenceClassification"),
190193
("roformer", "TFRoFormerForSequenceClassification"),
@@ -214,6 +217,7 @@
214217
TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
215218
[
216219
# Model for Question Answering mapping
220+
("deberta-v2", "TFDebertaV2ForQuestionAnswering"),
217221
("deberta", "TFDebertaForQuestionAnswering"),
218222
("rembert", "TFRemBertForQuestionAnswering"),
219223
("roformer", "TFRoFormerForQuestionAnswering"),
@@ -238,6 +242,7 @@
238242
TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
239243
[
240244
# Model for Token Classification mapping
245+
("deberta-v2", "TFDebertaV2ForTokenClassification"),
241246
("deberta", "TFDebertaForTokenClassification"),
242247
("rembert", "TFRemBertForTokenClassification"),
243248
("roformer", "TFRoFormerForTokenClassification"),

src/transformers/models/deberta_v2/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@
1818

1919
from typing import TYPE_CHECKING
2020

21-
from ...file_utils import _LazyModule, is_torch_available
21+
from ...file_utils import _LazyModule, is_tf_available, is_torch_available
2222

2323

2424
_import_structure = {
2525
"configuration_deberta_v2": ["DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP", "DebertaV2Config"],
2626
"tokenization_deberta_v2": ["DebertaV2Tokenizer"],
2727
}
2828

29+
if is_tf_available():
30+
_import_structure["modeling_tf_deberta_v2"] = [
31+
"TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
32+
"TFDebertaV2ForMaskedLM",
33+
"TFDebertaV2ForQuestionAnswering",
34+
"TFDebertaV2ForSequenceClassification",
35+
"TFDebertaV2ForTokenClassification",
36+
"TFDebertaV2Model",
37+
"TFDebertaV2PreTrainedModel",
38+
]
39+
2940
if is_torch_available():
3041
_import_structure["modeling_deberta_v2"] = [
3142
"DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
@@ -42,6 +53,17 @@
4253
from .configuration_deberta_v2 import DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP, DebertaV2Config
4354
from .tokenization_deberta_v2 import DebertaV2Tokenizer
4455

56+
if is_tf_available():
57+
from .modeling_tf_deberta_v2 import (
58+
TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
59+
TFDebertaV2ForMaskedLM,
60+
TFDebertaV2ForQuestionAnswering,
61+
TFDebertaV2ForSequenceClassification,
62+
TFDebertaV2ForTokenClassification,
63+
TFDebertaV2Model,
64+
TFDebertaV2PreTrainedModel,
65+
)
66+
4567
if is_torch_available():
4668
from .modeling_deberta_v2 import (
4769
DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,

0 commit comments

Comments
 (0)