MariaOls commited on
Commit
434d57d
·
verified ·
1 Parent(s): 42ff5a4

Train & push dual-head DM (final model only) + README

Browse files
README.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MariaOls/RussianDMRecognizer_dual
2
+
3
+ Dual-headed model (BIO token tagging + sentence-level DM detection) fine-tuned from **viktoroo/sberbank-rubert-base-collection3**.
4
+ Ready for inference with `AutoModel(..., trust_remote_code=True)` or your `probar.py` (sentence by sentence).
5
+
6
+ ## Eval metrics
7
+ | metric | value |
8
+ |---|---|
9
+ | eval_bio_accuracy | 0.993706 |
10
+ | eval_bio_precision | 0.925270 |
11
+ | eval_bio_recall | 0.936318 |
12
+ | eval_bio_f1 | 0.930762 |
13
+ | eval_cls_accuracy | 0.951408 |
14
+ | eval_cls_precision | 0.966135 |
15
+ | eval_cls_recall | 0.965174 |
16
+ | eval_cls_f1 | 0.965655 |
17
+
18
+
19
+ ## Usage (Python)
20
+ ```python
21
+ from transformers import AutoModel, AutoTokenizer
22
+ m = AutoModel.from_pretrained("MariaOls/RussianDMRecognizer_dual", trust_remote_code=True)
23
+ t = AutoTokenizer.from_pretrained("MariaOls/RussianDMRecognizer_dual", use_fast=True)
24
+ # m(...) devuelve dict con "logits": (logits_tok [B,L,3], logits_seq [B,2])
config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "viktoroo/sberbank-rubert-base-collection3",
3
+ "architectures": [
4
+ "DualHeadDMModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "auto_map": {
8
+ "AutoModel": "modeling_dual_head_dm.DualHeadDMModel"
9
+ },
10
+ "classifier_dropout": null,
11
+ "directionality": "bidi",
12
+ "hidden_act": "gelu",
13
+ "hidden_dropout_prob": 0.1,
14
+ "hidden_size": 768,
15
+ "id2label": {
16
+ "0": "O",
17
+ "1": "B-DM",
18
+ "2": "I-DM"
19
+ },
20
+ "initializer_range": 0.02,
21
+ "intermediate_size": 3072,
22
+ "label2id": {
23
+ "B-DM": 1,
24
+ "I-DM": 2,
25
+ "O": 0
26
+ },
27
+ "layer_norm_eps": 1e-12,
28
+ "max_position_embeddings": 512,
29
+ "model_type": "bert",
30
+ "num_attention_heads": 12,
31
+ "num_hidden_layers": 12,
32
+ "pad_token_id": 0,
33
+ "pooler_fc_size": 768,
34
+ "pooler_num_attention_heads": 12,
35
+ "pooler_num_fc_layers": 3,
36
+ "pooler_size_per_head": 128,
37
+ "pooler_type": "first_token_transform",
38
+ "position_embedding_type": "absolute",
39
+ "torch_dtype": "float32",
40
+ "transformers_version": "4.49.0",
41
+ "type_vocab_size": 2,
42
+ "use_cache": true,
43
+ "vocab_size": 120138
44
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3eccb37ffcf391416393720edaabfd8b15d2b30846991435712284d296e47d2
3
+ size 713269028
modeling_dual_head_dm.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch, torch.nn as nn
3
+ from transformers import PreTrainedModel, BertModel, BertConfig
4
+
5
+ class DualHeadDMModel(PreTrainedModel):
6
+ config_class = BertConfig
7
+ base_model_prefix = "encoder"
8
+
9
+ def __init__(self, config, num_token_labels=3, num_seq_labels=2, seq_loss_weight=0.5):
10
+ super().__init__(config)
11
+ if not isinstance(config, BertConfig):
12
+ config = BertConfig.from_dict(config.to_dict())
13
+ self.hidden_size = config.hidden_size
14
+ self.encoder = BertModel(config)
15
+ self.dropout = nn.Dropout(0.1)
16
+ self.token_classifier = nn.Linear(self.hidden_size, num_token_labels)
17
+ self.seq_classifier = nn.Linear(self.hidden_size, num_seq_labels)
18
+
19
+ def forward(self, input_ids=None, attention_mask=None, candidate_mask=None, **kwargs):
20
+ out = self.encoder(input_ids=input_ids, attention_mask=attention_mask, return_dict=True)
21
+ H = self.dropout(out.last_hidden_state)
22
+ logits_tok = self.token_classifier(H)
23
+ cls = H[:, 0, :]
24
+ logits_seq = self.seq_classifier(self.dropout(cls))
25
+ return {"logits": (logits_tok, logits_seq)}
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff