rita443 commited on
Commit
575b426
1 Parent(s): 0b38a2b

Upload model

Browse files
Files changed (5) hide show
  1. README.md +201 -0
  2. config.json +200 -0
  3. config.py +29 -0
  4. model.py +96 -0
  5. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]
200
+
201
+
config.json ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "liaad/srl-en_roberta-large_hf",
3
+ "architectures": [
4
+ "SRLModel"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "config.SRLModelConfig",
8
+ "AutoModel": "model.SRLModel"
9
+ },
10
+ "bert_model_name": "FacebookAI/roberta-large",
11
+ "embedding_dropout": 0.1,
12
+ "id2label": {
13
+ "0": "O",
14
+ "1": "<unk>",
15
+ "10": "I-C-A0",
16
+ "11": "I-C-A2",
17
+ "12": "B-A2",
18
+ "13": "B-R-A1",
19
+ "14": "I-C-AM-COM",
20
+ "15": "B-A0",
21
+ "16": "B-A4",
22
+ "17": "I-A3",
23
+ "18": "B-C-AM-COM",
24
+ "19": "B-C-AM-DIS",
25
+ "2": "I-C-AM-LOC",
26
+ "20": "B-C-AM-PRP",
27
+ "21": "I-AM-ADV",
28
+ "22": "I-AM-PRP",
29
+ "23": "I-AM-DIS",
30
+ "24": "B-C-A3",
31
+ "25": "B-AM-PRD",
32
+ "26": "B-C-A1",
33
+ "27": "I-C-AM-ADV",
34
+ "28": "I-C-AM-MNR",
35
+ "29": "I-R-A3",
36
+ "3": "I-AM-COM",
37
+ "30": "B-C-AM-NEG",
38
+ "31": "I-C-A3",
39
+ "32": "B-C-A2",
40
+ "33": "I-C-AM-NEG",
41
+ "34": "B-A3",
42
+ "35": "B-AM-LOC",
43
+ "36": "B-C-AM-TMP",
44
+ "37": "I-AM-DIR",
45
+ "38": "B-R-A2",
46
+ "39": "B-A5",
47
+ "4": "B-R-A0",
48
+ "40": "B-C-A0",
49
+ "41": "I-C-AM-PRP",
50
+ "42": "B-C-AM-PRD",
51
+ "43": "I-A1",
52
+ "44": "B-C-AM-EXT",
53
+ "45": "B-AM-CAU",
54
+ "46": "B-AM-MOD",
55
+ "47": "B-AM-COM",
56
+ "48": "B-AM-NEG",
57
+ "49": "B-AM-REC",
58
+ "5": "B-R-A4",
59
+ "50": "B-AM-ADV",
60
+ "51": "I-R-A1",
61
+ "52": "B-AM-DIR",
62
+ "53": "I-C-AM-TMP",
63
+ "54": "B-C-AM-MNR",
64
+ "55": "I-AM-GOL",
65
+ "56": "I-R-A2",
66
+ "57": "I-R-A0",
67
+ "58": "B-C-AM-DIR",
68
+ "59": "I-C-A4",
69
+ "6": "I-R-A4",
70
+ "60": "B-C-AM-LOC",
71
+ "61": "I-A2",
72
+ "62": "I-AM-MOD",
73
+ "63": "B-C-AM-DSP",
74
+ "64": "B-AM-TMP",
75
+ "65": "I-AM-REC",
76
+ "66": "I-C-AM-EXT",
77
+ "67": "I-C-AM-DIR",
78
+ "68": "I-AM-CAU",
79
+ "69": "I-C-AM-DIS",
80
+ "7": "B-AM-DIS",
81
+ "70": "I-C-AM-ADJ",
82
+ "71": "I-AM-LOC",
83
+ "72": "I-AM-NEG",
84
+ "73": "B-A1",
85
+ "74": "B-C-AM-ADV",
86
+ "75": "B-AM-GOL",
87
+ "76": "I-C-AM-DSP",
88
+ "77": "I-AM-PRD",
89
+ "78": "B-C-AM-ADJ",
90
+ "79": "B-C-A4",
91
+ "8": "B-V",
92
+ "80": "B-AM-EXT",
93
+ "81": "I-AM-TMP",
94
+ "82": "I-AM-EXT",
95
+ "83": "I-A0",
96
+ "84": "B-AM-MNR",
97
+ "85": "I-C-A1",
98
+ "86": "I-A4",
99
+ "87": "I-AM-MNR",
100
+ "88": "B-AM-PRP",
101
+ "89": "B-R-A3",
102
+ "9": "I-A5"
103
+ },
104
+ "label2id": {
105
+ "<unk>": 1,
106
+ "B-A0": 15,
107
+ "B-A1": 73,
108
+ "B-A2": 12,
109
+ "B-A3": 34,
110
+ "B-A4": 16,
111
+ "B-A5": 39,
112
+ "B-AM-ADV": 50,
113
+ "B-AM-CAU": 45,
114
+ "B-AM-COM": 47,
115
+ "B-AM-DIR": 52,
116
+ "B-AM-DIS": 7,
117
+ "B-AM-EXT": 80,
118
+ "B-AM-GOL": 75,
119
+ "B-AM-LOC": 35,
120
+ "B-AM-MNR": 84,
121
+ "B-AM-MOD": 46,
122
+ "B-AM-NEG": 48,
123
+ "B-AM-PRD": 25,
124
+ "B-AM-PRP": 88,
125
+ "B-AM-REC": 49,
126
+ "B-AM-TMP": 64,
127
+ "B-C-A0": 40,
128
+ "B-C-A1": 26,
129
+ "B-C-A2": 32,
130
+ "B-C-A3": 24,
131
+ "B-C-A4": 79,
132
+ "B-C-AM-ADJ": 78,
133
+ "B-C-AM-ADV": 74,
134
+ "B-C-AM-COM": 18,
135
+ "B-C-AM-DIR": 58,
136
+ "B-C-AM-DIS": 19,
137
+ "B-C-AM-DSP": 63,
138
+ "B-C-AM-EXT": 44,
139
+ "B-C-AM-LOC": 60,
140
+ "B-C-AM-MNR": 54,
141
+ "B-C-AM-NEG": 30,
142
+ "B-C-AM-PRD": 42,
143
+ "B-C-AM-PRP": 20,
144
+ "B-C-AM-TMP": 36,
145
+ "B-R-A0": 4,
146
+ "B-R-A1": 13,
147
+ "B-R-A2": 38,
148
+ "B-R-A3": 89,
149
+ "B-R-A4": 5,
150
+ "B-V": 8,
151
+ "I-A0": 83,
152
+ "I-A1": 43,
153
+ "I-A2": 61,
154
+ "I-A3": 17,
155
+ "I-A4": 86,
156
+ "I-A5": 9,
157
+ "I-AM-ADV": 21,
158
+ "I-AM-CAU": 68,
159
+ "I-AM-COM": 3,
160
+ "I-AM-DIR": 37,
161
+ "I-AM-DIS": 23,
162
+ "I-AM-EXT": 82,
163
+ "I-AM-GOL": 55,
164
+ "I-AM-LOC": 71,
165
+ "I-AM-MNR": 87,
166
+ "I-AM-MOD": 62,
167
+ "I-AM-NEG": 72,
168
+ "I-AM-PRD": 77,
169
+ "I-AM-PRP": 22,
170
+ "I-AM-REC": 65,
171
+ "I-AM-TMP": 81,
172
+ "I-C-A0": 10,
173
+ "I-C-A1": 85,
174
+ "I-C-A2": 11,
175
+ "I-C-A3": 31,
176
+ "I-C-A4": 59,
177
+ "I-C-AM-ADJ": 70,
178
+ "I-C-AM-ADV": 27,
179
+ "I-C-AM-COM": 14,
180
+ "I-C-AM-DIR": 67,
181
+ "I-C-AM-DIS": 69,
182
+ "I-C-AM-DSP": 76,
183
+ "I-C-AM-EXT": 66,
184
+ "I-C-AM-LOC": 2,
185
+ "I-C-AM-MNR": 28,
186
+ "I-C-AM-NEG": 33,
187
+ "I-C-AM-PRP": 41,
188
+ "I-C-AM-TMP": 53,
189
+ "I-R-A0": 57,
190
+ "I-R-A1": 51,
191
+ "I-R-A2": 56,
192
+ "I-R-A3": 29,
193
+ "I-R-A4": 6,
194
+ "O": 0
195
+ },
196
+ "model_type": "srl",
197
+ "num_labels": 90,
198
+ "torch_dtype": "float32",
199
+ "transformers_version": "4.39.3"
200
+ }
config.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+ class SRLModelConfig(PretrainedConfig):
4
+ model_type = "srl"
5
+
6
+ def __init__(
7
+ self,
8
+ num_labels=0,
9
+ bert_model_name="bert-base-uncased",
10
+ embedding_dropout=0.0,
11
+ label2id = {},
12
+ id2label = {},
13
+ **kwargs,
14
+ ):
15
+ super().__init__(**kwargs)
16
+ self.num_labels = num_labels
17
+ self.bert_model_name = bert_model_name
18
+ self.embedding_dropout = embedding_dropout
19
+ self.label2id = label2id
20
+ self.id2label = id2label
21
+
22
+ def to_dict(self):
23
+ config_dict = super().to_dict()
24
+
25
+ config_dict["num_labels"] = self.num_labels
26
+ # config_dict["bert_model_name"] = self.bert_model_name
27
+ # config_dict["embedding_dropout"] = self.embedding_dropout
28
+
29
+ return config_dict
model.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch.nn as nn
2
+ import torch.nn.functional as F
3
+ from transformers import AutoModel, AutoTokenizer, PreTrainedModel
4
+ from .config import SRLModelConfig
5
+
6
+
7
+ class SRLModel(PreTrainedModel):
8
+ config_class = SRLModelConfig
9
+
10
+ def __init__(self, config):
11
+ super().__init__(config)
12
+
13
+ print(config.num_labels, config.bert_model_name, config.embedding_dropout)
14
+
15
+ # Load pre-trained transformer-based model and tokenizer
16
+ self.tokenizer = AutoTokenizer.from_pretrained(config.bert_model_name)
17
+ self.transformer = AutoModel.from_pretrained(
18
+ config.bert_model_name,
19
+ num_labels=config.num_labels,
20
+ output_hidden_states=True,
21
+ )
22
+ self.transformer.config.id2label = config.id2label
23
+ self.transformer.config.label2id = config.label2id
24
+
25
+ # The roberta models do not have token_type_embeddings
26
+ # (the type_vocab_size is 1)
27
+ # but we use this to pass the verb's position
28
+ # so we need to change the model and initialize the embeddings randomly
29
+ if "xlm" in config.bert_model_name or "roberta" in config.bert_model_name:
30
+ self.transformer.config.type_vocab_size = 2
31
+ # Create a new Embeddings layer, with 2 possible segments IDs instead of 1
32
+ self.transformer.embeddings.token_type_embeddings = nn.Embedding(
33
+ 2, self.transformer.config.hidden_size
34
+ )
35
+ # Initialize it
36
+ self.transformer.embeddings.token_type_embeddings.weight.data.normal_(
37
+ mean=0.0, std=self.transformer.config.initializer_range
38
+ )
39
+
40
+ # Linear layer for tag projection
41
+ self.tag_projection_layer = nn.Linear(
42
+ self.transformer.config.hidden_size, config.num_labels
43
+ )
44
+
45
+ # Dropout layer for embeddings
46
+ self.embedding_dropout = nn.Dropout(p=config.embedding_dropout)
47
+
48
+ # Number of labels
49
+ self.num_labels = config.num_labels
50
+
51
+ def forward(self, input_ids, attention_mask, token_type_ids, labels=None):
52
+
53
+ # print("FORWARD")
54
+ # print(labels)
55
+
56
+ # Forward pass through the transformer model
57
+ # Returns BaseModelOutputWithPoolingAndCrossAttentions
58
+ outputs = self.transformer(
59
+ input_ids=input_ids,
60
+ attention_mask=attention_mask,
61
+ token_type_ids=token_type_ids,
62
+ )
63
+
64
+ # Extract the [CLS] token representation
65
+ # cls_output = outputs.pooler_output
66
+
67
+ bert_embedding = outputs.last_hidden_state
68
+
69
+ # Apply dropout to the embeddings
70
+ embedded_text_input = self.embedding_dropout(bert_embedding)
71
+
72
+ # Project to tag space
73
+ logits = self.tag_projection_layer(embedded_text_input)
74
+
75
+ reshaped_log_probs = logits.view(-1, self.num_labels)
76
+ class_probabilities = F.softmax(reshaped_log_probs, dim=-1).view(
77
+ logits.size(0), logits.size(1), -1
78
+ )
79
+
80
+ output_dict = {"logits": logits, "class_probabilities": class_probabilities}
81
+
82
+ output_dict["attention_mask"] = attention_mask
83
+ output_dict["input_ids"] = input_ids
84
+ # output_dict["start_offsets"] = start_offsets
85
+
86
+ if labels is not None:
87
+ # print("Input", logits.view(-1, self.num_labels).size())
88
+ # print("Target", labels.view(-1).size())
89
+ # print("C", self.num_labels)
90
+ # print("AllenNLP function", logits.size(-1))
91
+ # Could consider passing ignore_index as 0 (pad index) for minor optimization
92
+ loss = nn.CrossEntropyLoss(ignore_index=-100)(
93
+ logits.view(-1, self.num_labels), labels.view(-1)
94
+ )
95
+ output_dict["loss"] = loss
96
+ return output_dict
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a882024c5267e9d07627c0b53281a2e8117619330fa629bd10f789fb61bbd635
3
+ size 1421861880