guilhermedallm4 commited on
Commit
d9de3fb
·
verified ·
1 Parent(s): 9e1ee2b

HubParser-Base-L: parser completo (UPOS, LEMMA, FEATS, HEAD, DEPREL) no Porttinari

Browse files
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: neuralmind/bert-base-portuguese-cased
3
+ language: pt
4
+ library_name: transformers
5
+ license: mit
6
+ pipeline_tag: token-classification
7
+ tags:
8
+ - dependency-parsing
9
+ - universal-dependencies
10
+ - pos-tagging
11
+ - lemmatization
12
+ - morphological-tagging
13
+ - porttinari
14
+ - hubparser
15
+ model-index:
16
+ - name: HubParser-Base-L
17
+ results:
18
+ - task:
19
+ type: token-classification
20
+ name: Dependency parsing (UD)
21
+ dataset:
22
+ name: Porttinari-base (test)
23
+ type: porttinari
24
+ split: test
25
+ metrics:
26
+ - {type: accuracy, value: 99.20, name: UPOS accuracy, verified: false}
27
+ - {type: accuracy, value: 98.96, name: LEMMA accuracy, verified: false}
28
+ - {type: accuracy, value: 98.90, name: FEATS accuracy, verified: false}
29
+ - {type: uas, value: 94.18, name: UAS (Eisner), verified: false}
30
+ - {type: las, value: 92.77, name: LAS (Eisner), verified: false}
31
+ ---
32
+
33
+ # HubParser-Base-L
34
+
35
+ **HubParser-Base-L** é o HubParser com encoder **BERTimbau Base** e cabeçote **Linear** (L = Linear).
36
+ É um parser completo de Universal Dependencies para o português brasileiro: a partir de frases já tokenizadas,
37
+ ele prediz em conjunto **UPOS**, **LEMMA**, **FEATS**, **HEAD** e **DEPREL**. Foi treinado no corpus
38
+ **Porttinari-base** e faz parte da dissertação de mestrado *HubParser* (Guilherme Dallman Lima, PPGC/UFPel, 2026).
39
+
40
+ | | |
41
+ |---|---|
42
+ | Encoder | [BERTimbau Base](https://huggingface.co/neuralmind/bert-base-portuguese-cased) (110 M parâmetros, 12 camadas) |
43
+ | Cabeçote | **Linear**: cinco classificadores lineares por subtoken (UPOS, LEMMA, FEATS, DEPREL e HEAD). HEAD é uma classificação sobre a posição absoluta da palavra-pai (0 = raiz, 1..199 = índice da palavra). |
44
+ | LEMMA | classificação sobre 252 regras de edição (caixa · caracteres cortados do fim · sufixo acrescentado) |
45
+ | FEATS | classificação sobre 174 conjuntos completos de traços morfológicos |
46
+ | Decodificação | gulosa, Eisner (árvore projetiva) ou MST/Chu-Liu-Edmonds (árvore não projetiva), escolhida na inferência |
47
+
48
+ ### A família HubParser
49
+
50
+ O nome segue o padrão `HubParser-<encoder>-<cabeçote>`: **Base** ou **Large** é o tamanho do BERTimbau, e
51
+ **L** (Linear) ou **B** (Biaffine) é o cabeçote de análise sintática. Os quatro modelos foram treinados com o mesmo
52
+ protocolo. Resultados no teste (decodificação Eisner; MLAS pela avaliação oficial CoNLL 2018 sobre a saída MST):
53
+
54
+ | Modelo | UPOS | LEMMA | FEATS | UAS | LAS | MLAS |
55
+ |---|---|---|---|---|---|---|
56
+ | [HubParser-Base-L](https://huggingface.co/guilhermedallm4/HubParser-Base-L) **(este modelo)** | 99.20 | 98.96 | 98.90 | 94.18 | 92.77 | 86.55 |
57
+ | [HubParser-Base-B](https://huggingface.co/guilhermedallm4/HubParser-Base-B) | 99.33 | 99.11 | 99.07 | 96.96 | 95.94 | 92.12 |
58
+ | [HubParser-Large-L](https://huggingface.co/guilhermedallm4/HubParser-Large-L) | 99.28 | 99.00 | 99.01 | 95.15 | 93.79 | 88.14 |
59
+ | [HubParser-Large-B](https://huggingface.co/guilhermedallm4/HubParser-Large-B) | 99.38 | 99.09 | 99.10 | 97.20 | 96.16 | 92.69 |
60
+
61
+ ## Resultados no teste do Porttinari
62
+
63
+ São 1.683 frases (33.580 palavras), com predição no primeiro subtoken de cada palavra e pontuação incluída.
64
+
65
+ | Decodificação | UPOS | LEMMA | FEATS | UAS | LAS |
66
+ |---|---|---|---|---|---|
67
+ | Gulosa | 99.20 | 98.96 | 98.90 | 92.76 | 91.41 |
68
+ | Eisner | 99.20 | 98.96 | 98.90 | 94.18 | 92.77 |
69
+ | MST | 99.20 | 98.96 | 98.90 | 93.34 | 91.95 |
70
+
71
+ UPOS, LEMMA e FEATS não dependem da decodificação. Avaliação oficial CoNLL 2018 (`conll18_ud_eval.py`) sobre a saída MST:
72
+ UFeats 98.95 · AllTags 98.57 · Lemmas 98.96 · UAS 93.34 · LAS 92.11 ·
73
+ CLAS 89.47 · MLAS 86.55 · BLEX 87.94.
74
+
75
+ ## Como usar
76
+
77
+ O modelo usa uma classe própria, então é preciso passar `trust_remote_code=True`.
78
+ A entrada é uma lista de frases **já tokenizadas em palavras**, como na coluna FORM do CoNLL-U.
79
+
80
+ ```python
81
+ from transformers import AutoModel, AutoTokenizer
82
+
83
+ repo = "guilhermedallm4/HubParser-Base-L"
84
+ tokenizer = AutoTokenizer.from_pretrained(repo)
85
+ model = AutoModel.from_pretrained(repo, trust_remote_code=True).eval() # .to("cuda") se houver GPU
86
+
87
+ sentences = [["O", "canal", "terá", "o", "conteúdo", "reformulado", "."]]
88
+ parsed = model.parse(sentences, tokenizer, decoding="eisner") # "greedy", "eisner" ou "mst"
89
+ print(model.to_conllu(parsed))
90
+ ```
91
+
92
+ Saída:
93
+
94
+ ```
95
+ 1 O o DET _ Definite=Def|Gender=Masc|Number=Sing|PronType=Art 2 det _ _
96
+ 2 canal canal NOUN _ Gender=Masc|Number=Sing 3 nsubj _ _
97
+ 3 terá ter VERB _ Mood=Ind|Number=Sing|Person=3|Tense=Fut|VerbForm=Fin 0 root _ _
98
+ 4 o o DET _ Definite=Def|Gender=Masc|Number=Sing|PronType=Art 5 det _ _
99
+ 5 conteúdo conteúdo NOUN _ Gender=Masc|Number=Sing 3 obj _ _
100
+ 6 reformulado reformular VERB _ Gender=Masc|Number=Sing|VerbForm=Part|Voice=Pass 3 xcomp _ _
101
+ 7 . . PUNCT _ _ 3 punct _ _
102
+ ```
103
+
104
+ Cada palavra vem como `{id, form, lemma, upos, feats, head, deprel}`, em que `head = 0` indica a raiz.
105
+ As listas de rótulos ficam em `model.config.upos_labels`, `deprel_labels`, `lemma_rules` e `feats_labels`.
106
+
107
+ ## Treinamento
108
+
109
+ - **Dados:** Porttinari-base (8.418 frases; split da dissertação). LEMMA e FEATS vêm do UD_Portuguese-Porttinari r2.18,
110
+ alinhado frase a frase. A busca usa treino + validação; o modelo final é treinado no treino.
111
+ - **Objetivo:** soma das entropias cruzadas das cinco saídas, com pesos iguais. Os rótulos de cada palavra são
112
+ replicados em todos os seus subtokens.
113
+ - **Busca de hiperparâmetros:** 10 configurações fixas × validação cruzada de 5 folds (40 épocas, batch 16,
114
+ early stopping com paciência 5). A seleção usa a média das acurácias de validação de UPOS, LEMMA, FEATS e LAS.
115
+ Foi escolhida a configuração 4: score médio 96.17 ± 0.19,
116
+ LAS médio 89.15 (validação por subtoken, decodificação gulosa).
117
+ - **Treino final:** learning rate `3.818e-05`, weight decay `0.1425`,
118
+ warmup ratio `0.3364`, 40 épocas, batch 8, padding 512, fp32, seed 42.
119
+ O modelo publicado é o do fim da época 40, sem seleção de checkpoint
120
+ (cerca de 46 min numa RTX 4090).
121
+ - **Código:** <https://github.com/guilhermedallm4/HubParser>
122
+
123
+ ## Limitações
124
+
125
+ - O modelo não tokeniza: espera palavras já segmentadas, com contrações expandidas como no Porttinari (por exemplo, "do" vira "de o").
126
+ - Na decodificação gulosa a saída pode não ser uma árvore (ciclos ou mais de uma raiz); Eisner e MST sempre devolvem uma árvore com uma única raiz.
127
+ - No cabeçote linear, HEAD só alcança posições até 199.
128
+ - O lema vem de uma regra de edição aplicada à forma; formas com regras raras ou não vistas no treino podem receber lemas errados.
129
+
130
+ ## Citação
131
+
132
+ ```bibtex
133
+ @mastersthesis{lima2026hubparser,
134
+ title = {HubParser: parsing de dependências multi-tarefa para o português
135
+ brasileiro com encoders BERT},
136
+ author = {Lima, Guilherme Dallman},
137
+ school = {Universidade Federal de Pelotas},
138
+ year = {2026}
139
+ }
140
+ ```
config.json ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "HubParserFullLinear"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "base_model": "neuralmind/bert-base-portuguese-cased",
8
+ "bos_token_id": null,
9
+ "classifier_dropout": null,
10
+ "deprel_labels": [
11
+ "det",
12
+ "nsubj",
13
+ "root",
14
+ "obj",
15
+ "xcomp",
16
+ "punct",
17
+ "mark",
18
+ "advcl",
19
+ "case",
20
+ "obl",
21
+ "amod",
22
+ "conj",
23
+ "cc",
24
+ "nmod",
25
+ "advmod",
26
+ "flat:name",
27
+ "ccomp",
28
+ "cop",
29
+ "acl",
30
+ "nummod",
31
+ "acl:relcl",
32
+ "ccomp:speech",
33
+ "parataxis",
34
+ "csubj",
35
+ "aux:pass",
36
+ "appos",
37
+ "fixed",
38
+ "nsubj:pass",
39
+ "aux",
40
+ "nsubj:outer",
41
+ "obl:agent",
42
+ "expl:impers",
43
+ "expl",
44
+ "discourse",
45
+ "orphan",
46
+ "dislocated",
47
+ "flat",
48
+ "flat:foreign",
49
+ "iobj",
50
+ "vocative",
51
+ "csubj:outer",
52
+ "list",
53
+ "reparandum",
54
+ "csubj:pass"
55
+ ],
56
+ "directionality": "bidi",
57
+ "dtype": "float32",
58
+ "eos_token_id": null,
59
+ "feats_labels": [
60
+ "_",
61
+ "Gender=Masc|Number=Sing",
62
+ "Gender=Fem|Number=Sing",
63
+ "Definite=Def|Gender=Masc|Number=Sing|PronType=Art",
64
+ "Definite=Def|Gender=Fem|Number=Sing|PronType=Art",
65
+ "Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin",
66
+ "Gender=Masc|Number=Plur",
67
+ "Gender=Fem|Number=Plur",
68
+ "VerbForm=Inf",
69
+ "Number=Sing",
70
+ "Mood=Ind|Number=Sing|Person=3|Tense=Past|VerbForm=Fin",
71
+ "NumType=Card",
72
+ "Definite=Def|Gender=Masc|Number=Plur|PronType=Art",
73
+ "PronType=Rel",
74
+ "Number=Plur",
75
+ "Definite=Def|Gender=Fem|Number=Plur|PronType=Art",
76
+ "Mood=Ind|Number=Plur|Person=3|Tense=Pres|VerbForm=Fin",
77
+ "Definite=Ind|Gender=Masc|Number=Sing|PronType=Art",
78
+ "Definite=Ind|Gender=Fem|Number=Sing|PronType=Art",
79
+ "Gender=Masc|Number=Sing|PronType=Dem",
80
+ "Mood=Ind|Number=Sing|Person=3|Tense=Imp|VerbForm=Fin",
81
+ "Gender=Masc|Number=Sing|VerbForm=Part",
82
+ "Mood=Ind|Number=Plur|Person=3|Tense=Past|VerbForm=Fin",
83
+ "VerbForm=Ger",
84
+ "Gender=Masc|Number=Sing|VerbForm=Part|Voice=Pass",
85
+ "Case=Acc|Person=3|PronType=Prs",
86
+ "Case=Nom|Gender=Masc|Number=Sing|Person=3|PronType=Prs",
87
+ "ExtPos=SCONJ",
88
+ "Gender=Fem|Number=Sing|VerbForm=Part|Voice=Pass",
89
+ "Gender=Masc|Number=Sing|PronType=Ind",
90
+ "Gender=Fem|Number=Sing|PronType=Dem",
91
+ "Mood=Ind|Number=Sing|Person=1|Tense=Pres|VerbForm=Fin",
92
+ "Foreign=Yes",
93
+ "Gender=Masc|Number=Plur|PronType=Ind",
94
+ "Mood=Ind|Number=Sing|Person=3|Tense=Fut|VerbForm=Fin",
95
+ "Gender=Masc|Number=Plur|VerbForm=Part|Voice=Pass",
96
+ "Gender=Masc|NumType=Card",
97
+ "Gender=Masc|Number=Sing|Person=3|PronType=Dem",
98
+ "PronType=Ind",
99
+ "Gender=Fem|Number=Sing|Person=3|Poss=Yes|PronType=Prs",
100
+ "Mood=Sub|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin",
101
+ "Gender=Fem|Number=Sing|VerbForm=Part",
102
+ "Mood=Ind|Number=Plur|Person=1|Tense=Pres|VerbForm=Fin",
103
+ "Mood=Ind|Number=Plur|Person=3|Tense=Imp|VerbForm=Fin",
104
+ "Gender=Fem|Number=Plur|VerbForm=Part|Voice=Pass",
105
+ "Mood=Cnd|Number=Sing|Person=3|VerbForm=Fin",
106
+ "Mood=Ind|Number=Sing|Person=1|Tense=Past|VerbForm=Fin",
107
+ "ExtPos=ADV",
108
+ "Case=Nom|Gender=Fem|Number=Sing|Person=3|PronType=Prs",
109
+ "Gender=Masc|Number=Plur|VerbForm=Part",
110
+ "Gender=Masc|Number=Sing|Person=3|Poss=Yes|PronType=Prs",
111
+ "Gender=Fem|NumType=Card",
112
+ "Case=Nom|Number=Sing|Person=1|PronType=Prs",
113
+ "Gender=Fem|Number=Plur|PronType=Ind",
114
+ "Gender=Fem|Number=Sing|NumType=Ord",
115
+ "Number=Sing|PronType=Ind",
116
+ "Gender=Masc|Number=Sing|NumType=Ord",
117
+ "Case=Nom|Person=3|PronType=Prs",
118
+ "Gender=Fem|Number=Sing|PronType=Ind",
119
+ "Case=Nom|Gender=Masc|Number=Plur|Person=3|PronType=Prs",
120
+ "Gender=Fem|Number=Plur|VerbForm=Part",
121
+ "Gender=Masc|Number=Plur|Person=3|Poss=Yes|PronType=Prs",
122
+ "Gender=Masc|Number=Plur|PronType=Dem",
123
+ "ExtPos=PRON|Gender=Masc|Number=Sing|Person=3|PronType=Dem",
124
+ "Mood=Sub|Number=Sing|Person=3|Tense=Past|VerbForm=Fin",
125
+ "Case=Acc|Gender=Masc|Number=Sing|Person=3|PronType=Prs",
126
+ "Gender=Masc|Number=Sing|Person=1|Poss=Yes|PronType=Prs",
127
+ "Gender=Fem|Number=Plur|PronType=Dem",
128
+ "Gender=Fem|Number=Sing|Person=1|Poss=Yes|PronType=Prs",
129
+ "Mood=Ind|Number=Plur|Person=3|Tense=Fut|VerbForm=Fin",
130
+ "Number=Sing|Person=3|VerbForm=Inf",
131
+ "Case=Dat|Number=Sing|Person=1|PronType=Prs",
132
+ "Case=Nom|Number=Sing|Person=2|PronType=Prs",
133
+ "Gender=Fem|Number=Plur|Person=3|Poss=Yes|PronType=Prs",
134
+ "Number=Plur|Person=3|VerbForm=Inf",
135
+ "Abbr=Yes|Gender=Fem|Number=Sing",
136
+ "Mood=Sub|Number=Plur|Person=3|Tense=Pres|VerbForm=Fin",
137
+ "ExtPos=CCONJ",
138
+ "Gender=Fem|Number=Sing|Person=3|PronType=Dem",
139
+ "Gender=Masc",
140
+ "Mood=Cnd|Number=Plur|Person=3|VerbForm=Fin",
141
+ "Mood=Ind|Number=Sing|Person=1|Tense=Imp|VerbForm=Fin",
142
+ "Mood=Sub|Number=Sing|Person=3|Tense=Fut|VerbForm=Fin",
143
+ "Gender=Masc|Number=Plur|Person=3|PronType=Dem",
144
+ "Case=Nom|Gender=Fem|Number=Plur|Person=3|PronType=Prs",
145
+ "Case=Nom|Number=Plur|Person=1|PronType=Prs",
146
+ "PronType=Int",
147
+ "Case=Acc|Number=Sing|Person=1|PronType=Prs",
148
+ "Case=Dat|Number=Sing|Person=3|PronType=Prs",
149
+ "Mood=Imp|Number=Sing|Person=3|VerbForm=Fin",
150
+ "Case=Acc|Gender=Fem|Number=Sing|Person=3|PronType=Prs",
151
+ "Case=Acc|Number=Plur|Person=1|PronType=Prs",
152
+ "ExtPos=ADP",
153
+ "Mood=Sub|Number=Plur|Person=3|Tense=Past|VerbForm=Fin",
154
+ "Gender=Masc|Number=Plur|Person=1|Poss=Yes|PronType=Prs",
155
+ "Mood=Ind|Number=Plur|Person=1|Tense=Past|VerbForm=Fin",
156
+ "ExtPos=ADV|Number=Sing|PronType=Ind",
157
+ "Gender=Fem|Number=Plur|Person=3|PronType=Dem",
158
+ "Number=Sing|PronType=Rel",
159
+ "Mood=Ind|Number=Plur|Person=1|Tense=Imp|VerbForm=Fin",
160
+ "Case=Acc|Gender=Masc|Number=Plur|Person=3|PronType=Prs",
161
+ "Abbr=Yes",
162
+ "Abbr=Yes|Gender=Masc|Number=Sing",
163
+ "Case=Dat|Number=Plur|Person=1|PronType=Prs",
164
+ "Gender=Fem|Number=Plur|Person=1|Poss=Yes|PronType=Prs",
165
+ "Number=Sing|PronType=Int",
166
+ "Abbr=Yes|Gender=Masc",
167
+ "Definite=Ind|ExtPos=ADV|Gender=Masc|Number=Sing|PronType=Art",
168
+ "ExtPos=ADP|Gender=Masc|Number=Sing|VerbForm=Part",
169
+ "Mood=Ind|Number=Plur|Person=1|Tense=Fut|VerbForm=Fin",
170
+ "Gender=Masc|Number=Plur|NumType=Ord",
171
+ "Mood=Sub|Number=Plur|Person=3|Tense=Fut|VerbForm=Fin",
172
+ "Case=Acc|Gender=Fem|Number=Plur|Person=3|PronType=Prs",
173
+ "Mood=Ind|Number=Sing|Person=3|Tense=Pqp|VerbForm=Fin",
174
+ "Number=Plur|PronType=Rel",
175
+ "Mood=Cnd|Number=Sing|Person=1|VerbForm=Fin",
176
+ "Mood=Sub|Number=Plur|Person=1|Tense=Pres|VerbForm=Fin",
177
+ "Number=Plur|Person=1|VerbForm=Inf",
178
+ "Number=Plur|PronType=Ind",
179
+ "Case=Nom|Number=Plur|Person=2|PronType=Prs",
180
+ "Number=Sing|PronType=Dem",
181
+ "Gender=Fem|Number=Plur|NumType=Ord",
182
+ "Mood=Cnd|Number=Plur|Person=1|VerbForm=Fin",
183
+ "Mood=Sub|Number=Plur|Person=1|Tense=Fut|VerbForm=Fin",
184
+ "Mood=Sub|Number=Sing|Person=1|Tense=Pres|VerbForm=Fin",
185
+ "Definite=Ind|Gender=Masc|Number=Plur|PronType=Art",
186
+ "ExtPos=PRON|Gender=Masc|Number=Plur|Person=3|PronType=Dem",
187
+ "ExtPos=PRON|Gender=Masc|Number=Sing|PronType=Dem",
188
+ "ExtPos=PRON|PronType=Ind",
189
+ "Gender=Fem|Number=Sing|PronType=Rel",
190
+ "Mood=Imp|Number=Sing|Person=2|VerbForm=Fin",
191
+ "Case=Dat|Person=3|PronType=Prs",
192
+ "ExtPos=PRON|Gender=Fem|Number=Sing|Person=3|PronType=Dem",
193
+ "Gender=Fem",
194
+ "Mood=Sub|Number=Sing|Person=1|Tense=Past|VerbForm=Fin",
195
+ "Number=Plur|PronType=Int",
196
+ "Abbr=Yes|Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin",
197
+ "Gender=Masc|Number=Sing|PronType=Rel",
198
+ "Mood=Imp|Number=Plur|Person=3|VerbForm=Fin",
199
+ "Mood=Ind|Number=Plur|Person=3|Tense=Pqp|VerbForm=Fin",
200
+ "Mood=Ind|Number=Sing|Person=1|Tense=Fut|VerbForm=Fin",
201
+ "ExtPos=PRON|Gender=Fem|Number=Plur|Person=3|PronType=Dem",
202
+ "ExtPos=SCONJ|Gender=Fem|NumType=Card",
203
+ "Mood=Imp|Number=Plur|Person=1|VerbForm=Fin",
204
+ "Mood=Sub|Number=Plur|Person=1|Tense=Past|VerbForm=Fin",
205
+ "Case=Dat|Number=Plur|Person=3|PronType=Prs",
206
+ "Definite=Ind|Gender=Fem|Number=Plur|PronType=Art",
207
+ "ExtPos=SCONJ|Gender=Masc|Number=Sing|VerbForm=Part",
208
+ "Gender=Fem|NumType=Frac",
209
+ "Gender=Masc|NumType=Frac",
210
+ "Number=Plur|PronType=Dem",
211
+ "Abbr=Yes|Gender=Masc|Number=Plur",
212
+ "Case=Acc|Number=Sing|Person=2|PronType=Prs",
213
+ "Definite=Ind|ExtPos=SCONJ|Gender=Fem|Number=Sing|PronType=Art",
214
+ "ExtPos=ADV|Gender=Fem|Number=Sing",
215
+ "ExtPos=ADV|Gender=Masc|NumType=Card",
216
+ "ExtPos=CCONJ|Gender=Masc|Number=Sing",
217
+ "ExtPos=SCONJ|Number=Sing|PronType=Dem",
218
+ "Gender=Fem|Number=Plur|PronType=Rel",
219
+ "Gender=Masc|NumType=Ord",
220
+ "Mood=Sub|Number=Sing|Person=1|Tense=Fut|VerbForm=Fin",
221
+ "Abbr=Yes|Mood=Ind|Number=Plur|Person=1|Tense=Pres|VerbForm=Fin",
222
+ "Abbr=Yes|Mood=Ind|Number=Sing|Person=1|Tense=Pres|VerbForm=Fin",
223
+ "Abbr=Yes|Mood=Ind|Number=Sing|Person=3|Tense=Imp|VerbForm=Fin",
224
+ "Case=Dat|Number=Sing|Person=2|PronType=Prs",
225
+ "Definite=Def|ExtPos=ADV|Gender=Masc|Number=Sing|PronType=Art",
226
+ "ExtPos=ADP|Gender=Fem|Number=Sing",
227
+ "ExtPos=ADV|Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin",
228
+ "ExtPos=CCONJ|Gender=Masc|Number=Sing|PronType=Dem",
229
+ "ExtPos=PRON|Gender=Fem|Number=Sing|PronType=Dem",
230
+ "ExtPos=SCONJ|Number=Sing|PronType=Ind",
231
+ "Gender=Masc|Number=Plur|PronType=Rel",
232
+ "Number=Sing|Person=1|VerbForm=Inf",
233
+ "Number=Sing|VerbForm=Part"
234
+ ],
235
+ "head_target": "word_index",
236
+ "hidden_act": "gelu",
237
+ "hidden_dropout_prob": 0.1,
238
+ "hidden_size": 768,
239
+ "hubparser_head": "linear",
240
+ "initializer_range": 0.02,
241
+ "intermediate_size": 3072,
242
+ "is_decoder": false,
243
+ "layer_norm_eps": 1e-12,
244
+ "lemma_rules": [
245
+ "k|0|",
246
+ "k|1|",
247
+ "k|1|o",
248
+ "l|0|",
249
+ "k|2|o",
250
+ "k|0|r",
251
+ "k|2|",
252
+ "k|2|ar",
253
+ "k|1|r",
254
+ "k|2|r",
255
+ "k|3|r",
256
+ "k|1|ser",
257
+ "k|3|ão",
258
+ "k|3|ser",
259
+ "k|2|l",
260
+ "k|2|er",
261
+ "l|1|",
262
+ "k|1|e",
263
+ "k|1|ar",
264
+ "k|0|er",
265
+ "k|3|er",
266
+ "k|2|eu",
267
+ "k|2|m",
268
+ "k|3|ir",
269
+ "k|3|zer",
270
+ "k|1|ir",
271
+ "k|4|er",
272
+ "k|2|ir",
273
+ "k|5|ser",
274
+ "k|1|aver",
275
+ "k|1|er",
276
+ "k|2|e",
277
+ "l|0|r",
278
+ "l|1|e",
279
+ "l|3|r",
280
+ "k|3|ois",
281
+ "k|3|",
282
+ "k|4|ês",
283
+ "l|1|ar",
284
+ "k|3|eu",
285
+ "l|2|ar",
286
+ "k|0|-feira",
287
+ "k|4|azer",
288
+ "l|2|r",
289
+ "l|2|",
290
+ "l|1|aver",
291
+ "k|2|azer",
292
+ "k|3|eguir",
293
+ "l|1|r",
294
+ "k|4|r",
295
+ "l|2|er",
296
+ "l|1|o",
297
+ "k|4|eu",
298
+ "k|4|ir",
299
+ "k|4|aver",
300
+ "k|6|er",
301
+ "k|5|er",
302
+ "k|5|ir",
303
+ "k|0|o",
304
+ "k|4|ser",
305
+ "k|2|os",
306
+ "k|2|zer",
307
+ "k|1|m",
308
+ "l|2|o",
309
+ "k|3|ar",
310
+ "k|2|erer",
311
+ "k|3|ês",
312
+ "k|6|azer",
313
+ "k|3|el",
314
+ "k|3|der",
315
+ "k|3|il",
316
+ "l|1|er",
317
+ "k|2|or",
318
+ "k|2|aber",
319
+ "k|2|ara",
320
+ "l|2|eu",
321
+ "k|1|l",
322
+ "k|4|car",
323
+ "l|1|ir",
324
+ "l|2|e",
325
+ "l|2|l",
326
+ "k|0|ir",
327
+ "k|2|quilômetro",
328
+ "l|4|eu",
329
+ "k|4|ar",
330
+ "k|5|azer",
331
+ "k|6|zer",
332
+ "l|2|m",
333
+ "k|3|unir",
334
+ "k|4|erer",
335
+ "l|3|ão",
336
+ "k|2|cer",
337
+ "k|2|enhor",
338
+ "k|3|ger",
339
+ "k|5|eu",
340
+ "k|6|ar",
341
+ "k|6|oder",
342
+ "k|2|nder",
343
+ "k|4|",
344
+ "k|2|ver",
345
+ "k|3|çar",
346
+ "k|3|erir",
347
+ "k|4|der",
348
+ "k|7|er",
349
+ "k|1|ililitro",
350
+ "k|2|estar",
351
+ "k|3|car",
352
+ "k|5|aver",
353
+ "k|6|ser",
354
+ "l|2|ir",
355
+ "l|3|eu",
356
+ "l|4|er",
357
+ "k|2|der",
358
+ "k|2|dir",
359
+ "k|2|u",
360
+ "k|3|ibir",
361
+ "k|3|nder",
362
+ "k|3|oder",
363
+ "k|4|aber",
364
+ "k|4|atar",
365
+ "k|4|rir",
366
+ "k|4|zer",
367
+ "k|5|",
368
+ "l|0|er",
369
+ "l|3|er",
370
+ "l|3|zer",
371
+ "l|4|entir",
372
+ "l|5|er",
373
+ "k|1|au",
374
+ "k|1|efone",
375
+ "k|1|úmero",
376
+ "k|3|ol",
377
+ "k|3|or",
378
+ "k|5|rir",
379
+ "k|7|aver",
380
+ "l|2|os",
381
+ "l|4|",
382
+ "l|4|ar",
383
+ "k|0|uto",
384
+ "k|2|ôr",
385
+ "k|3|ever",
386
+ "k|3|u",
387
+ "k|3|ubir",
388
+ "k|4|entir",
389
+ "k|4|ger",
390
+ "k|4|iz",
391
+ "k|4|ão",
392
+ "k|5|atar",
393
+ "k|5|zer",
394
+ "k|6|erer",
395
+ "k|8|-feira",
396
+ "l|2|aber",
397
+ "l|2|azer",
398
+ "l|2|cer",
399
+ "l|3|",
400
+ "l|3|car",
401
+ "l|3|erir",
402
+ "l|4|aver",
403
+ "l|5|",
404
+ "k|0|mente",
405
+ "k|1|ingo",
406
+ "k|2|gir",
407
+ "k|2|uir",
408
+ "k|3|ber",
409
+ "k|3|cer",
410
+ "k|3|enhora",
411
+ "k|3|iar",
412
+ "k|3|umir",
413
+ "k|4|és",
414
+ "k|5|r",
415
+ "k|5|ôr",
416
+ "k|7|aber",
417
+ "k|9|er",
418
+ "l|1|elevisão",
419
+ "l|1|m",
420
+ "l|3|ois",
421
+ "l|4|azer",
422
+ "l|4|car",
423
+ "l|6|ar",
424
+ "l|6|er",
425
+ "l|7|er",
426
+ "k|0|u",
427
+ "k|10|o-ministro",
428
+ "k|11|-executivo",
429
+ "k|15|disente-ditador",
430
+ "k|16|-incorporador",
431
+ "k|1|em",
432
+ "k|1|igo",
433
+ "k|1|uto",
434
+ "k|2|elhor",
435
+ "k|2|oer",
436
+ "k|2|om",
437
+ "k|2|quilograma",
438
+ "k|2|s",
439
+ "k|2|çar",
440
+ "k|2|ô",
441
+ "k|3|edir",
442
+ "k|3|etir",
443
+ "k|3|gir",
444
+ "k|3|iz",
445
+ "k|3|rer",
446
+ "k|3|ugir",
447
+ "k|4|eguir",
448
+ "k|4|ergir",
449
+ "k|4|erir",
450
+ "k|4|ervir",
451
+ "k|4|estar",
452
+ "k|4|ever",
453
+ "k|4|ibir",
454
+ "k|4|imir",
455
+ "k|4|oder",
456
+ "k|4|ormir",
457
+ "k|4|rer",
458
+ "k|4|ubir",
459
+ "k|4|ugir",
460
+ "k|5|ar",
461
+ "k|5|der",
462
+ "k|5|ói",
463
+ "k|6|der",
464
+ "k|6|ir",
465
+ "k|6|o",
466
+ "k|6|o-irmão",
467
+ "k|6|or",
468
+ "k|6|r",
469
+ "k|6|ôr",
470
+ "k|7|ar",
471
+ "k|7|azer",
472
+ "k|7|oder",
473
+ "k|8|-prima",
474
+ "k|8|coitadinho",
475
+ "k|9|-de-jaca",
476
+ "k|9|oder",
477
+ "l|1|ado",
478
+ "l|1|au",
479
+ "l|1|esso",
480
+ "l|1|ionamento",
481
+ "l|2|or",
482
+ "l|2|outor",
483
+ "l|2|ver",
484
+ "l|2|zer",
485
+ "l|2|çar",
486
+ "l|3|ar",
487
+ "l|3|der",
488
+ "l|3|il",
489
+ "l|3|ir",
490
+ "l|3|ol",
491
+ "l|3|çar",
492
+ "l|4|ir",
493
+ "l|4|r",
494
+ "l|4|rir",
495
+ "l|5|zer",
496
+ "l|5|ôr"
497
+ ],
498
+ "max_position_embeddings": 512,
499
+ "model_type": "bert",
500
+ "num_attention_heads": 12,
501
+ "num_head_labels": 200,
502
+ "num_hidden_layers": 12,
503
+ "output_past": true,
504
+ "pad_token_id": 0,
505
+ "pooler_fc_size": 768,
506
+ "pooler_num_attention_heads": 12,
507
+ "pooler_num_fc_layers": 3,
508
+ "pooler_size_per_head": 128,
509
+ "pooler_type": "first_token_transform",
510
+ "tie_word_embeddings": true,
511
+ "transformers_version": "5.6.2",
512
+ "type_vocab_size": 2,
513
+ "upos_labels": [
514
+ "DET",
515
+ "NOUN",
516
+ "VERB",
517
+ "PUNCT",
518
+ "SCONJ",
519
+ "ADP",
520
+ "ADJ",
521
+ "CCONJ",
522
+ "ADV",
523
+ "PROPN",
524
+ "AUX",
525
+ "NUM",
526
+ "PRON",
527
+ "SYM",
528
+ "X",
529
+ "INTJ"
530
+ ],
531
+ "use_cache": false,
532
+ "vocab_size": 29794,
533
+ "auto_map": {
534
+ "AutoModel": "modeling_hubparser.HubParserFullLinear"
535
+ }
536
+ }
hubparser_results.json ADDED
@@ -0,0 +1,593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "job": "bertimbau-base__linear__pt_full",
3
+ "encoder": "neuralmind/bert-base-portuguese-cased",
4
+ "head": "linear",
5
+ "corpus": "pt_full",
6
+ "search_best": {
7
+ "config": 4,
8
+ "hyperparameters": {
9
+ "learning_rate": 3.818145165896868e-05,
10
+ "weight_decay": 0.14246782213565523,
11
+ "warmup_ratio": 0.3363649934414201,
12
+ "num_train_epochs": 40
13
+ },
14
+ "folds": 5,
15
+ "mean_score": 0.9617479533129053,
16
+ "mean_las": 0.8914823995496827,
17
+ "mean_upos": 0.9892535564748087,
18
+ "mean_lemma": 0.982218396794544,
19
+ "mean_feats": 0.9840374604325863,
20
+ "std_score": 0.0019339629166869176
21
+ },
22
+ "hyperparameters": {
23
+ "learning_rate": 3.818145165896868e-05,
24
+ "weight_decay": 0.14246782213565523,
25
+ "warmup_ratio": 0.3363649934414201,
26
+ "num_train_epochs": 40
27
+ },
28
+ "selection": "final_epoch",
29
+ "train_minutes": 45.7,
30
+ "test": {
31
+ "greedy": {
32
+ "words": 33580,
33
+ "upos": 99.20190589636688,
34
+ "lemma": 98.96069088743299,
35
+ "feats": 98.90113162596784,
36
+ "uas": 92.76354973198332,
37
+ "las": 91.41155449672424
38
+ },
39
+ "eisner": {
40
+ "words": 33580,
41
+ "upos": 99.20190589636688,
42
+ "lemma": 98.96069088743299,
43
+ "feats": 98.90113162596784,
44
+ "uas": 94.18106015485408,
45
+ "las": 92.7724836212031
46
+ },
47
+ "mst": {
48
+ "words": 33580,
49
+ "upos": 99.20190589636688,
50
+ "lemma": 98.96069088743299,
51
+ "feats": 98.90113162596784,
52
+ "uas": 93.3382966051221,
53
+ "las": 91.95354377605717
54
+ }
55
+ },
56
+ "test_conll18_mst": {
57
+ "Tokens": 100.0,
58
+ "Sentences": 100.0,
59
+ "Words": 100.0,
60
+ "UPOS": 99.2,
61
+ "XPOS": 100.0,
62
+ "UFeats": 98.95,
63
+ "AllTags": 98.57,
64
+ "Lemmas": 98.96,
65
+ "UAS": 93.34,
66
+ "LAS": 92.11,
67
+ "CLAS": 89.47,
68
+ "MLAS": 86.55,
69
+ "BLEX": 87.94
70
+ },
71
+ "val_history": [
72
+ {
73
+ "loss": 13.414382934570312,
74
+ "uas": 0.083008472373824,
75
+ "las": 0.023078122563542802,
76
+ "upos": 0.6377150579551952,
77
+ "lemma": 0.6825718592442435,
78
+ "feats": 0.40605021050990175,
79
+ "score": 0.4373538125682208,
80
+ "runtime": 2.7802,
81
+ "samples_per_second": 302.855,
82
+ "steps_per_second": 9.712,
83
+ "epoch": 1.0
84
+ },
85
+ {
86
+ "loss": 7.165677070617676,
87
+ "uas": 0.1213160767191642,
88
+ "las": 0.10385155153594261,
89
+ "upos": 0.9581579084151983,
90
+ "lemma": 0.8676126617807578,
91
+ "feats": 0.8145953531888351,
92
+ "score": 0.6860543687301834,
93
+ "runtime": 2.7737,
94
+ "samples_per_second": 303.567,
95
+ "steps_per_second": 9.734,
96
+ "epoch": 2.0
97
+ },
98
+ {
99
+ "loss": 5.182169437408447,
100
+ "uas": 0.1711627423462758,
101
+ "las": 0.15619314933208586,
102
+ "upos": 0.9781173657674516,
103
+ "lemma": 0.9014501793232497,
104
+ "feats": 0.8859088310203233,
105
+ "score": 0.7304173813607776,
106
+ "runtime": 2.783,
107
+ "samples_per_second": 302.553,
108
+ "steps_per_second": 9.702,
109
+ "epoch": 3.0
110
+ },
111
+ {
112
+ "loss": 3.9568979740142822,
113
+ "uas": 0.24996101668485887,
114
+ "las": 0.23790217786787254,
115
+ "upos": 0.9839388741618588,
116
+ "lemma": 0.9183949269712564,
117
+ "feats": 0.9211497479078954,
118
+ "score": 0.7653464317272207,
119
+ "runtime": 2.7753,
120
+ "samples_per_second": 303.391,
121
+ "steps_per_second": 9.729,
122
+ "epoch": 4.0
123
+ },
124
+ {
125
+ "loss": 3.061382532119751,
126
+ "uas": 0.38884557409428766,
127
+ "las": 0.3737200478195332,
128
+ "upos": 0.9865897395914549,
129
+ "lemma": 0.9295701439783772,
130
+ "feats": 0.9443838037320027,
131
+ "score": 0.808565933780342,
132
+ "runtime": 2.7769,
133
+ "samples_per_second": 303.219,
134
+ "steps_per_second": 9.723,
135
+ "epoch": 5.0
136
+ },
137
+ {
138
+ "loss": 2.436089277267456,
139
+ "uas": 0.5003378553978897,
140
+ "las": 0.48354904101044754,
141
+ "upos": 0.9876812724154062,
142
+ "lemma": 0.9358074744009564,
143
+ "feats": 0.9584177971828057,
144
+ "score": 0.8413638962524039,
145
+ "runtime": 2.7829,
146
+ "samples_per_second": 302.565,
147
+ "steps_per_second": 9.702,
148
+ "epoch": 6.0
149
+ },
150
+ {
151
+ "loss": 1.953381061553955,
152
+ "uas": 0.6088674047507666,
153
+ "las": 0.5915588128281095,
154
+ "upos": 0.9882530277041426,
155
+ "lemma": 0.945891158584126,
156
+ "feats": 0.9679817038307604,
157
+ "score": 0.8734211757367847,
158
+ "runtime": 2.7805,
159
+ "samples_per_second": 302.823,
160
+ "steps_per_second": 9.71,
161
+ "epoch": 7.0
162
+ },
163
+ {
164
+ "loss": 1.6378138065338135,
165
+ "uas": 0.6828837257653724,
166
+ "las": 0.6669265554342741,
167
+ "upos": 0.9884609387182286,
168
+ "lemma": 0.9522324445137481,
169
+ "feats": 0.9718800353448724,
170
+ "score": 0.8948749935027809,
171
+ "runtime": 2.7842,
172
+ "samples_per_second": 302.422,
173
+ "steps_per_second": 9.698,
174
+ "epoch": 8.0
175
+ },
176
+ {
177
+ "loss": 1.3754998445510864,
178
+ "uas": 0.7452570299911638,
179
+ "las": 0.7276885493008992,
180
+ "upos": 0.9880451166900567,
181
+ "lemma": 0.956962420084204,
182
+ "feats": 0.9755184780913769,
183
+ "score": 0.9120536410416341,
184
+ "runtime": 2.7854,
185
+ "samples_per_second": 302.293,
186
+ "steps_per_second": 9.693,
187
+ "epoch": 9.0
188
+ },
189
+ {
190
+ "loss": 1.2243858575820923,
191
+ "uas": 0.7824211237590312,
192
+ "las": 0.764800665315245,
193
+ "upos": 0.9885648942252716,
194
+ "lemma": 0.9622641509433962,
195
+ "feats": 0.9772337439575861,
196
+ "score": 0.9232158636103747,
197
+ "runtime": 2.7794,
198
+ "samples_per_second": 302.94,
199
+ "steps_per_second": 9.714,
200
+ "epoch": 10.0
201
+ },
202
+ {
203
+ "loss": 1.1207982301712036,
204
+ "uas": 0.8015489370549405,
205
+ "las": 0.7851759446956702,
206
+ "upos": 0.988720827485836,
207
+ "lemma": 0.9663184157180726,
208
+ "feats": 0.9788450543167524,
209
+ "score": 0.9297650605540829,
210
+ "runtime": 2.7814,
211
+ "samples_per_second": 302.731,
212
+ "steps_per_second": 9.708,
213
+ "epoch": 11.0
214
+ },
215
+ {
216
+ "loss": 1.017077088356018,
217
+ "uas": 0.8319559228650137,
218
+ "las": 0.8142834866677062,
219
+ "upos": 0.9890846717604865,
220
+ "lemma": 0.9693851031758407,
221
+ "feats": 0.9799365871407038,
222
+ "score": 0.9381724621861843,
223
+ "runtime": 2.7805,
224
+ "samples_per_second": 302.828,
225
+ "steps_per_second": 9.711,
226
+ "epoch": 12.0
227
+ },
228
+ {
229
+ "loss": 1.0069432258605957,
230
+ "uas": 0.8311762565621914,
231
+ "las": 0.8143354644212277,
232
+ "upos": 0.9893965382816154,
233
+ "lemma": 0.9714122355631789,
234
+ "feats": 0.9807162534435262,
235
+ "score": 0.938965122927387,
236
+ "runtime": 2.7946,
237
+ "samples_per_second": 301.29,
238
+ "steps_per_second": 9.661,
239
+ "epoch": 13.0
240
+ },
241
+ {
242
+ "loss": 1.0252442359924316,
243
+ "uas": 0.8210925723790218,
244
+ "las": 0.8041478247310151,
245
+ "upos": 0.9880970944435782,
246
+ "lemma": 0.9732834346899527,
247
+ "feats": 0.9809241644576121,
248
+ "score": 0.9366131295805394,
249
+ "runtime": 2.7851,
250
+ "samples_per_second": 302.327,
251
+ "steps_per_second": 9.695,
252
+ "epoch": 14.0
253
+ },
254
+ {
255
+ "loss": 0.9513410329818726,
256
+ "uas": 0.8535786683299548,
257
+ "las": 0.8362180986537762,
258
+ "upos": 0.9893445605280939,
259
+ "lemma": 0.9755704558448984,
260
+ "feats": 0.981963719528042,
261
+ "score": 0.9457742086387027,
262
+ "runtime": 2.7819,
263
+ "samples_per_second": 302.674,
264
+ "steps_per_second": 9.706,
265
+ "epoch": 15.0
266
+ },
267
+ {
268
+ "loss": 0.9867361783981323,
269
+ "uas": 0.8521752689848745,
270
+ "las": 0.8356983211185612,
271
+ "upos": 0.9887728052393575,
272
+ "lemma": 0.9775456104787151,
273
+ "feats": 0.9830032745984718,
274
+ "score": 0.9462550028587765,
275
+ "runtime": 2.7829,
276
+ "samples_per_second": 302.558,
277
+ "steps_per_second": 9.702,
278
+ "epoch": 16.0
279
+ },
280
+ {
281
+ "loss": 0.9320211410522461,
282
+ "uas": 0.8627787307032591,
283
+ "las": 0.8466656271115962,
284
+ "upos": 0.988928738499922,
285
+ "lemma": 0.9782213212744946,
286
+ "feats": 0.9829512968449503,
287
+ "score": 0.9491917459327408,
288
+ "runtime": 2.7843,
289
+ "samples_per_second": 302.411,
290
+ "steps_per_second": 9.697,
291
+ "epoch": 17.0
292
+ },
293
+ {
294
+ "loss": 0.9572083950042725,
295
+ "uas": 0.8838297208794635,
296
+ "las": 0.8667290399708925,
297
+ "upos": 0.988824782992879,
298
+ "lemma": 0.9788450543167524,
299
+ "feats": 0.9825354748167784,
300
+ "score": 0.9542335880243256,
301
+ "runtime": 2.7817,
302
+ "samples_per_second": 302.697,
303
+ "steps_per_second": 9.706,
304
+ "epoch": 18.0
305
+ },
306
+ {
307
+ "loss": 0.931108832359314,
308
+ "uas": 0.8768647019075836,
309
+ "las": 0.8602837985342273,
310
+ "upos": 0.9898123603097874,
311
+ "lemma": 0.9793128540984458,
312
+ "feats": 0.9836270076407297,
313
+ "score": 0.9532590051457976,
314
+ "runtime": 2.7799,
315
+ "samples_per_second": 302.894,
316
+ "steps_per_second": 9.713,
317
+ "epoch": 19.0
318
+ },
319
+ {
320
+ "loss": 0.8930281400680542,
321
+ "uas": 0.8942772493372837,
322
+ "las": 0.8775923904568844,
323
+ "upos": 0.989760382556266,
324
+ "lemma": 0.9793648318519673,
325
+ "feats": 0.9838868964083373,
326
+ "score": 0.9576511253183638,
327
+ "runtime": 2.7811,
328
+ "samples_per_second": 302.762,
329
+ "steps_per_second": 9.709,
330
+ "epoch": 20.0
331
+ },
332
+ {
333
+ "loss": 0.9088257551193237,
334
+ "uas": 0.9009823795415562,
335
+ "las": 0.8852331202245439,
336
+ "upos": 0.989656427049223,
337
+ "lemma": 0.9805083424294402,
338
+ "feats": 0.9838868964083373,
339
+ "score": 0.9598211965278861,
340
+ "runtime": 2.7808,
341
+ "samples_per_second": 302.795,
342
+ "steps_per_second": 9.71,
343
+ "epoch": 21.0
344
+ },
345
+ {
346
+ "loss": 0.9104270935058594,
347
+ "uas": 0.895264826654192,
348
+ "las": 0.8784240345132284,
349
+ "upos": 0.9898123603097874,
350
+ "lemma": 0.9811840532252196,
351
+ "feats": 0.9845626072041166,
352
+ "score": 0.958495763813088,
353
+ "runtime": 2.7795,
354
+ "samples_per_second": 302.933,
355
+ "steps_per_second": 9.714,
356
+ "epoch": 22.0
357
+ },
358
+ {
359
+ "loss": 0.9419113993644714,
360
+ "uas": 0.8992151359218254,
361
+ "las": 0.8825822547949478,
362
+ "upos": 0.989760382556266,
363
+ "lemma": 0.9819117417745205,
364
+ "feats": 0.9844066739435522,
365
+ "score": 0.9596652632673217,
366
+ "runtime": 2.783,
367
+ "samples_per_second": 302.549,
368
+ "steps_per_second": 9.702,
369
+ "epoch": 23.0
370
+ },
371
+ {
372
+ "loss": 0.9673270583152771,
373
+ "uas": 0.8978637143302667,
374
+ "las": 0.8818025884921253,
375
+ "upos": 0.9896044492957015,
376
+ "lemma": 0.9824834970632569,
377
+ "feats": 0.9839388741618588,
378
+ "score": 0.9594573522532356,
379
+ "runtime": 2.7786,
380
+ "samples_per_second": 303.029,
381
+ "steps_per_second": 9.717,
382
+ "epoch": 24.0
383
+ },
384
+ {
385
+ "loss": 0.9065078496932983,
386
+ "uas": 0.9121056187951557,
387
+ "las": 0.8958365819429285,
388
+ "upos": 0.9909038931337387,
389
+ "lemma": 0.9828473413379074,
390
+ "feats": 0.9850823847393315,
391
+ "score": 0.9636675502884766,
392
+ "runtime": 2.7823,
393
+ "samples_per_second": 302.622,
394
+ "steps_per_second": 9.704,
395
+ "epoch": 25.0
396
+ },
397
+ {
398
+ "loss": 0.9272711873054504,
399
+ "uas": 0.912781329590935,
400
+ "las": 0.8976038255626592,
401
+ "upos": 0.9898643380633089,
402
+ "lemma": 0.9828993190914289,
403
+ "feats": 0.9849784292322886,
404
+ "score": 0.9638364779874214,
405
+ "runtime": 2.7837,
406
+ "samples_per_second": 302.473,
407
+ "steps_per_second": 9.699,
408
+ "epoch": 26.0
409
+ },
410
+ {
411
+ "loss": 0.9851851463317871,
412
+ "uas": 0.9020739123655076,
413
+ "las": 0.8866365195696242,
414
+ "upos": 0.9904360933520453,
415
+ "lemma": 0.9840428296689017,
416
+ "feats": 0.985862051042154,
417
+ "score": 0.9617443734081812,
418
+ "runtime": 2.7953,
419
+ "samples_per_second": 301.223,
420
+ "steps_per_second": 9.659,
421
+ "epoch": 27.0
422
+ },
423
+ {
424
+ "loss": 0.9855141043663025,
425
+ "uas": 0.9074276209782213,
426
+ "las": 0.8916263839076876,
427
+ "upos": 0.9907479598731743,
428
+ "lemma": 0.9831592078590363,
429
+ "feats": 0.9859140287956755,
430
+ "score": 0.9628618951088934,
431
+ "runtime": 2.7818,
432
+ "samples_per_second": 302.677,
433
+ "steps_per_second": 9.706,
434
+ "epoch": 28.0
435
+ },
436
+ {
437
+ "loss": 1.0266239643096924,
438
+ "uas": 0.9058163106190551,
439
+ "las": 0.8897032070273923,
440
+ "upos": 0.9900722490773949,
441
+ "lemma": 0.9831072301055148,
442
+ "feats": 0.9848224959717241,
443
+ "score": 0.9619262955455066,
444
+ "runtime": 2.7874,
445
+ "samples_per_second": 302.07,
446
+ "steps_per_second": 9.686,
447
+ "epoch": 29.0
448
+ },
449
+ {
450
+ "loss": 0.976352870464325,
451
+ "uas": 0.920162170590987,
452
+ "las": 0.9042050002598888,
453
+ "upos": 0.9901242268309164,
454
+ "lemma": 0.9839908519153803,
455
+ "feats": 0.985446229013982,
456
+ "score": 0.9659415770050418,
457
+ "runtime": 2.788,
458
+ "samples_per_second": 302.008,
459
+ "steps_per_second": 9.684,
460
+ "epoch": 30.0
461
+ },
462
+ {
463
+ "loss": 1.0598485469818115,
464
+ "uas": 0.9075835542387858,
465
+ "las": 0.8915224284006446,
466
+ "upos": 0.9901242268309164,
467
+ "lemma": 0.9844066739435522,
468
+ "feats": 0.9863818285773689,
469
+ "score": 0.9631087894381204,
470
+ "runtime": 2.7882,
471
+ "samples_per_second": 301.984,
472
+ "steps_per_second": 9.684,
473
+ "epoch": 31.0
474
+ },
475
+ {
476
+ "loss": 0.9969959259033203,
477
+ "uas": 0.9189666822599927,
478
+ "las": 0.902957534175373,
479
+ "upos": 0.9904360933520453,
480
+ "lemma": 0.9847185404646811,
481
+ "feats": 0.9858100732886325,
482
+ "score": 0.965980560320183,
483
+ "runtime": 2.787,
484
+ "samples_per_second": 302.116,
485
+ "steps_per_second": 9.688,
486
+ "epoch": 32.0
487
+ },
488
+ {
489
+ "loss": 1.0541725158691406,
490
+ "uas": 0.9122615520557201,
491
+ "las": 0.8962004262175789,
492
+ "upos": 0.9906440043661313,
493
+ "lemma": 0.9848224959717241,
494
+ "feats": 0.985758095535111,
495
+ "score": 0.9643562555226364,
496
+ "runtime": 2.7862,
497
+ "samples_per_second": 302.209,
498
+ "steps_per_second": 9.691,
499
+ "epoch": 33.0
500
+ },
501
+ {
502
+ "loss": 1.0476558208465576,
503
+ "uas": 0.9153282395134882,
504
+ "las": 0.9000467799781694,
505
+ "upos": 0.9906440043661313,
506
+ "lemma": 0.9849264514787671,
507
+ "feats": 0.985862051042154,
508
+ "score": 0.9653698217163055,
509
+ "runtime": 2.7856,
510
+ "samples_per_second": 302.274,
511
+ "steps_per_second": 9.693,
512
+ "epoch": 34.0
513
+ },
514
+ {
515
+ "loss": 1.0358879566192627,
516
+ "uas": 0.9181870159571703,
517
+ "las": 0.9032174229429804,
518
+ "upos": 0.9910078486407817,
519
+ "lemma": 0.9850823847393315,
520
+ "feats": 0.9864338063308904,
521
+ "score": 0.966435365663496,
522
+ "runtime": 2.7884,
523
+ "samples_per_second": 301.968,
524
+ "steps_per_second": 9.683,
525
+ "epoch": 35.0
526
+ },
527
+ {
528
+ "loss": 1.063065767288208,
529
+ "uas": 0.9151203284994023,
530
+ "las": 0.8996829357035189,
531
+ "upos": 0.9906440043661313,
532
+ "lemma": 0.9848224959717241,
533
+ "feats": 0.985862051042154,
534
+ "score": 0.9652528717708821,
535
+ "runtime": 2.7786,
536
+ "samples_per_second": 303.033,
537
+ "steps_per_second": 9.717,
538
+ "epoch": 36.0
539
+ },
540
+ {
541
+ "loss": 1.064010500907898,
542
+ "uas": 0.9179791049430843,
543
+ "las": 0.9023857788866365,
544
+ "upos": 0.9909558708872602,
545
+ "lemma": 0.985134362492853,
546
+ "feats": 0.9863818285773689,
547
+ "score": 0.9662144602110296,
548
+ "runtime": 2.7811,
549
+ "samples_per_second": 302.763,
550
+ "steps_per_second": 9.709,
551
+ "epoch": 37.0
552
+ },
553
+ {
554
+ "loss": 1.0475267171859741,
555
+ "uas": 0.9177192161754769,
556
+ "las": 0.9029055564218514,
557
+ "upos": 0.9911118041478247,
558
+ "lemma": 0.9850304069858101,
559
+ "feats": 0.9865897395914549,
560
+ "score": 0.9664093767867352,
561
+ "runtime": 2.7865,
562
+ "samples_per_second": 302.173,
563
+ "steps_per_second": 9.69,
564
+ "epoch": 38.0
565
+ },
566
+ {
567
+ "loss": 1.0473544597625732,
568
+ "uas": 0.9190186600135142,
569
+ "las": 0.9039451114922813,
570
+ "upos": 0.9912157596548677,
571
+ "lemma": 0.9850823847393315,
572
+ "feats": 0.9866936950984978,
573
+ "score": 0.9667342377462446,
574
+ "runtime": 2.7834,
575
+ "samples_per_second": 302.507,
576
+ "steps_per_second": 9.7,
577
+ "epoch": 39.0
578
+ },
579
+ {
580
+ "loss": 1.0459518432617188,
581
+ "uas": 0.9184988824782993,
582
+ "las": 0.9036852227246739,
583
+ "upos": 0.9910598263943032,
584
+ "lemma": 0.9850304069858101,
585
+ "feats": 0.9866936950984978,
586
+ "score": 0.9666172878008212,
587
+ "runtime": 2.7869,
588
+ "samples_per_second": 302.132,
589
+ "steps_per_second": 9.688,
590
+ "epoch": 40.0
591
+ }
592
+ ]
593
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b33bbab31052a2ef99e1ae86b09f79666b92f06f1cef87bb68ee73e42011071f
3
+ size 437826968
modeling_hubparser.py ADDED
@@ -0,0 +1,644 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """HubParser: complete UD parser for Brazilian Portuguese (UPOS + LEMMA + FEATS + HEAD + DEPREL).
2
+
3
+ Self-contained remote code for the Hugging Face Hub (only torch, numpy and transformers).
4
+
5
+ from transformers import AutoModel, AutoTokenizer
6
+ tok = AutoTokenizer.from_pretrained(repo)
7
+ model = AutoModel.from_pretrained(repo, trust_remote_code=True).eval()
8
+ model.parse([["O", "canal", "terá", "o", "conteúdo", "reformulado", "."]], tok, decoding="eisner")
9
+
10
+ Each word comes back as {id, form, lemma, upos, feats, head, deprel} (head 0 = root).
11
+ HubParser: multi-task UD parsers (UPOS + DEPREL + HEAD) on BERT-family encoders.
12
+
13
+ Two head types, as in the dissertation:
14
+ * linear - three per-token linear classifiers; HEAD is a classification over
15
+ absolute word positions (0 = root, 1..N = 1-based word index).
16
+ * biaffine - linear UPOS + biaffine arc/rel scorers (Dozat & Manning, 2017);
17
+ HEAD is scored over the subtoken positions of the sequence.
18
+
19
+ Biaffine head targets (`config.head_target`):
20
+ * word_index - as in the dissertation: the gold column for head word k is
21
+ sequence position k (misaligned once earlier words split into
22
+ several subtokens);
23
+ * first_subtoken - corrected: the gold column is the first subtoken of the head
24
+ word, and the root is [CLS] (position 0).
25
+
26
+ Label inventories live in the config (`upos_labels`, `deprel_labels`).
27
+ """
28
+ from typing import List, Optional
29
+
30
+ import numpy as np
31
+ import torch
32
+ import torch.nn as nn
33
+ from transformers import (
34
+ AutoModel,
35
+ BertConfig,
36
+ BertModel,
37
+ BertPreTrainedModel,
38
+ ModernBertConfig,
39
+ ModernBertModel,
40
+ ModernBertPreTrainedModel,
41
+ )
42
+
43
+
44
+ # ─────────────────────────────────────────────────────────────────────────────
45
+ # Building blocks
46
+ # ─────────────────────────────────────────────────────────────────────────────
47
+ class MLP(nn.Module):
48
+ """Non-linear projection used before the biaffine layers."""
49
+
50
+ def __init__(self, in_features: int, out_features: int, dropout: float = 0.33):
51
+ super().__init__()
52
+ self.linear = nn.Linear(in_features, out_features)
53
+ self.activation = nn.ELU()
54
+ self.norm = nn.LayerNorm(out_features)
55
+ self.dropout = nn.Dropout(dropout)
56
+ nn.init.orthogonal_(self.linear.weight)
57
+ nn.init.zeros_(self.linear.bias)
58
+
59
+ def forward(self, x):
60
+ return self.dropout(self.norm(self.activation(self.linear(x))))
61
+
62
+
63
+ class Biaffine(nn.Module):
64
+ """score[b, o, i, j] = x[b,i,:] · W[o] · y[b,j,:] (x = dependent, y = head)."""
65
+
66
+ def __init__(self, in_features: int, out_features: int = 1, bias_x: bool = True, bias_y: bool = True):
67
+ super().__init__()
68
+ self.in_features = in_features
69
+ self.out_features = out_features
70
+ self.bias_x = bias_x
71
+ self.bias_y = bias_y
72
+ self.weight = nn.Parameter(torch.zeros(out_features, in_features + int(bias_x), in_features + int(bias_y)))
73
+ nn.init.normal_(self.weight, std=1.0 / in_features)
74
+
75
+ def forward(self, x, y):
76
+ if self.bias_x:
77
+ x = torch.cat([x, x.new_ones(*x.shape[:-1], 1)], dim=-1)
78
+ if self.bias_y:
79
+ y = torch.cat([y, y.new_ones(*y.shape[:-1], 1)], dim=-1)
80
+ return torch.einsum("bih,ohk,bjk->boij", x, self.weight, y)
81
+
82
+
83
+ def _init_biaffine_weights(model, module):
84
+ if isinstance(module, Biaffine):
85
+ nn.init.normal_(module.weight, std=1.0 / module.in_features)
86
+ elif isinstance(module, nn.Linear):
87
+ nn.init.normal_(module.weight, std=model.config.initializer_range)
88
+ if module.bias is not None:
89
+ nn.init.zeros_(module.bias)
90
+ elif isinstance(module, nn.LayerNorm):
91
+ nn.init.zeros_(module.bias)
92
+ nn.init.ones_(module.weight)
93
+ elif isinstance(module, nn.Embedding):
94
+ nn.init.normal_(module.weight, std=model.config.initializer_range)
95
+ if module.padding_idx is not None:
96
+ module.weight.data[module.padding_idx].zero_()
97
+
98
+
99
+ # ─────────────────────────────────────────────────────────────────────────────
100
+ # Inference helper shared by every variant
101
+ # ─────────────────────────────────────────────────────────────────────────────
102
+ class HubParserMixin:
103
+ """Inference shared by every variant.
104
+
105
+ decoding = "greedy" (per-word argmax, as in the dissertation), "eisner" (best
106
+ projective tree) or "mst" (Chu-Liu/Edmonds, best non-projective tree). Tree
107
+ decoders use log P(head | dependent) restricted to the words of the sentence and
108
+ always return a single-rooted tree.
109
+ """
110
+
111
+ def _head_columns(self, first_pos):
112
+ """Sequence columns that stand for heads 0..n (0 = root)."""
113
+ if getattr(self.config, "hubparser_head", "linear") == "linear":
114
+ return list(range(len(first_pos) + 1)) # class k = word k
115
+ if getattr(self.config, "head_target", "word_index") == "first_subtoken":
116
+ return [0] + first_pos # [CLS] = root
117
+ return list(range(len(first_pos) + 1)) # dissertation: position k = word k
118
+
119
+ @torch.no_grad()
120
+ def _sentence_outputs(self, enc_one):
121
+ inputs = {k: v.to(self.device) for k, v in enc_one.items()}
122
+ if getattr(self.config, "hubparser_head", "linear") == "linear":
123
+ logits_deprel, logits_upos, logits_head = self(
124
+ input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"],
125
+ token_type_ids=inputs.get("token_type_ids"))
126
+ return logits_upos[0], logits_head[0], logits_deprel[0], None
127
+ seq = self._encode(inputs)
128
+ seq = self.dropout(seq)
129
+ arc = self.arc_biaffine(self.arc_dep_mlp(seq), self.arc_head_mlp(seq)).squeeze(1)[0]
130
+ rel = self.rel_biaffine(self.rel_dep_mlp(seq), self.rel_head_mlp(seq))[0] # [R, L, L]
131
+ return self.upos_classifier(seq)[0], arc, None, rel
132
+
133
+ @torch.no_grad()
134
+ def parse(self, sentences: List[List[str]], tokenizer, decoding: str = "greedy", max_length: int = 512):
135
+ """Parse pre-tokenized sentences. Returns one list per sentence of dicts
136
+ {id, form, upos, head, deprel} (head = 0 is the root)."""
137
+ assert decoding in ("greedy", "eisner", "mst"), decoding
138
+ self.eval()
139
+ biaffine = getattr(self.config, "hubparser_head", "linear") == "biaffine"
140
+ results = []
141
+ for words in sentences:
142
+ enc = tokenizer([words], is_split_into_words=True, truncation=True, max_length=max_length,
143
+ return_tensors="pt")
144
+ word_ids = enc.word_ids(0)
145
+ first = {}
146
+ for pos, w in enumerate(word_ids):
147
+ if w is not None and w not in first:
148
+ first[w] = pos
149
+ n = len(first)
150
+ first_pos = [first[i] for i in range(n)]
151
+ cols = self._head_columns(first_pos)
152
+ col2head = {c: h for h, c in enumerate(cols)}
153
+ pos2word = {p: (w + 1 if w is not None else 0) for p, w in enumerate(word_ids)}
154
+
155
+ upos_l, head_l, deprel_l, rel = self._sentence_outputs(dict(enc))
156
+ head_rows = head_l[first_pos].float() # [n, C]
157
+ if decoding == "greedy":
158
+ pred_cols = head_rows.argmax(-1).tolist()
159
+ if biaffine and getattr(self.config, "head_target", "word_index") == "first_subtoken":
160
+ heads = [pos2word.get(c, 0) for c in pred_cols]
161
+ else:
162
+ heads = pred_cols # may fall outside 0..n
163
+ else:
164
+ S = torch.log_softmax(head_rows, -1)[:, cols].double().cpu().numpy()
165
+ heads = eisner(S) if decoding == "eisner" else chu_liu_edmonds(S)
166
+ pred_cols = [cols[h] if h < len(cols) else h for h in heads]
167
+ if biaffine:
168
+ deprel_ids = [int(rel[:, first_pos[d], min(c, rel.shape[-1] - 1)].argmax()) for d, c in enumerate(pred_cols)]
169
+ else:
170
+ deprel_ids = deprel_l[first_pos].argmax(-1).tolist()
171
+ upos_ids = upos_l[first_pos].argmax(-1).tolist()
172
+ results.append([
173
+ {"id": d + 1, "form": words[d], "upos": self.config.upos_labels[upos_ids[d]],
174
+ "head": int(heads[d]), "deprel": self.config.deprel_labels[deprel_ids[d]]}
175
+ for d in range(n)])
176
+ return results
177
+
178
+
179
+ # ─────────────────────────────────────────────────────────────────────────────
180
+ # Linear head (any encoder loadable with AutoModel)
181
+ # ─────────────────────────────────────────────────────────────────────────────
182
+ class HubParserLinear(HubParserMixin, BertPreTrainedModel):
183
+ config_class = BertConfig
184
+
185
+ def __init__(self, config):
186
+ super().__init__(config)
187
+ self.num_deprel_labels = len(config.deprel_labels)
188
+ self.num_upos_labels = len(config.upos_labels)
189
+ self.num_head_labels = config.num_head_labels
190
+
191
+ self.bert = AutoModel.from_config(config)
192
+ self.deprel_classifier = nn.Linear(config.hidden_size, self.num_deprel_labels)
193
+ self.upos_classifier = nn.Linear(config.hidden_size, self.num_upos_labels)
194
+ self.head_classifier = nn.Linear(config.hidden_size, self.num_head_labels)
195
+
196
+ classifier_dropout = getattr(config, "classifier_dropout", None)
197
+ if classifier_dropout is None:
198
+ classifier_dropout = getattr(config, "hidden_dropout_prob", 0.1)
199
+ self.dropout = nn.Dropout(classifier_dropout)
200
+ self.post_init()
201
+
202
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None,
203
+ deprel_label=None, upos_label=None, head_label=None):
204
+ encoder_kwargs = {"input_ids": input_ids, "attention_mask": attention_mask}
205
+ if token_type_ids is not None and self.config.model_type != "modernbert":
206
+ encoder_kwargs["token_type_ids"] = token_type_ids
207
+ sequence_output = self.dropout(self.bert(**encoder_kwargs)[0])
208
+
209
+ logits_deprel = self.deprel_classifier(sequence_output)
210
+ logits_upos = self.upos_classifier(sequence_output)
211
+ logits_head = self.head_classifier(sequence_output)
212
+
213
+ if deprel_label is not None and upos_label is not None and head_label is not None:
214
+ loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
215
+ loss = (
216
+ loss_fct(logits_deprel.view(-1, self.num_deprel_labels), deprel_label.view(-1))
217
+ + loss_fct(logits_upos.view(-1, self.num_upos_labels), upos_label.view(-1))
218
+ + loss_fct(logits_head.view(-1, self.num_head_labels), head_label.view(-1))
219
+ )
220
+ return loss, logits_deprel, logits_upos, logits_head
221
+ return logits_deprel, logits_upos, logits_head
222
+
223
+
224
+ class HubParserLinearModernBert(HubParserLinear):
225
+ config_class = ModernBertConfig
226
+
227
+
228
+ # ─────────────────────────────────────────────────────────────────────────────
229
+ # Biaffine head
230
+ # ─────────────────────────────────────────────────────────────────────────────
231
+ class _BiaffineHeads:
232
+ def _build_heads(self, config):
233
+ self.num_deprel_labels = len(config.deprel_labels)
234
+ self.num_upos_labels = len(config.upos_labels)
235
+ arc_hidden, rel_hidden, mlp_dropout = config.arc_hidden, config.rel_hidden, config.mlp_dropout
236
+
237
+ self.upos_classifier = nn.Linear(config.hidden_size, self.num_upos_labels)
238
+ nn.init.xavier_uniform_(self.upos_classifier.weight)
239
+ nn.init.zeros_(self.upos_classifier.bias)
240
+
241
+ self.arc_head_mlp = MLP(config.hidden_size, arc_hidden, mlp_dropout)
242
+ self.arc_dep_mlp = MLP(config.hidden_size, arc_hidden, mlp_dropout)
243
+ self.rel_head_mlp = MLP(config.hidden_size, rel_hidden, mlp_dropout)
244
+ self.rel_dep_mlp = MLP(config.hidden_size, rel_hidden, mlp_dropout)
245
+
246
+ self.arc_biaffine = Biaffine(arc_hidden, out_features=1, bias_x=True, bias_y=False)
247
+ self.rel_biaffine = Biaffine(rel_hidden, out_features=self.num_deprel_labels, bias_x=True, bias_y=True)
248
+
249
+ def _heads_forward(self, seq, attention_mask, deprel_label, upos_label, head_label):
250
+ seq = self.dropout(seq)
251
+ B, L, _ = seq.shape
252
+
253
+ logits_upos = self.upos_classifier(seq)
254
+
255
+ logits_head = self.arc_biaffine(self.arc_dep_mlp(seq), self.arc_head_mlp(seq)).squeeze(1)
256
+ if self.training and logits_head.abs().max() > 1e4:
257
+ raise RuntimeError(f"logits_head.abs().max()={logits_head.abs().max():.3e}")
258
+ if attention_mask is not None:
259
+ logits_head = logits_head.masked_fill((attention_mask == 0).unsqueeze(1), -1e4)
260
+
261
+ logits_rel = self.rel_biaffine(self.rel_dep_mlp(seq), self.rel_head_mlp(seq)) # [B, R, L, L]
262
+ logits_rel_t = logits_rel.permute(0, 2, 3, 1).contiguous() # [B, L, L, R]
263
+
264
+ # DEPREL evaluated at the predicted head
265
+ arc_preds = logits_head.argmax(-1).clamp(0, L - 1)
266
+ idx_pred = arc_preds.unsqueeze(-1).unsqueeze(-1).expand(B, L, 1, self.num_deprel_labels)
267
+ logits_deprel_out = logits_rel_t.gather(2, idx_pred).squeeze(2)
268
+
269
+ if head_label is None or deprel_label is None or upos_label is None:
270
+ return logits_deprel_out, logits_upos, logits_head
271
+
272
+ loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
273
+ oob_mask = (head_label != -100) & (head_label >= L)
274
+ head_label_clean = head_label.clone()
275
+ deprel_label_clean = deprel_label.clone()
276
+ head_label_clean[oob_mask] = -100
277
+ deprel_label_clean[oob_mask] = -100
278
+
279
+ loss_head = loss_fct(logits_head.reshape(B * L, L), head_label_clean.reshape(-1))
280
+
281
+ # DEPREL loss with teacher forcing on the gold head
282
+ safe_heads = head_label_clean.clamp(0, L - 1)
283
+ idx_gold = safe_heads.unsqueeze(-1).unsqueeze(-1).expand(B, L, 1, self.num_deprel_labels)
284
+ logits_deprel_gold = logits_rel_t.gather(2, idx_gold).squeeze(2)
285
+ loss_deprel = loss_fct(logits_deprel_gold.reshape(B * L, self.num_deprel_labels), deprel_label_clean.reshape(-1))
286
+
287
+ loss_upos = loss_fct(logits_upos.reshape(B * L, self.num_upos_labels), upos_label.reshape(-1))
288
+
289
+ for name, val in [("loss_head", loss_head), ("loss_deprel", loss_deprel), ("loss_upos", loss_upos)]:
290
+ if torch.isnan(val) or torch.isinf(val):
291
+ raise RuntimeError(f"{name}={val.item():.4e}")
292
+
293
+ return loss_head + loss_deprel + loss_upos, logits_deprel_out, logits_upos, logits_head
294
+
295
+
296
+ class HubParserBiaffine(HubParserMixin, _BiaffineHeads, BertPreTrainedModel):
297
+ config_class = BertConfig
298
+
299
+ def __init__(self, config):
300
+ super().__init__(config)
301
+ self.bert = BertModel(config, add_pooling_layer=False)
302
+ encoder_dropout = (
303
+ config.classifier_dropout if getattr(config, "classifier_dropout", None) is not None
304
+ else config.hidden_dropout_prob
305
+ )
306
+ self.dropout = nn.Dropout(encoder_dropout)
307
+ self._build_heads(config)
308
+ self.post_init()
309
+
310
+ def _init_weights(self, module):
311
+ _init_biaffine_weights(self, module)
312
+
313
+ def _encode(self, inputs):
314
+ return self.bert(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"],
315
+ token_type_ids=inputs.get("token_type_ids")).last_hidden_state
316
+
317
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None,
318
+ deprel_label=None, upos_label=None, head_label=None):
319
+ seq = self.bert(input_ids=input_ids, attention_mask=attention_mask,
320
+ token_type_ids=token_type_ids).last_hidden_state
321
+ return self._heads_forward(seq, attention_mask, deprel_label, upos_label, head_label)
322
+
323
+
324
+ class HubParserBiaffineModernBert(HubParserMixin, _BiaffineHeads, ModernBertPreTrainedModel):
325
+ config_class = ModernBertConfig
326
+
327
+ def __init__(self, config):
328
+ super().__init__(config)
329
+ self.model = ModernBertModel(config)
330
+ encoder_dropout = (
331
+ getattr(config, "classifier_dropout", None)
332
+ or getattr(config, "hidden_dropout_prob", None)
333
+ or getattr(config, "embedding_dropout", 0.1)
334
+ )
335
+ self.dropout = nn.Dropout(encoder_dropout)
336
+ self._build_heads(config)
337
+ self.post_init()
338
+
339
+ def _init_weights(self, module):
340
+ _init_biaffine_weights(self, module)
341
+
342
+ def _encode(self, inputs):
343
+ return self.model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"]).last_hidden_state
344
+
345
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None,
346
+ deprel_label=None, upos_label=None, head_label=None):
347
+ seq = self.model(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
348
+ return self._heads_forward(seq, attention_mask, deprel_label, upos_label, head_label)
349
+
350
+
351
+ def hubparser_class(head: str, model_type: str):
352
+ modern = model_type == "modernbert"
353
+ if head == "linear":
354
+ return HubParserLinearModernBert if modern else HubParserLinear
355
+ return HubParserBiaffineModernBert if modern else HubParserBiaffine
356
+
357
+ # ═════════════════════════════ tree decoders ═════════════════════════════
358
+ NEG = -1e9
359
+
360
+
361
+ def _arc_matrix(S):
362
+ """(n+1, n+1) matrix A[h, d] with A[h, 0] = -inf (nothing heads the root)."""
363
+ n = S.shape[0]
364
+ A = np.full((n + 1, n + 1), NEG)
365
+ A[:, 1:] = S.T
366
+ A[np.arange(n + 1), np.arange(n + 1)] = NEG # no self loops
367
+ return A
368
+
369
+
370
+ def _connected_to_root(heads):
371
+ """heads[d-1] in 0..n or None (detached). Returns ok[v] = v reaches the root."""
372
+ n = len(heads)
373
+ ok = [False] * (n + 1)
374
+ ok[0] = True
375
+ for start in range(1, n + 1):
376
+ path, cur = [], start
377
+ while cur is not None and cur != 0 and not ok[cur] and cur not in path:
378
+ path.append(cur)
379
+ cur = heads[cur - 1]
380
+ if cur is not None and ok[cur]:
381
+ for p in path:
382
+ ok[p] = True
383
+ return ok
384
+
385
+
386
+ # ─────────────────────────────────────────────────────────────────────────────
387
+ # 4. Eisner (projective, exactly one root child)
388
+ # ─────────────────────────────────────────────────────────────────────────────
389
+ def _eisner_tables(A):
390
+ """Inside tables over words 1..n. A[h, d] arc scores. Returns C, I, backpointers."""
391
+ n = A.shape[0] - 1
392
+ # C[s,t,0]: complete span, head t (left-pointing); C[s,t,1]: head s (right-pointing)
393
+ C = np.full((n + 2, n + 2, 2), NEG)
394
+ I = np.full((n + 2, n + 2, 2), NEG)
395
+ bC = np.zeros((n + 2, n + 2, 2), dtype=int)
396
+ bI = np.zeros((n + 2, n + 2, 2), dtype=int)
397
+ for s in range(1, n + 1):
398
+ C[s, s, 0] = C[s, s, 1] = 0.0
399
+ for k in range(1, n):
400
+ for s in range(1, n - k + 1):
401
+ t = s + k
402
+ vals = C[s, s:t, 1] + C[s + 1:t + 1, t, 0]
403
+ r = int(np.argmax(vals))
404
+ I[s, t, 0] = vals[r] + A[t, s]
405
+ I[s, t, 1] = vals[r] + A[s, t]
406
+ bI[s, t, 0] = bI[s, t, 1] = s + r
407
+ vals = C[s, s:t, 0] + I[s:t, t, 0]
408
+ r = int(np.argmax(vals))
409
+ C[s, t, 0] = vals[r]
410
+ bC[s, t, 0] = s + r
411
+ vals = I[s, s + 1:t + 1, 1] + C[s + 1:t + 1, t, 1]
412
+ r = int(np.argmax(vals))
413
+ C[s, t, 1] = vals[r]
414
+ bC[s, t, 1] = s + 1 + r
415
+ return C, I, bC, bI
416
+
417
+
418
+ def eisner(S):
419
+ n = S.shape[0]
420
+ A = _arc_matrix(S)
421
+ C, I, bC, bI = _eisner_tables(A)
422
+ root_scores = [A[0, r] + C[1, r, 0] + C[r, n, 1] for r in range(1, n + 1)]
423
+ r = 1 + int(np.argmax(root_scores))
424
+ heads = [0] * n
425
+ heads[r - 1] = 0
426
+
427
+ def back_C(s, t, d):
428
+ if s == t:
429
+ return
430
+ m = bC[s, t, d]
431
+ if d == 0:
432
+ back_C(s, m, 0)
433
+ back_I(m, t, 0)
434
+ else:
435
+ back_I(s, m, 1)
436
+ back_C(m, t, 1)
437
+
438
+ def back_I(s, t, d):
439
+ m = bI[s, t, d]
440
+ if d == 0:
441
+ heads[s - 1] = t
442
+ else:
443
+ heads[t - 1] = s
444
+ back_C(s, m, 1)
445
+ back_C(m + 1, t, 0)
446
+
447
+ back_C(1, r, 0)
448
+ back_C(r, n, 1)
449
+ return heads
450
+
451
+
452
+ # ─────────────────────────────────────────────────────────────────────────────
453
+ # 5. Chu-Liu/Edmonds (non-projective MST, exactly one root child)
454
+ # ─────────────────────────────────────────────────────────────────────────────
455
+ def _find_cycle(heads):
456
+ n = len(heads) - 1 # heads[0] unused
457
+ color = [0] * (n + 1)
458
+ for start in range(1, n + 1):
459
+ path, cur = [], start
460
+ while cur != 0 and color[cur] == 0:
461
+ color[cur] = 1
462
+ path.append(cur)
463
+ cur = heads[cur]
464
+ if cur != 0 and color[cur] == 1:
465
+ return path[path.index(cur):]
466
+ for p in path:
467
+ color[p] = 2
468
+ return None
469
+
470
+
471
+ def _cle(A):
472
+ """A[h, d], nodes 0..n with 0 = root. Returns heads[d] for d=1..n (index 0 unused)."""
473
+ n = A.shape[0] - 1
474
+ heads = [0] + [int(np.argmax(A[:, d])) for d in range(1, n + 1)]
475
+ cycle = _find_cycle(heads)
476
+ if cycle is None:
477
+ return heads
478
+ cyc = set(cycle)
479
+ rest = [v for v in range(n + 1) if v not in cyc] # rest[0] == 0
480
+ idx = {v: i for i, v in enumerate(rest)}
481
+ c = len(rest) # contracted node id
482
+ B = np.full((c + 1, c + 1), NEG)
483
+ enter_from, leave_to = {}, {}
484
+ cyc_score = sum(A[heads[v], v] for v in cycle)
485
+ for u in rest:
486
+ for v in rest:
487
+ if u != v:
488
+ B[idx[u], idx[v]] = A[u, v]
489
+ # arc entering the cycle from u: replace one cycle arc
490
+ gains = [(A[u, v] - A[heads[v], v], v) for v in cycle]
491
+ g, v = max(gains)
492
+ B[idx[u], c] = cyc_score + g
493
+ enter_from[u] = v
494
+ # arc leaving the cycle to u
495
+ if u != 0:
496
+ s, w = max((A[w, u], w) for w in cycle)
497
+ B[c, idx[u]] = s
498
+ leave_to[u] = w
499
+ sub = _cle(B)
500
+ out = list(heads)
501
+ for u in rest[1:]:
502
+ h = sub[idx[u]]
503
+ out[u] = leave_to[u] if h == c else rest[h]
504
+ u = rest[sub[c]]
505
+ out[enter_from[u]] = u
506
+ return out
507
+
508
+
509
+ def chu_liu_edmonds(S):
510
+ n = S.shape[0]
511
+ A = _arc_matrix(S)
512
+ heads = _cle(A)[1:]
513
+ roots = [d for d in range(1, n + 1) if heads[d - 1] == 0]
514
+ if len(roots) == 1:
515
+ return heads
516
+ # one-root constraint: try each root child, keep the best tree
517
+ best, best_score = None, -np.inf
518
+ for r in range(1, n + 1):
519
+ B = A.copy()
520
+ B[0, :] = NEG
521
+ B[0, r] = A[0, r]
522
+ h = _cle(B)[1:]
523
+ sc = sum(A[h[d - 1], d] for d in range(1, n + 1))
524
+ if sc > best_score:
525
+ best, best_score = h, sc
526
+ return best
527
+
528
+
529
+
530
+
531
+ # ═════════════════════════ complete parser (LEMMA + FEATS) ═════════════════════════
532
+ def apply_rule(form: str, rule: str) -> str:
533
+ """Lemma edit rule "casing|cut|suffix": casing k = form as is, l = lowercased;
534
+ cut = characters removed from the end; suffix = string appended."""
535
+ casing, cut, add = rule.split("|", 2)
536
+ f = form if casing == "k" else form.lower()
537
+ cut = int(cut)
538
+ return (f[:len(f) - cut] if cut else f) + add
539
+
540
+
541
+ class _FullExtra:
542
+ """Two per-word linear classifiers on the encoder output: lemma rule and feature bundle."""
543
+
544
+ def _build_extra(self, config):
545
+ h = config.hidden_size
546
+ self.lemma_classifier = nn.Linear(h, len(config.lemma_rules))
547
+ self.feats_classifier = nn.Linear(h, len(config.feats_labels))
548
+ for m in (self.lemma_classifier, self.feats_classifier):
549
+ nn.init.normal_(m.weight, std=config.initializer_range)
550
+ nn.init.zeros_(m.bias)
551
+
552
+ def _extra_logits(self, seq):
553
+ seq = self.dropout(seq)
554
+ return self.lemma_classifier(seq), self.feats_classifier(seq)
555
+
556
+ def _extra_loss(self, ll, lf, lemma_label, feats_label):
557
+ ce = nn.CrossEntropyLoss(ignore_index=-100)
558
+ return (ce(ll.reshape(-1, ll.shape[-1]), lemma_label.reshape(-1))
559
+ + ce(lf.reshape(-1, lf.shape[-1]), feats_label.reshape(-1)))
560
+
561
+ @torch.no_grad()
562
+ def lemma_feats(self, enc_one, first_pos):
563
+ inputs = {k: v.to(self.device) for k, v in enc_one.items()}
564
+ ll, lf = self._extra_logits(self._encode(inputs))
565
+ return ll[0, first_pos].argmax(-1).tolist(), lf[0, first_pos].argmax(-1).tolist()
566
+
567
+ @torch.no_grad()
568
+ def parse(self, sentences: List[List[str]], tokenizer, decoding: str = "greedy", max_length: int = 512):
569
+ """Parse pre-tokenized sentences. decoding = "greedy", "eisner" (projective) or "mst"
570
+ (non-projective). Returns, per sentence, a list of dicts
571
+ {id, form, lemma, upos, feats, head, deprel}."""
572
+ parsed = super().parse(sentences, tokenizer, decoding=decoding, max_length=max_length)
573
+ for words, sent in zip(sentences, parsed):
574
+ enc = tokenizer([words], is_split_into_words=True, truncation=True, max_length=max_length,
575
+ return_tensors="pt")
576
+ first = {}
577
+ for p, w in enumerate(enc.word_ids(0)):
578
+ if w is not None and w not in first:
579
+ first[w] = p
580
+ rl, rf = self.lemma_feats(dict(enc), [first[i] for i in range(len(first))])
581
+ for tok_, r, f in zip(sent, rl, rf):
582
+ tok_["lemma"] = apply_rule(tok_["form"], self.config.lemma_rules[r])
583
+ tok_["feats"] = self.config.feats_labels[f]
584
+ return [[{k: t[k] for k in ("id", "form", "lemma", "upos", "feats", "head", "deprel")} for t in s]
585
+ for s in parsed]
586
+
587
+ @staticmethod
588
+ def to_conllu(parsed) -> str:
589
+ """CoNLL-U text for the output of parse()."""
590
+ lines = []
591
+ for sent in parsed:
592
+ for t in sent:
593
+ lines.append(f"{t['id']}\t{t['form']}\t{t['lemma']}\t{t['upos']}\t_\t{t['feats']}\t{t['head']}\t{t['deprel']}\t_\t_")
594
+ lines.append("")
595
+ return "\n".join(lines) + "\n"
596
+
597
+
598
+ class HubParserFullLinear(_FullExtra, HubParserLinear):
599
+ def __init__(self, config):
600
+ super().__init__(config)
601
+ self._build_extra(config)
602
+
603
+ def _encode(self, inputs):
604
+ kw = {"input_ids": inputs["input_ids"], "attention_mask": inputs["attention_mask"]}
605
+ if inputs.get("token_type_ids") is not None:
606
+ kw["token_type_ids"] = inputs["token_type_ids"]
607
+ return self.bert(**kw)[0]
608
+
609
+ @torch.no_grad()
610
+ def _sentence_outputs(self, enc_one):
611
+ inputs = {k: v.to(self.device) for k, v in enc_one.items()}
612
+ d, u, h = self(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"],
613
+ token_type_ids=inputs.get("token_type_ids"))[:3]
614
+ return u[0], h[0], d[0], None
615
+
616
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None, deprel_label=None, upos_label=None,
617
+ head_label=None, lemma_label=None, feats_label=None):
618
+ seq_raw = self._encode({"input_ids": input_ids, "attention_mask": attention_mask,
619
+ "token_type_ids": token_type_ids})
620
+ seq = self.dropout(seq_raw)
621
+ d, u, h = self.deprel_classifier(seq), self.upos_classifier(seq), self.head_classifier(seq)
622
+ ll, lf = self._extra_logits(seq_raw)
623
+ if head_label is None:
624
+ return d, u, h, ll, lf
625
+ ce = nn.CrossEntropyLoss(ignore_index=-100)
626
+ loss = (ce(d.view(-1, d.shape[-1]), deprel_label.view(-1)) + ce(u.view(-1, u.shape[-1]), upos_label.view(-1))
627
+ + ce(h.view(-1, h.shape[-1]), head_label.view(-1)) + self._extra_loss(ll, lf, lemma_label, feats_label))
628
+ return loss, d, u, h, ll, lf
629
+
630
+
631
+ class HubParserFullBiaffine(_FullExtra, HubParserBiaffine):
632
+ def __init__(self, config):
633
+ super().__init__(config)
634
+ self._build_extra(config)
635
+
636
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None, deprel_label=None, upos_label=None,
637
+ head_label=None, lemma_label=None, feats_label=None):
638
+ seq = self.bert(input_ids=input_ids, attention_mask=attention_mask,
639
+ token_type_ids=token_type_ids).last_hidden_state
640
+ out = self._heads_forward(seq, attention_mask, deprel_label, upos_label, head_label)
641
+ ll, lf = self._extra_logits(seq)
642
+ if head_label is None:
643
+ return (*out, ll, lf)
644
+ return (out[0] + self._extra_loss(ll, lf, lemma_label, feats_label), *out[1:], ll, lf)
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": false,
5
+ "is_local": false,
6
+ "local_files_only": false,
7
+ "mask_token": "[MASK]",
8
+ "model_max_length": 1000000000000000019884624838656,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }