tburst commited on
Commit
0868718
1 Parent(s): 4f4aadc

Upload model

Browse files
config.json ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "xlm-roberta-large",
3
+ "architectures": [
4
+ "CustomXLMRobertaModelForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "auto_map": {
8
+ "AutoModelForSequenceClassification": "modeling_custom_head_xlm_roberta.CustomXLMRobertaModelForSequenceClassification"
9
+ },
10
+ "bos_token_id": 0,
11
+ "classifier_dropout": 0.1,
12
+ "eos_token_id": 2,
13
+ "hidden_act": "gelu",
14
+ "hidden_dropout_prob": 0.1,
15
+ "hidden_size": 1024,
16
+ "id2label": {
17
+ "0": "LABEL_0",
18
+ "1": "LABEL_1",
19
+ "2": "LABEL_2",
20
+ "3": "LABEL_3",
21
+ "4": "LABEL_4",
22
+ "5": "LABEL_5",
23
+ "6": "LABEL_6",
24
+ "7": "LABEL_7",
25
+ "8": "LABEL_8",
26
+ "9": "LABEL_9",
27
+ "10": "LABEL_10",
28
+ "11": "LABEL_11",
29
+ "12": "LABEL_12",
30
+ "13": "LABEL_13",
31
+ "14": "LABEL_14",
32
+ "15": "LABEL_15",
33
+ "16": "LABEL_16",
34
+ "17": "LABEL_17",
35
+ "18": "LABEL_18",
36
+ "19": "LABEL_19",
37
+ "20": "LABEL_20",
38
+ "21": "LABEL_21",
39
+ "22": "LABEL_22",
40
+ "23": "LABEL_23",
41
+ "24": "LABEL_24",
42
+ "25": "LABEL_25",
43
+ "26": "LABEL_26",
44
+ "27": "LABEL_27",
45
+ "28": "LABEL_28",
46
+ "29": "LABEL_29",
47
+ "30": "LABEL_30",
48
+ "31": "LABEL_31",
49
+ "32": "LABEL_32",
50
+ "33": "LABEL_33",
51
+ "34": "LABEL_34",
52
+ "35": "LABEL_35",
53
+ "36": "LABEL_36",
54
+ "37": "LABEL_37",
55
+ "38": "LABEL_38",
56
+ "39": "LABEL_39",
57
+ "40": "LABEL_40",
58
+ "41": "LABEL_41",
59
+ "42": "LABEL_42",
60
+ "43": "LABEL_43",
61
+ "44": "LABEL_44",
62
+ "45": "LABEL_45",
63
+ "46": "LABEL_46",
64
+ "47": "LABEL_47",
65
+ "48": "LABEL_48",
66
+ "49": "LABEL_49",
67
+ "50": "LABEL_50",
68
+ "51": "LABEL_51",
69
+ "52": "LABEL_52",
70
+ "53": "LABEL_53",
71
+ "54": "LABEL_54",
72
+ "55": "LABEL_55"
73
+ },
74
+ "initializer_range": 0.02,
75
+ "intermediate_size": 4096,
76
+ "label2id": {
77
+ "LABEL_0": 0,
78
+ "LABEL_1": 1,
79
+ "LABEL_10": 10,
80
+ "LABEL_11": 11,
81
+ "LABEL_12": 12,
82
+ "LABEL_13": 13,
83
+ "LABEL_14": 14,
84
+ "LABEL_15": 15,
85
+ "LABEL_16": 16,
86
+ "LABEL_17": 17,
87
+ "LABEL_18": 18,
88
+ "LABEL_19": 19,
89
+ "LABEL_2": 2,
90
+ "LABEL_20": 20,
91
+ "LABEL_21": 21,
92
+ "LABEL_22": 22,
93
+ "LABEL_23": 23,
94
+ "LABEL_24": 24,
95
+ "LABEL_25": 25,
96
+ "LABEL_26": 26,
97
+ "LABEL_27": 27,
98
+ "LABEL_28": 28,
99
+ "LABEL_29": 29,
100
+ "LABEL_3": 3,
101
+ "LABEL_30": 30,
102
+ "LABEL_31": 31,
103
+ "LABEL_32": 32,
104
+ "LABEL_33": 33,
105
+ "LABEL_34": 34,
106
+ "LABEL_35": 35,
107
+ "LABEL_36": 36,
108
+ "LABEL_37": 37,
109
+ "LABEL_38": 38,
110
+ "LABEL_39": 39,
111
+ "LABEL_4": 4,
112
+ "LABEL_40": 40,
113
+ "LABEL_41": 41,
114
+ "LABEL_42": 42,
115
+ "LABEL_43": 43,
116
+ "LABEL_44": 44,
117
+ "LABEL_45": 45,
118
+ "LABEL_46": 46,
119
+ "LABEL_47": 47,
120
+ "LABEL_48": 48,
121
+ "LABEL_49": 49,
122
+ "LABEL_5": 5,
123
+ "LABEL_50": 50,
124
+ "LABEL_51": 51,
125
+ "LABEL_52": 52,
126
+ "LABEL_53": 53,
127
+ "LABEL_54": 54,
128
+ "LABEL_55": 55,
129
+ "LABEL_6": 6,
130
+ "LABEL_7": 7,
131
+ "LABEL_8": 8,
132
+ "LABEL_9": 9
133
+ },
134
+ "layer_norm_eps": 1e-05,
135
+ "max_position_embeddings": 514,
136
+ "model_type": "xlm-roberta",
137
+ "num_attention_heads": 16,
138
+ "num_hidden_layers": 24,
139
+ "output_past": true,
140
+ "pad_token_id": 1,
141
+ "position_embedding_type": "absolute",
142
+ "problem_type": "single_label_classification",
143
+ "torch_dtype": "float32",
144
+ "transformers_version": "4.33.2",
145
+ "type_vocab_size": 1,
146
+ "use_cache": true,
147
+ "vocab_size": 250002
148
+ }
modeling_custom_head_xlm_roberta.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from torch.nn import Linear
4
+ from transformers import XLMRobertaForSequenceClassification, XLMRobertaConfig
5
+ from transformers.modeling_outputs import SequenceClassifierOutput
6
+ from torch.nn import MSELoss, CrossEntropyLoss, BCEWithLogitsLoss
7
+
8
+ from typing import Optional, Union, Tuple
9
+
10
+
11
+ class CustomXLMRobertaModelForSequenceClassification(XLMRobertaForSequenceClassification):
12
+ config_class = XLMRobertaConfig
13
+
14
+ def __init__(self, config):
15
+ super().__init__(config)
16
+
17
+ self.final_classifier = Linear(config.hidden_size, config.num_labels)
18
+ self.init_weights()
19
+
20
+ def forward(
21
+ self,
22
+ input_ids: Optional[torch.LongTensor] = None,
23
+ attention_mask: Optional[torch.FloatTensor] = None,
24
+ token_type_ids: Optional[torch.LongTensor] = None,
25
+ position_ids: Optional[torch.LongTensor] = None,
26
+ head_mask: Optional[torch.FloatTensor] = None,
27
+ inputs_embeds: Optional[torch.FloatTensor] = None,
28
+ labels: Optional[torch.LongTensor] = None,
29
+ output_attentions: Optional[bool] = None,
30
+ output_hidden_states: Optional[bool] = None,
31
+ return_dict: Optional[bool] = None,
32
+ ) -> Union[Tuple[torch.Tensor], SequenceClassifierOutput]:
33
+
34
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
35
+ outputs_sentence = self.roberta(input_ids,
36
+ attention_mask=attention_mask,
37
+ token_type_ids=token_type_ids,
38
+ position_ids=position_ids,
39
+ head_mask=head_mask,
40
+ inputs_embeds=inputs_embeds,
41
+ output_attentions=output_attentions,
42
+ output_hidden_states=output_hidden_states,
43
+ return_dict=True)
44
+
45
+ sequence_output_sentence = outputs_sentence["last_hidden_state"][:, 0, :]
46
+
47
+ logits = self.final_classifier(sequence_output_sentence)
48
+
49
+ loss = None
50
+ if labels is not None:
51
+ if self.config.problem_type is None:
52
+ if self.num_labels == 1:
53
+ self.config.problem_type = "regression"
54
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
55
+ self.config.problem_type = "single_label_classification"
56
+ else:
57
+ self.config.problem_type = "multi_label_classification"
58
+
59
+ if self.config.problem_type == "regression":
60
+ loss_fct = MSELoss()
61
+ if self.num_labels == 1:
62
+ loss = loss_fct(logits.squeeze(), labels.squeeze())
63
+ else:
64
+ loss = loss_fct(logits, labels)
65
+ elif self.config.problem_type == "single_label_classification":
66
+ loss_fct = CrossEntropyLoss()
67
+ loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
68
+ elif self.config.problem_type == "multi_label_classification":
69
+ loss_fct = BCEWithLogitsLoss()
70
+ loss = loss_fct(logits, labels)
71
+
72
+ if not return_dict:
73
+ output = (logits,)
74
+ return ((loss,) + output) if loss is not None else output
75
+
76
+ return SequenceClassifierOutput(
77
+ loss=loss,
78
+ logits=logits
79
+ )
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:388e5bc3d088bb84bd214e7ce1b616a04b77a4a11e34fd3d1c39b81ccfefcdac
3
+ size 2240151609