Upload model
Browse files- config.json +148 -0
- modeling_custom_head_xlm_roberta.py +76 -0
- pytorch_model.bin +3 -0
config.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "C:/Users/algaddooa/ownCloud - [email protected]@owncloud.gwdg.de/MARPOR/manifestoberta/manifestoberta-xlm-roberta-56policy-topics-sentence-2024-1-1",
|
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": null,
|
12 |
+
"eos_token_id": 2,
|
13 |
+
"hidden_act": "gelu",
|
14 |
+
"hidden_dropout_prob": 0.1,
|
15 |
+
"hidden_size": 1024,
|
16 |
+
"id2label": {
|
17 |
+
"0": "101 - Foreign Special Relationships: Positive",
|
18 |
+
"1": "102 - Foreign Special Relationships: Negative",
|
19 |
+
"2": "103 - Anti-Imperialism",
|
20 |
+
"3": "104 - Military: Positive",
|
21 |
+
"4": "105 - Military: Negative",
|
22 |
+
"5": "106 - Peace",
|
23 |
+
"6": "107 - Internationalism: Positive",
|
24 |
+
"7": "108 - European Community/Union: Positive",
|
25 |
+
"8": "109 - Internationalism: Negative",
|
26 |
+
"9": "110 - European Community/Union: Negative",
|
27 |
+
"10": "201 - Freedom and Human Rights",
|
28 |
+
"11": "202 - Democracy",
|
29 |
+
"12": "203 - Constitutionalism: Positive",
|
30 |
+
"13": "204 - Constitutionalism: Negative",
|
31 |
+
"14": "301 - Federalism",
|
32 |
+
"15": "302 - Centralisation",
|
33 |
+
"16": "303 - Governmental and Administrative Efficiency",
|
34 |
+
"17": "304 - Political Corruption",
|
35 |
+
"18": "305 - Political Authority",
|
36 |
+
"19": "401 - Free Market Economy",
|
37 |
+
"20": "402 - Incentives",
|
38 |
+
"21": "403 - Market Regulation",
|
39 |
+
"22": "404 - Economic Planning",
|
40 |
+
"23": "405 - Corporatism/ Mixed Economy",
|
41 |
+
"24": "406 - Protectionism: Positive",
|
42 |
+
"25": "407 - Protectionism: Negative",
|
43 |
+
"26": "408 - Economic Goals",
|
44 |
+
"27": "409 - Keynesian Demand Management",
|
45 |
+
"28": "410 - Economic Growth: Positive",
|
46 |
+
"29": "411 - Technology and Infrastructure",
|
47 |
+
"30": "412 - Controlled Economy",
|
48 |
+
"31": "413 - Nationalisation",
|
49 |
+
"32": "414 - Economic Orthodoxy",
|
50 |
+
"33": "415 - Marxist Analysis: Positive",
|
51 |
+
"34": "416 - Anti-Growth Economy: Positive",
|
52 |
+
"35": "501 - Environmental Protection: Positive",
|
53 |
+
"36": "502 - Culture: Positive",
|
54 |
+
"37": "503 - Equality: Positive",
|
55 |
+
"38": "504 - Welfare State Expansion",
|
56 |
+
"39": "505 - Welfare State Limitation",
|
57 |
+
"40": "506 - Education Expansion",
|
58 |
+
"41": "507 - Education Limitation",
|
59 |
+
"42": "601 - National Way of Life: Positive",
|
60 |
+
"43": "602 - National Way of Life: Negative",
|
61 |
+
"44": "603 - Traditional Morality: Positive",
|
62 |
+
"45": "604 - Traditional Morality: Negative",
|
63 |
+
"46": "605 - Law and Order: Positive",
|
64 |
+
"47": "606 - Civic Mindedness: Positive",
|
65 |
+
"48": "607 - Multiculturalism: Positive",
|
66 |
+
"49": "608 - Multiculturalism: Negative",
|
67 |
+
"50": "701 - Labour Groups: Positive",
|
68 |
+
"51": "702 - Labour Groups: Negative",
|
69 |
+
"52": "703 - Agriculture and Farmers: Positive",
|
70 |
+
"53": "704 - Middle Class and Professional Groups",
|
71 |
+
"54": "705 - Underprivileged Minority Groups",
|
72 |
+
"55": "706 - Non-economic Demographic Groups"
|
73 |
+
},
|
74 |
+
"initializer_range": 0.02,
|
75 |
+
"intermediate_size": 4096,
|
76 |
+
"label2id": {
|
77 |
+
"101 - Foreign Special Relationships: Positive": 0,
|
78 |
+
"102 - Foreign Special Relationships: Negative": 1,
|
79 |
+
"103 - Anti-Imperialism": 2,
|
80 |
+
"104 - Military: Positive": 3,
|
81 |
+
"105 - Military: Negative": 4,
|
82 |
+
"106 - Peace": 5,
|
83 |
+
"107 - Internationalism: Positive": 6,
|
84 |
+
"108 - European Community/Union: Positive": 7,
|
85 |
+
"109 - Internationalism: Negative": 8,
|
86 |
+
"110 - European Community/Union: Negative": 9,
|
87 |
+
"201 - Freedom and Human Rights": 10,
|
88 |
+
"202 - Democracy": 11,
|
89 |
+
"203 - Constitutionalism: Positive": 12,
|
90 |
+
"204 - Constitutionalism: Negative": 13,
|
91 |
+
"301 - Federalism": 14,
|
92 |
+
"302 - Centralisation": 15,
|
93 |
+
"303 - Governmental and Administrative Efficiency": 16,
|
94 |
+
"304 - Political Corruption": 17,
|
95 |
+
"305 - Political Authority": 18,
|
96 |
+
"401 - Free Market Economy": 19,
|
97 |
+
"402 - Incentives": 20,
|
98 |
+
"403 - Market Regulation": 21,
|
99 |
+
"404 - Economic Planning": 22,
|
100 |
+
"405 - Corporatism/ Mixed Economy": 23,
|
101 |
+
"406 - Protectionism: Positive": 24,
|
102 |
+
"407 - Protectionism: Negative": 25,
|
103 |
+
"408 - Economic Goals": 26,
|
104 |
+
"409 - Keynesian Demand Management": 27,
|
105 |
+
"410 - Economic Growth: Positive": 28,
|
106 |
+
"411 - Technology and Infrastructure": 29,
|
107 |
+
"412 - Controlled Economy": 30,
|
108 |
+
"413 - Nationalisation": 31,
|
109 |
+
"414 - Economic Orthodoxy": 32,
|
110 |
+
"415 - Marxist Analysis: Positive": 33,
|
111 |
+
"416 - Anti-Growth Economy: Positive": 34,
|
112 |
+
"501 - Environmental Protection: Positive": 35,
|
113 |
+
"502 - Culture: Positive": 36,
|
114 |
+
"503 - Equality: Positive": 37,
|
115 |
+
"504 - Welfare State Expansion": 38,
|
116 |
+
"505 - Welfare State Limitation": 39,
|
117 |
+
"506 - Education Expansion": 40,
|
118 |
+
"507 - Education Limitation": 41,
|
119 |
+
"601 - National Way of Life: Positive": 42,
|
120 |
+
"602 - National Way of Life: Negative": 43,
|
121 |
+
"603 - Traditional Morality: Positive": 44,
|
122 |
+
"604 - Traditional Morality: Negative": 45,
|
123 |
+
"605 - Law and Order: Positive": 46,
|
124 |
+
"606 - Civic Mindedness: Positive": 47,
|
125 |
+
"607 - Multiculturalism: Positive": 48,
|
126 |
+
"608 - Multiculturalism: Negative": 49,
|
127 |
+
"701 - Labour Groups: Positive": 50,
|
128 |
+
"702 - Labour Groups: Negative": 51,
|
129 |
+
"703 - Agriculture and Farmers: Positive": 52,
|
130 |
+
"704 - Middle Class and Professional Groups": 53,
|
131 |
+
"705 - Underprivileged Minority Groups": 54,
|
132 |
+
"706 - Non-economic Demographic Groups": 55
|
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.24.0",
|
145 |
+
"type_vocab_size": 1,
|
146 |
+
"use_cache": true,
|
147 |
+
"vocab_size": 250002
|
148 |
+
}
|
modeling_custom_head_xlm_roberta.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import XLMRobertaForSequenceClassification, XLMRobertaConfig
|
2 |
+
from torch.nn import MSELoss, CrossEntropyLoss, BCEWithLogitsLoss
|
3 |
+
from typing import Optional, Union, Tuple
|
4 |
+
from transformers.modeling_outputs import SequenceClassifierOutput
|
5 |
+
import torch
|
6 |
+
from torch.nn import Linear
|
7 |
+
|
8 |
+
class CustomXLMRobertaModelForSequenceClassification(XLMRobertaForSequenceClassification):
|
9 |
+
config_class = XLMRobertaConfig
|
10 |
+
|
11 |
+
def __init__(self, config):
|
12 |
+
super().__init__(config)
|
13 |
+
|
14 |
+
self.final_classifier = Linear(config.hidden_size, config.num_labels)
|
15 |
+
self.init_weights()
|
16 |
+
|
17 |
+
def forward(
|
18 |
+
self,
|
19 |
+
input_ids: Optional[torch.LongTensor] = None,
|
20 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
21 |
+
token_type_ids: Optional[torch.LongTensor] = None,
|
22 |
+
position_ids: Optional[torch.LongTensor] = None,
|
23 |
+
head_mask: Optional[torch.FloatTensor] = None,
|
24 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
25 |
+
labels: Optional[torch.LongTensor] = None,
|
26 |
+
output_attentions: Optional[bool] = None,
|
27 |
+
output_hidden_states: Optional[bool] = None,
|
28 |
+
return_dict: Optional[bool] = None,
|
29 |
+
) -> Union[Tuple[torch.Tensor], SequenceClassifierOutput]:
|
30 |
+
|
31 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
32 |
+
outputs_sentence = self.roberta(input_ids,
|
33 |
+
attention_mask=attention_mask,
|
34 |
+
token_type_ids=token_type_ids,
|
35 |
+
position_ids=position_ids,
|
36 |
+
head_mask=head_mask,
|
37 |
+
inputs_embeds=inputs_embeds,
|
38 |
+
output_attentions=output_attentions,
|
39 |
+
output_hidden_states=output_hidden_states,
|
40 |
+
return_dict=True)
|
41 |
+
|
42 |
+
sequence_output_sentence = outputs_sentence["last_hidden_state"][:, 0, :]
|
43 |
+
|
44 |
+
logits = self.final_classifier(sequence_output_sentence)
|
45 |
+
|
46 |
+
loss = None
|
47 |
+
if labels is not None:
|
48 |
+
if self.config.problem_type is None:
|
49 |
+
if self.num_labels == 1:
|
50 |
+
self.config.problem_type = "regression"
|
51 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
52 |
+
self.config.problem_type = "single_label_classification"
|
53 |
+
else:
|
54 |
+
self.config.problem_type = "multi_label_classification"
|
55 |
+
|
56 |
+
if self.config.problem_type == "regression":
|
57 |
+
loss_fct = MSELoss()
|
58 |
+
if self.num_labels == 1:
|
59 |
+
loss = loss_fct(logits.squeeze(), labels.squeeze())
|
60 |
+
else:
|
61 |
+
loss = loss_fct(logits, labels)
|
62 |
+
elif self.config.problem_type == "single_label_classification":
|
63 |
+
loss_fct = CrossEntropyLoss()
|
64 |
+
loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
|
65 |
+
elif self.config.problem_type == "multi_label_classification":
|
66 |
+
loss_fct = BCEWithLogitsLoss()
|
67 |
+
loss = loss_fct(logits, labels)
|
68 |
+
|
69 |
+
if not return_dict:
|
70 |
+
output = (logits,)
|
71 |
+
return ((loss,) + output) if loss is not None else output
|
72 |
+
|
73 |
+
return SequenceClassifierOutput(
|
74 |
+
loss=loss,
|
75 |
+
logits=logits
|
76 |
+
)
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:60d688198b405592c70a05b16d01d82e31c8283618419a3e4a86a21d6153e7a1
|
3 |
+
size 2240156029
|