rita443 commited on
Commit
750e21b
1 Parent(s): 407f6b5

Upload model

Browse files
Files changed (5) hide show
  1. README.md +201 -0
  2. config.json +146 -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,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "liaad/srl-pt_bertimbau-base_hf",
3
+ "architectures": [
4
+ "SRLModel"
5
+ ],
6
+ "auto-map": {
7
+ "AutoConfig": "config.SRLModelConfig",
8
+ "AutoModel": "model.SRLModel"
9
+ },
10
+ "auto_map": {
11
+ "AutoConfig": "config.SRLModelConfig",
12
+ "AutoModel": "model.SRLModel"
13
+ },
14
+ "bert_model_name": "neuralmind/bert-base-portuguese-cased",
15
+ "embedding_dropout": 0.1,
16
+ "id2label": {
17
+ "0": "O",
18
+ "1": "[UNK]",
19
+ "10": "I-C-AM-PRD",
20
+ "11": "I-C-AM-TMP",
21
+ "12": "B-C-AM-LOC",
22
+ "13": "B-AM-PRD",
23
+ "14": "B-AM-EXT",
24
+ "15": "I-C-AM-LOC",
25
+ "16": "I-AM-PNC",
26
+ "17": "I-C-AM-CAU",
27
+ "18": "I-C-A2",
28
+ "19": "B-C-AM-MNR",
29
+ "2": "B-AM-CAU",
30
+ "20": "B-AM-PNC",
31
+ "21": "I-A2",
32
+ "22": "B-C-AM-ADV",
33
+ "23": "B-AM-REC",
34
+ "24": "B-C-A2",
35
+ "25": "B-AM-ADV",
36
+ "26": "B-A1",
37
+ "27": "I-C-AM-MNR",
38
+ "28": "I-A3",
39
+ "29": "I-C-AM-ADV",
40
+ "3": "I-AM-CAU",
41
+ "30": "I-A1",
42
+ "31": "B-A4",
43
+ "32": "B-C-A3",
44
+ "33": "B-AM-LOC",
45
+ "34": "B-C-A1",
46
+ "35": "I-AM-MNR",
47
+ "36": "B-A3",
48
+ "37": "B-A0",
49
+ "38": "B-C-A0",
50
+ "39": "I-AM-DIS",
51
+ "4": "B-C-AM-NEG",
52
+ "40": "I-AM-LOC",
53
+ "41": "B-AM-MNR",
54
+ "42": "I-AM-PRD",
55
+ "43": "B-C-AM-DIS",
56
+ "44": "B-C-AM-PRD",
57
+ "45": "I-AM-NEG",
58
+ "46": "B-AM-DIR",
59
+ "47": "B-C-V",
60
+ "48": "B-AM-DIS",
61
+ "49": "B-C-AM-CAU",
62
+ "5": "B-C-AM-TMP",
63
+ "50": "I-C-A0",
64
+ "51": "B-AM-NEG",
65
+ "52": "B-C-AM-EXT",
66
+ "53": "I-AM-DIR",
67
+ "54": "I-A0",
68
+ "55": "I-C-V",
69
+ "56": "B-V",
70
+ "57": "I-AM-EXT",
71
+ "58": "B-AM-TMP",
72
+ "59": "I-AM-ADV",
73
+ "6": "I-A4",
74
+ "60": "I-AM-TMP",
75
+ "7": "I-C-A3",
76
+ "8": "I-C-A1",
77
+ "9": "B-A2"
78
+ },
79
+ "label2id": {
80
+ "B-A0": 37,
81
+ "B-A1": 26,
82
+ "B-A2": 9,
83
+ "B-A3": 36,
84
+ "B-A4": 31,
85
+ "B-AM-ADV": 25,
86
+ "B-AM-CAU": 2,
87
+ "B-AM-DIR": 46,
88
+ "B-AM-DIS": 48,
89
+ "B-AM-EXT": 14,
90
+ "B-AM-LOC": 33,
91
+ "B-AM-MNR": 41,
92
+ "B-AM-NEG": 51,
93
+ "B-AM-PNC": 20,
94
+ "B-AM-PRD": 13,
95
+ "B-AM-REC": 23,
96
+ "B-AM-TMP": 58,
97
+ "B-C-A0": 38,
98
+ "B-C-A1": 34,
99
+ "B-C-A2": 24,
100
+ "B-C-A3": 32,
101
+ "B-C-AM-ADV": 22,
102
+ "B-C-AM-CAU": 49,
103
+ "B-C-AM-DIS": 43,
104
+ "B-C-AM-EXT": 52,
105
+ "B-C-AM-LOC": 12,
106
+ "B-C-AM-MNR": 19,
107
+ "B-C-AM-NEG": 4,
108
+ "B-C-AM-PRD": 44,
109
+ "B-C-AM-TMP": 5,
110
+ "B-C-V": 47,
111
+ "B-V": 56,
112
+ "I-A0": 54,
113
+ "I-A1": 30,
114
+ "I-A2": 21,
115
+ "I-A3": 28,
116
+ "I-A4": 6,
117
+ "I-AM-ADV": 59,
118
+ "I-AM-CAU": 3,
119
+ "I-AM-DIR": 53,
120
+ "I-AM-DIS": 39,
121
+ "I-AM-EXT": 57,
122
+ "I-AM-LOC": 40,
123
+ "I-AM-MNR": 35,
124
+ "I-AM-NEG": 45,
125
+ "I-AM-PNC": 16,
126
+ "I-AM-PRD": 42,
127
+ "I-AM-TMP": 60,
128
+ "I-C-A0": 50,
129
+ "I-C-A1": 8,
130
+ "I-C-A2": 18,
131
+ "I-C-A3": 7,
132
+ "I-C-AM-ADV": 29,
133
+ "I-C-AM-CAU": 17,
134
+ "I-C-AM-LOC": 15,
135
+ "I-C-AM-MNR": 27,
136
+ "I-C-AM-PRD": 10,
137
+ "I-C-AM-TMP": 11,
138
+ "I-C-V": 55,
139
+ "O": 0,
140
+ "[UNK]": 1
141
+ },
142
+ "model_type": "srl",
143
+ "num_labels": 61,
144
+ "torch_dtype": "float32",
145
+ "transformers_version": "4.39.3"
146
+ }
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:ed69dae877e6013b39aa4d708aa65c14dc0cd0b8202b63573df7318a8aae5da1
3
+ size 435905116