berendg commited on
Commit
4277e38
1 Parent(s): 08bd783

Upload DebertaForMaskedLM

Browse files
Files changed (4) hide show
  1. README.md +199 -0
  2. config.json +37 -0
  3. configuration_deberta.py +192 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/home/ubuntu/bert_sparse/checkpoints/hu_deberta_100M_mlsm_post/10000/",
3
+ "architectures": [
4
+ "DebertaForMaskedLM"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_deberta.DebertaConfiguration",
9
+ "AutoModelForMaskedLM": "modeling_deberta.DebertaForMaskedLM"
10
+ },
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "layer_norm_eps": 1e-07,
17
+ "max_position_embeddings": 512,
18
+ "max_relative_positions": -1,
19
+ "model_type": "deberta",
20
+ "num_attention_heads": 12,
21
+ "num_concepts": 3000,
22
+ "num_hidden_layers": 12,
23
+ "pad_token_id": 0,
24
+ "pooler_dropout": 0,
25
+ "pooler_hidden_act": "gelu",
26
+ "pooler_hidden_size": 768,
27
+ "pos_att_type": [
28
+ "c2p",
29
+ "p2c"
30
+ ],
31
+ "position_biased_input": false,
32
+ "relative_attention": true,
33
+ "torch_dtype": "float32",
34
+ "transformers_version": "4.45.2",
35
+ "type_vocab_size": 0,
36
+ "vocab_size": 35001
37
+ }
configuration_deberta.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020, Microsoft and the HuggingFace Inc. team.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """DeBERTa model configuration"""
16
+
17
+ from collections import OrderedDict
18
+ from typing import TYPE_CHECKING, Any, Mapping, Optional, Union
19
+
20
+ from transformers.configuration_utils import PretrainedConfig
21
+ from transformers.onnx import OnnxConfig
22
+ from transformers.utils import logging
23
+
24
+
25
+ if TYPE_CHECKING:
26
+ from transformers import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType
27
+
28
+
29
+ logger = logging.get_logger(__name__)
30
+
31
+
32
+ class DebertaConfiguration(PretrainedConfig):
33
+ r"""
34
+ This is the configuration class to store the configuration of a [`DebertaModel`] or a [`TFDebertaModel`]. It is
35
+ used to instantiate a DeBERTa model according to the specified arguments, defining the model architecture.
36
+ Instantiating a configuration with the defaults will yield a similar configuration to that of the DeBERTa
37
+ [microsoft/deberta-base](https://huggingface.co/microsoft/deberta-base) architecture.
38
+
39
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
40
+ documentation from [`PretrainedConfig`] for more information.
41
+
42
+ Arguments:
43
+ vocab_size (`int`, *optional*, defaults to 30522):
44
+ Vocabulary size of the DeBERTa model. Defines the number of different tokens that can be represented by the
45
+ `inputs_ids` passed when calling [`DebertaModel`] or [`TFDebertaModel`].
46
+ hidden_size (`int`, *optional*, defaults to 768):
47
+ Dimensionality of the encoder layers and the pooler layer.
48
+ num_hidden_layers (`int`, *optional*, defaults to 12):
49
+ Number of hidden layers in the Transformer encoder.
50
+ num_attention_heads (`int`, *optional*, defaults to 12):
51
+ Number of attention heads for each attention layer in the Transformer encoder.
52
+ intermediate_size (`int`, *optional*, defaults to 3072):
53
+ Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
54
+ hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
55
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
56
+ `"relu"`, `"silu"`, `"gelu"`, `"tanh"`, `"gelu_fast"`, `"mish"`, `"linear"`, `"sigmoid"` and `"gelu_new"`
57
+ are supported.
58
+ hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
59
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
60
+ attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
61
+ The dropout ratio for the attention probabilities.
62
+ max_position_embeddings (`int`, *optional*, defaults to 512):
63
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
64
+ just in case (e.g., 512 or 1024 or 2048).
65
+ type_vocab_size (`int`, *optional*, defaults to 2):
66
+ The vocabulary size of the `token_type_ids` passed when calling [`DebertaModel`] or [`TFDebertaModel`].
67
+ initializer_range (`float`, *optional*, defaults to 0.02):
68
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
69
+ layer_norm_eps (`float`, *optional*, defaults to 1e-12):
70
+ The epsilon used by the layer normalization layers.
71
+ relative_attention (`bool`, *optional*, defaults to `False`):
72
+ Whether use relative position encoding.
73
+ max_relative_positions (`int`, *optional*, defaults to 1):
74
+ The range of relative positions `[-max_position_embeddings, max_position_embeddings]`. Use the same value
75
+ as `max_position_embeddings`.
76
+ pad_token_id (`int`, *optional*, defaults to 0):
77
+ The value used to pad input_ids.
78
+ position_biased_input (`bool`, *optional*, defaults to `True`):
79
+ Whether add absolute position embedding to content embedding.
80
+ pos_att_type (`List[str]`, *optional*):
81
+ The type of relative position attention, it can be a combination of `["p2c", "c2p"]`, e.g. `["p2c"]`,
82
+ `["p2c", "c2p"]`.
83
+ layer_norm_eps (`float`, *optional*, defaults to 1e-12):
84
+ The epsilon used by the layer normalization layers.
85
+
86
+ Example:
87
+
88
+ ```python
89
+ >>> from transformers import DebertaConfig, DebertaModel
90
+
91
+ >>> # Initializing a DeBERTa microsoft/deberta-base style configuration
92
+ >>> configuration = DebertaConfig()
93
+
94
+ >>> # Initializing a model (with random weights) from the microsoft/deberta-base style configuration
95
+ >>> model = DebertaModel(configuration)
96
+
97
+ >>> # Accessing the model configuration
98
+ >>> configuration = model.config
99
+ ```"""
100
+
101
+ model_type = "deberta"
102
+
103
+ def __init__(
104
+ self,
105
+ vocab_size=50265,
106
+ hidden_size=768,
107
+ num_hidden_layers=12,
108
+ num_attention_heads=12,
109
+ intermediate_size=3072,
110
+ hidden_act="gelu",
111
+ hidden_dropout_prob=0.1,
112
+ attention_probs_dropout_prob=0.1,
113
+ max_position_embeddings=512,
114
+ type_vocab_size=0,
115
+ initializer_range=0.02,
116
+ layer_norm_eps=1e-7,
117
+ relative_attention=False,
118
+ max_relative_positions=-1,
119
+ pad_token_id=0,
120
+ position_biased_input=True,
121
+ pos_att_type=None,
122
+ pooler_dropout=0,
123
+ pooler_hidden_act="gelu",
124
+ **kwargs,
125
+ ):
126
+ super().__init__(**kwargs)
127
+
128
+ self.hidden_size = hidden_size
129
+ self.num_hidden_layers = num_hidden_layers
130
+ self.num_attention_heads = num_attention_heads
131
+ self.intermediate_size = intermediate_size
132
+ self.hidden_act = hidden_act
133
+ self.hidden_dropout_prob = hidden_dropout_prob
134
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
135
+ self.max_position_embeddings = max_position_embeddings
136
+ self.type_vocab_size = type_vocab_size
137
+ self.initializer_range = initializer_range
138
+ self.relative_attention = relative_attention
139
+ self.max_relative_positions = max_relative_positions
140
+ self.pad_token_id = pad_token_id
141
+ self.position_biased_input = position_biased_input
142
+
143
+ # Backwards compatibility
144
+ if isinstance(pos_att_type, str):
145
+ pos_att_type = [x.strip() for x in pos_att_type.lower().split("|")]
146
+
147
+ self.pos_att_type = pos_att_type
148
+ self.vocab_size = vocab_size
149
+ self.layer_norm_eps = layer_norm_eps
150
+
151
+ self.pooler_hidden_size = kwargs.get("pooler_hidden_size", hidden_size)
152
+ self.pooler_dropout = pooler_dropout
153
+ self.pooler_hidden_act = pooler_hidden_act
154
+
155
+
156
+ # Copied from transformers.models.deberta_v2.configuration_deberta_v2.DebertaV2OnnxConfig
157
+ class DebertaOnnxConfig(OnnxConfig):
158
+ @property
159
+ def inputs(self) -> Mapping[str, Mapping[int, str]]:
160
+ if self.task == "multiple-choice":
161
+ dynamic_axis = {0: "batch", 1: "choice", 2: "sequence"}
162
+ else:
163
+ dynamic_axis = {0: "batch", 1: "sequence"}
164
+ if self._config.type_vocab_size > 0:
165
+ return OrderedDict(
166
+ [("input_ids", dynamic_axis), ("attention_mask", dynamic_axis), ("token_type_ids", dynamic_axis)]
167
+ )
168
+ else:
169
+ return OrderedDict([("input_ids", dynamic_axis), ("attention_mask", dynamic_axis)])
170
+
171
+ @property
172
+ def default_onnx_opset(self) -> int:
173
+ return 12
174
+
175
+ def generate_dummy_inputs(
176
+ self,
177
+ preprocessor: Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"],
178
+ batch_size: int = -1,
179
+ seq_length: int = -1,
180
+ num_choices: int = -1,
181
+ is_pair: bool = False,
182
+ framework: Optional["TensorType"] = None,
183
+ num_channels: int = 3,
184
+ image_width: int = 40,
185
+ image_height: int = 40,
186
+ tokenizer: "PreTrainedTokenizerBase" = None,
187
+ ) -> Mapping[str, Any]:
188
+ dummy_inputs = super().generate_dummy_inputs(preprocessor=preprocessor, framework=framework)
189
+ if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
190
+ del dummy_inputs["token_type_ids"]
191
+ return dummy_inputs
192
+
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e90da32b3341ca49c8f5c093342ecf13d565a3d3d4704c8a679628790270f4bd
3
+ size 894188928