Upload BertItaliano
Browse files- config.json +27 -0
- configuration_moral.py +46 -0
- modeling_moral.py +24 -0
- pytorch_model.bin +3 -0
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertItaliano"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_moral.BertItalianoConfig",
|
8 |
+
"AutoModel": "modeling_moral.BertItaliano"
|
9 |
+
},
|
10 |
+
"gradient_checkpointing": false,
|
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-12,
|
17 |
+
"max_position_embeddings": 512,
|
18 |
+
"model_type": "BertItaliano",
|
19 |
+
"num_attention_heads": 12,
|
20 |
+
"num_hidden_layers": 12,
|
21 |
+
"position_embedding_type": "absolute",
|
22 |
+
"torch_dtype": "float32",
|
23 |
+
"transformers_version": "4.33.2",
|
24 |
+
"type_vocab_size": 2,
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 32102
|
27 |
+
}
|
configuration_moral.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig
|
2 |
+
|
3 |
+
class BertItalianoConfig(PretrainedConfig):
|
4 |
+
model_type="BertItaliano"
|
5 |
+
|
6 |
+
def __init__(
|
7 |
+
self,
|
8 |
+
attention_probs_dropout_prob: float = 0.1,
|
9 |
+
gradient_checkpointing: bool = False,
|
10 |
+
hidden_act="gelu",
|
11 |
+
hidden_dropout_prob: float = 0.1,
|
12 |
+
hidden_size: int = 768,
|
13 |
+
initializer_range: float = 0.02,
|
14 |
+
intermediate_size: int = 3072,
|
15 |
+
layer_norm_eps: float = 1e-12,
|
16 |
+
max_position_embeddings: int = 512,
|
17 |
+
num_attention_heads: int = 12,
|
18 |
+
num_hidden_layers: int = 12,
|
19 |
+
pad_token_id: int = 0,
|
20 |
+
position_embedding_type="absolute",
|
21 |
+
transformers_version="4.10.3",
|
22 |
+
torch_dtype="float32",
|
23 |
+
type_vocab_size: int = 2,
|
24 |
+
use_cache: bool = True,
|
25 |
+
vocab_size: int = 32102,
|
26 |
+
**kwargs,
|
27 |
+
):
|
28 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
29 |
+
self.gradient_checkpointing = gradient_checkpointing
|
30 |
+
self.hidden_act = hidden_act
|
31 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
32 |
+
self.hidden_size = hidden_size
|
33 |
+
self.initializer_range = initializer_range
|
34 |
+
self.intermediate_size = intermediate_size
|
35 |
+
self.layer_norm_eps = layer_norm_eps
|
36 |
+
self.max_position_embeddings = max_position_embeddings
|
37 |
+
self.num_attention_heads = num_attention_heads
|
38 |
+
self.num_hidden_layers = num_hidden_layers
|
39 |
+
self.pad_token_id = pad_token_id
|
40 |
+
self.position_embedding_type = position_embedding_type
|
41 |
+
self.transformers_version = transformers_version
|
42 |
+
self.torch_dtype = torch_dtype
|
43 |
+
self.type_vocab_size = type_vocab_size
|
44 |
+
self.use_cache = use_cache
|
45 |
+
self.vocab_size = vocab_size
|
46 |
+
super().__init__(**kwargs)
|
modeling_moral.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PreTrainedModel, AutoModel
|
2 |
+
from .configuration_moral import BertItalianoConfig
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class BertItaliano(PreTrainedModel):
|
6 |
+
config_class = BertItalianoConfig
|
7 |
+
|
8 |
+
def __init__(self, config, num_labels_1=6, num_labels_2=3):
|
9 |
+
super(BertItaliano, self).__init__(config)
|
10 |
+
self.num_labels1 = num_labels_1
|
11 |
+
self.num_labels2 = num_labels_2
|
12 |
+
self.bert = AutoModel.from_pretrained("dbmdz/bert-base-italian-xxl-uncased")
|
13 |
+
self.dropout = torch.nn.Dropout(0.3)
|
14 |
+
self.linear_1 = torch.nn.Linear(config.hidden_size, num_labels_1)
|
15 |
+
self.linear_2 = torch.nn.Linear(config.hidden_size, num_labels_2)
|
16 |
+
|
17 |
+
def forward(self, input_ids, attention_mask=None, token_type_ids=None):
|
18 |
+
outputs = self.bert(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
|
19 |
+
pooled_output = outputs[1]
|
20 |
+
pooled_output = self.dropout(pooled_output)
|
21 |
+
logits_1 = self.linear_1(pooled_output)
|
22 |
+
logits_2 = self.linear_2(pooled_output)
|
23 |
+
|
24 |
+
return logits_1, logits_2
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4a5196b67f9b5af7a439315d733e6ae306f158519657f2c7263aa0dc4b39ebe4
|
3 |
+
size 442874731
|