KoichiYasuoka commited on
Commit
31088a4
·
1 Parent(s): 3be54c8

initial release

Browse files
Files changed (10) hide show
  1. README.md +30 -0
  2. added_tokens.json +5 -0
  3. config.json +500 -0
  4. maker.py +101 -0
  5. merges.txt +0 -0
  6. pytorch_model.bin +3 -0
  7. special_tokens_map.json +20 -0
  8. tokenizer_config.json +44 -0
  9. ud.py +159 -0
  10. vocab.json +0 -0
README.md ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - "ja"
4
+ tags:
5
+ - "japanese"
6
+ - "pos"
7
+ - "dependency-parsing"
8
+ base_model: Kendamarron/Tokara-0.5B-v0.1
9
+ datasets:
10
+ - "universal_dependencies"
11
+ license: "apache-2.0"
12
+ pipeline_tag: "token-classification"
13
+ widget:
14
+ - text: "全学年にわたって小学校の国語の教科書に挿し絵が用いられている"
15
+ ---
16
+
17
+ # Tokara-0.5B-ud-embeds
18
+
19
+ ## Model Description
20
+
21
+ This is a Qwen1.5 model pretrained for POS-tagging and dependency-parsing, derived from [Tokara-0.5B-v0.1](https://huggingface.co/Kendamarron/Tokara-0.5B-v0.1) refined for [UD_Japanese-GSDLUW](https://github.com/UniversalDependencies/UD_Japanese-GSDLUW).
22
+
23
+ ## How to Use
24
+
25
+ ```
26
+ from transformers import pipeline
27
+ nlp=pipeline("universal-dependencies","KoichiYasuoka/Tokara-0.5B-ud-embeds",trust_remote_code=True)
28
+ print(nlp("全学年にわたって小学校の国語の教科書に挿し絵が用いられている"))
29
+ ```
30
+
added_tokens.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "<|endoftext|>": 151643,
3
+ "<|im_end|>": 151645,
4
+ "<|im_start|>": 151644
5
+ }
config.json ADDED
@@ -0,0 +1,500 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForTokenClassification"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "custom_pipelines": {
8
+ "upos": {
9
+ "impl": "ud.BellmanFordTokenClassificationPipeline",
10
+ "pt": "AutoModelForTokenClassification"
11
+ },
12
+ "universal-dependencies": {
13
+ "impl": "ud.UniversalDependenciesPipeline",
14
+ "pt": "AutoModelForTokenClassification"
15
+ }
16
+ },
17
+ "eos_token_id": 151643,
18
+ "hidden_act": "silu",
19
+ "hidden_size": 1024,
20
+ "id2label": {
21
+ "0": "ADJ",
22
+ "1": "ADJ.",
23
+ "2": "ADJ|_",
24
+ "3": "ADJ|l-acl",
25
+ "4": "ADJ|l-advcl",
26
+ "5": "ADJ|l-amod",
27
+ "6": "ADJ|l-ccomp",
28
+ "7": "ADJ|l-csubj",
29
+ "8": "ADJ|l-csubj:outer",
30
+ "9": "ADJ|l-nmod",
31
+ "10": "ADJ|l-nsubj",
32
+ "11": "ADJ|l-obj",
33
+ "12": "ADJ|l-obl",
34
+ "13": "ADJ|r-acl",
35
+ "14": "ADJ|r-amod",
36
+ "15": "ADJ|r-dep",
37
+ "16": "ADJ|root",
38
+ "17": "ADP",
39
+ "18": "ADP.",
40
+ "19": "ADP|_",
41
+ "20": "ADP|l-case",
42
+ "21": "ADP|r-case",
43
+ "22": "ADP|r-fixed",
44
+ "23": "ADV",
45
+ "24": "ADV.",
46
+ "25": "ADV|_",
47
+ "26": "ADV|l-advcl",
48
+ "27": "ADV|l-advmod",
49
+ "28": "ADV|l-obj",
50
+ "29": "ADV|r-dep",
51
+ "30": "ADV|root",
52
+ "31": "AUX",
53
+ "32": "AUX.",
54
+ "33": "AUX|Polarity=Neg|_",
55
+ "34": "AUX|Polarity=Neg|r-aux",
56
+ "35": "AUX|Polarity=Neg|r-fixed",
57
+ "36": "AUX|_",
58
+ "37": "AUX|r-aux",
59
+ "38": "AUX|r-cop",
60
+ "39": "AUX|r-fixed",
61
+ "40": "AUX|root",
62
+ "41": "B-ADJ",
63
+ "42": "B-ADJ.",
64
+ "43": "B-ADP",
65
+ "44": "B-ADP.",
66
+ "45": "B-ADV",
67
+ "46": "B-ADV.",
68
+ "47": "B-AUX",
69
+ "48": "B-AUX.",
70
+ "49": "B-CCONJ",
71
+ "50": "B-CCONJ.",
72
+ "51": "B-DET",
73
+ "52": "B-DET.",
74
+ "53": "B-INTJ",
75
+ "54": "B-INTJ.",
76
+ "55": "B-NOUN",
77
+ "56": "B-NOUN.",
78
+ "57": "B-NUM",
79
+ "58": "B-NUM.",
80
+ "59": "B-PART",
81
+ "60": "B-PART.",
82
+ "61": "B-PRON",
83
+ "62": "B-PRON.",
84
+ "63": "B-PROPN",
85
+ "64": "B-PROPN.",
86
+ "65": "B-PUNCT",
87
+ "66": "B-PUNCT.",
88
+ "67": "B-SCONJ",
89
+ "68": "B-SCONJ.",
90
+ "69": "B-SYM",
91
+ "70": "B-SYM.",
92
+ "71": "B-VERB",
93
+ "72": "B-VERB.",
94
+ "73": "B-X",
95
+ "74": "B-X.",
96
+ "75": "CCONJ",
97
+ "76": "CCONJ.",
98
+ "77": "CCONJ|_",
99
+ "78": "CCONJ|l-cc",
100
+ "79": "CCONJ|r-cc",
101
+ "80": "DET",
102
+ "81": "DET.",
103
+ "82": "DET|_",
104
+ "83": "DET|l-det",
105
+ "84": "I-ADJ",
106
+ "85": "I-ADJ.",
107
+ "86": "I-ADP",
108
+ "87": "I-ADP.",
109
+ "88": "I-ADV",
110
+ "89": "I-ADV.",
111
+ "90": "I-AUX",
112
+ "91": "I-AUX.",
113
+ "92": "I-CCONJ",
114
+ "93": "I-CCONJ.",
115
+ "94": "I-DET",
116
+ "95": "I-DET.",
117
+ "96": "I-INTJ",
118
+ "97": "I-INTJ.",
119
+ "98": "I-NOUN",
120
+ "99": "I-NOUN.",
121
+ "100": "I-NUM",
122
+ "101": "I-NUM.",
123
+ "102": "I-PART",
124
+ "103": "I-PART.",
125
+ "104": "I-PRON",
126
+ "105": "I-PRON.",
127
+ "106": "I-PROPN",
128
+ "107": "I-PROPN.",
129
+ "108": "I-PUNCT",
130
+ "109": "I-PUNCT.",
131
+ "110": "I-SCONJ",
132
+ "111": "I-SCONJ.",
133
+ "112": "I-SYM",
134
+ "113": "I-SYM.",
135
+ "114": "I-VERB",
136
+ "115": "I-VERB.",
137
+ "116": "I-X",
138
+ "117": "I-X.",
139
+ "118": "INTJ",
140
+ "119": "INTJ.",
141
+ "120": "INTJ|_",
142
+ "121": "INTJ|l-discourse",
143
+ "122": "INTJ|r-discourse",
144
+ "123": "INTJ|root",
145
+ "124": "NOUN",
146
+ "125": "NOUN.",
147
+ "126": "NOUN|Polarity=Neg|_",
148
+ "127": "NOUN|Polarity=Neg|l-obl",
149
+ "128": "NOUN|Polarity=Neg|root",
150
+ "129": "NOUN|_",
151
+ "130": "NOUN|l-acl",
152
+ "131": "NOUN|l-advcl",
153
+ "132": "NOUN|l-ccomp",
154
+ "133": "NOUN|l-compound",
155
+ "134": "NOUN|l-csubj",
156
+ "135": "NOUN|l-csubj:outer",
157
+ "136": "NOUN|l-nmod",
158
+ "137": "NOUN|l-nsubj",
159
+ "138": "NOUN|l-nsubj:outer",
160
+ "139": "NOUN|l-obj",
161
+ "140": "NOUN|l-obl",
162
+ "141": "NOUN|r-compound",
163
+ "142": "NOUN|r-nmod",
164
+ "143": "NOUN|r-nsubj",
165
+ "144": "NOUN|root",
166
+ "145": "NUM",
167
+ "146": "NUM.",
168
+ "147": "NUM|_",
169
+ "148": "NUM|l-advcl",
170
+ "149": "NUM|l-compound",
171
+ "150": "NUM|l-nmod",
172
+ "151": "NUM|l-nsubj",
173
+ "152": "NUM|l-nsubj:outer",
174
+ "153": "NUM|l-nummod",
175
+ "154": "NUM|l-obj",
176
+ "155": "NUM|l-obl",
177
+ "156": "NUM|r-compound",
178
+ "157": "NUM|root",
179
+ "158": "PART",
180
+ "159": "PART.",
181
+ "160": "PART|_",
182
+ "161": "PART|l-mark",
183
+ "162": "PART|r-mark",
184
+ "163": "PRON",
185
+ "164": "PRON.",
186
+ "165": "PRON|_",
187
+ "166": "PRON|l-acl",
188
+ "167": "PRON|l-advcl",
189
+ "168": "PRON|l-nmod",
190
+ "169": "PRON|l-nsubj",
191
+ "170": "PRON|l-nsubj:outer",
192
+ "171": "PRON|l-obj",
193
+ "172": "PRON|l-obl",
194
+ "173": "PRON|root",
195
+ "174": "PROPN",
196
+ "175": "PROPN.",
197
+ "176": "PROPN|_",
198
+ "177": "PROPN|l-acl",
199
+ "178": "PROPN|l-advcl",
200
+ "179": "PROPN|l-compound",
201
+ "180": "PROPN|l-nmod",
202
+ "181": "PROPN|l-nsubj",
203
+ "182": "PROPN|l-nsubj:outer",
204
+ "183": "PROPN|l-obj",
205
+ "184": "PROPN|l-obl",
206
+ "185": "PROPN|r-compound",
207
+ "186": "PROPN|r-nmod",
208
+ "187": "PROPN|root",
209
+ "188": "PUNCT",
210
+ "189": "PUNCT.",
211
+ "190": "PUNCT|_",
212
+ "191": "PUNCT|l-punct",
213
+ "192": "PUNCT|r-punct",
214
+ "193": "SCONJ",
215
+ "194": "SCONJ.",
216
+ "195": "SCONJ|_",
217
+ "196": "SCONJ|l-dep",
218
+ "197": "SCONJ|r-fixed",
219
+ "198": "SCONJ|r-mark",
220
+ "199": "SYM",
221
+ "200": "SYM.",
222
+ "201": "SYM|_",
223
+ "202": "SYM|l-compound",
224
+ "203": "SYM|l-dep",
225
+ "204": "SYM|l-nmod",
226
+ "205": "SYM|l-obl",
227
+ "206": "SYM|r-compound",
228
+ "207": "SYM|r-dep",
229
+ "208": "VERB",
230
+ "209": "VERB.",
231
+ "210": "VERB|_",
232
+ "211": "VERB|l-acl",
233
+ "212": "VERB|l-advcl",
234
+ "213": "VERB|l-ccomp",
235
+ "214": "VERB|l-compound",
236
+ "215": "VERB|l-csubj",
237
+ "216": "VERB|l-csubj:outer",
238
+ "217": "VERB|l-nmod",
239
+ "218": "VERB|l-obj",
240
+ "219": "VERB|l-obl",
241
+ "220": "VERB|r-acl",
242
+ "221": "VERB|r-advcl",
243
+ "222": "VERB|r-compound",
244
+ "223": "VERB|root",
245
+ "224": "X",
246
+ "225": "X.",
247
+ "226": "X|_",
248
+ "227": "X|l-nmod",
249
+ "228": "X|r-dep"
250
+ },
251
+ "initializer_range": 0.02,
252
+ "intermediate_size": 2816,
253
+ "label2id": {
254
+ "ADJ": 0,
255
+ "ADJ.": 1,
256
+ "ADJ|_": 2,
257
+ "ADJ|l-acl": 3,
258
+ "ADJ|l-advcl": 4,
259
+ "ADJ|l-amod": 5,
260
+ "ADJ|l-ccomp": 6,
261
+ "ADJ|l-csubj": 7,
262
+ "ADJ|l-csubj:outer": 8,
263
+ "ADJ|l-nmod": 9,
264
+ "ADJ|l-nsubj": 10,
265
+ "ADJ|l-obj": 11,
266
+ "ADJ|l-obl": 12,
267
+ "ADJ|r-acl": 13,
268
+ "ADJ|r-amod": 14,
269
+ "ADJ|r-dep": 15,
270
+ "ADJ|root": 16,
271
+ "ADP": 17,
272
+ "ADP.": 18,
273
+ "ADP|_": 19,
274
+ "ADP|l-case": 20,
275
+ "ADP|r-case": 21,
276
+ "ADP|r-fixed": 22,
277
+ "ADV": 23,
278
+ "ADV.": 24,
279
+ "ADV|_": 25,
280
+ "ADV|l-advcl": 26,
281
+ "ADV|l-advmod": 27,
282
+ "ADV|l-obj": 28,
283
+ "ADV|r-dep": 29,
284
+ "ADV|root": 30,
285
+ "AUX": 31,
286
+ "AUX.": 32,
287
+ "AUX|Polarity=Neg|_": 33,
288
+ "AUX|Polarity=Neg|r-aux": 34,
289
+ "AUX|Polarity=Neg|r-fixed": 35,
290
+ "AUX|_": 36,
291
+ "AUX|r-aux": 37,
292
+ "AUX|r-cop": 38,
293
+ "AUX|r-fixed": 39,
294
+ "AUX|root": 40,
295
+ "B-ADJ": 41,
296
+ "B-ADJ.": 42,
297
+ "B-ADP": 43,
298
+ "B-ADP.": 44,
299
+ "B-ADV": 45,
300
+ "B-ADV.": 46,
301
+ "B-AUX": 47,
302
+ "B-AUX.": 48,
303
+ "B-CCONJ": 49,
304
+ "B-CCONJ.": 50,
305
+ "B-DET": 51,
306
+ "B-DET.": 52,
307
+ "B-INTJ": 53,
308
+ "B-INTJ.": 54,
309
+ "B-NOUN": 55,
310
+ "B-NOUN.": 56,
311
+ "B-NUM": 57,
312
+ "B-NUM.": 58,
313
+ "B-PART": 59,
314
+ "B-PART.": 60,
315
+ "B-PRON": 61,
316
+ "B-PRON.": 62,
317
+ "B-PROPN": 63,
318
+ "B-PROPN.": 64,
319
+ "B-PUNCT": 65,
320
+ "B-PUNCT.": 66,
321
+ "B-SCONJ": 67,
322
+ "B-SCONJ.": 68,
323
+ "B-SYM": 69,
324
+ "B-SYM.": 70,
325
+ "B-VERB": 71,
326
+ "B-VERB.": 72,
327
+ "B-X": 73,
328
+ "B-X.": 74,
329
+ "CCONJ": 75,
330
+ "CCONJ.": 76,
331
+ "CCONJ|_": 77,
332
+ "CCONJ|l-cc": 78,
333
+ "CCONJ|r-cc": 79,
334
+ "DET": 80,
335
+ "DET.": 81,
336
+ "DET|_": 82,
337
+ "DET|l-det": 83,
338
+ "I-ADJ": 84,
339
+ "I-ADJ.": 85,
340
+ "I-ADP": 86,
341
+ "I-ADP.": 87,
342
+ "I-ADV": 88,
343
+ "I-ADV.": 89,
344
+ "I-AUX": 90,
345
+ "I-AUX.": 91,
346
+ "I-CCONJ": 92,
347
+ "I-CCONJ.": 93,
348
+ "I-DET": 94,
349
+ "I-DET.": 95,
350
+ "I-INTJ": 96,
351
+ "I-INTJ.": 97,
352
+ "I-NOUN": 98,
353
+ "I-NOUN.": 99,
354
+ "I-NUM": 100,
355
+ "I-NUM.": 101,
356
+ "I-PART": 102,
357
+ "I-PART.": 103,
358
+ "I-PRON": 104,
359
+ "I-PRON.": 105,
360
+ "I-PROPN": 106,
361
+ "I-PROPN.": 107,
362
+ "I-PUNCT": 108,
363
+ "I-PUNCT.": 109,
364
+ "I-SCONJ": 110,
365
+ "I-SCONJ.": 111,
366
+ "I-SYM": 112,
367
+ "I-SYM.": 113,
368
+ "I-VERB": 114,
369
+ "I-VERB.": 115,
370
+ "I-X": 116,
371
+ "I-X.": 117,
372
+ "INTJ": 118,
373
+ "INTJ.": 119,
374
+ "INTJ|_": 120,
375
+ "INTJ|l-discourse": 121,
376
+ "INTJ|r-discourse": 122,
377
+ "INTJ|root": 123,
378
+ "NOUN": 124,
379
+ "NOUN.": 125,
380
+ "NOUN|Polarity=Neg|_": 126,
381
+ "NOUN|Polarity=Neg|l-obl": 127,
382
+ "NOUN|Polarity=Neg|root": 128,
383
+ "NOUN|_": 129,
384
+ "NOUN|l-acl": 130,
385
+ "NOUN|l-advcl": 131,
386
+ "NOUN|l-ccomp": 132,
387
+ "NOUN|l-compound": 133,
388
+ "NOUN|l-csubj": 134,
389
+ "NOUN|l-csubj:outer": 135,
390
+ "NOUN|l-nmod": 136,
391
+ "NOUN|l-nsubj": 137,
392
+ "NOUN|l-nsubj:outer": 138,
393
+ "NOUN|l-obj": 139,
394
+ "NOUN|l-obl": 140,
395
+ "NOUN|r-compound": 141,
396
+ "NOUN|r-nmod": 142,
397
+ "NOUN|r-nsubj": 143,
398
+ "NOUN|root": 144,
399
+ "NUM": 145,
400
+ "NUM.": 146,
401
+ "NUM|_": 147,
402
+ "NUM|l-advcl": 148,
403
+ "NUM|l-compound": 149,
404
+ "NUM|l-nmod": 150,
405
+ "NUM|l-nsubj": 151,
406
+ "NUM|l-nsubj:outer": 152,
407
+ "NUM|l-nummod": 153,
408
+ "NUM|l-obj": 154,
409
+ "NUM|l-obl": 155,
410
+ "NUM|r-compound": 156,
411
+ "NUM|root": 157,
412
+ "PART": 158,
413
+ "PART.": 159,
414
+ "PART|_": 160,
415
+ "PART|l-mark": 161,
416
+ "PART|r-mark": 162,
417
+ "PRON": 163,
418
+ "PRON.": 164,
419
+ "PRON|_": 165,
420
+ "PRON|l-acl": 166,
421
+ "PRON|l-advcl": 167,
422
+ "PRON|l-nmod": 168,
423
+ "PRON|l-nsubj": 169,
424
+ "PRON|l-nsubj:outer": 170,
425
+ "PRON|l-obj": 171,
426
+ "PRON|l-obl": 172,
427
+ "PRON|root": 173,
428
+ "PROPN": 174,
429
+ "PROPN.": 175,
430
+ "PROPN|_": 176,
431
+ "PROPN|l-acl": 177,
432
+ "PROPN|l-advcl": 178,
433
+ "PROPN|l-compound": 179,
434
+ "PROPN|l-nmod": 180,
435
+ "PROPN|l-nsubj": 181,
436
+ "PROPN|l-nsubj:outer": 182,
437
+ "PROPN|l-obj": 183,
438
+ "PROPN|l-obl": 184,
439
+ "PROPN|r-compound": 185,
440
+ "PROPN|r-nmod": 186,
441
+ "PROPN|root": 187,
442
+ "PUNCT": 188,
443
+ "PUNCT.": 189,
444
+ "PUNCT|_": 190,
445
+ "PUNCT|l-punct": 191,
446
+ "PUNCT|r-punct": 192,
447
+ "SCONJ": 193,
448
+ "SCONJ.": 194,
449
+ "SCONJ|_": 195,
450
+ "SCONJ|l-dep": 196,
451
+ "SCONJ|r-fixed": 197,
452
+ "SCONJ|r-mark": 198,
453
+ "SYM": 199,
454
+ "SYM.": 200,
455
+ "SYM|_": 201,
456
+ "SYM|l-compound": 202,
457
+ "SYM|l-dep": 203,
458
+ "SYM|l-nmod": 204,
459
+ "SYM|l-obl": 205,
460
+ "SYM|r-compound": 206,
461
+ "SYM|r-dep": 207,
462
+ "VERB": 208,
463
+ "VERB.": 209,
464
+ "VERB|_": 210,
465
+ "VERB|l-acl": 211,
466
+ "VERB|l-advcl": 212,
467
+ "VERB|l-ccomp": 213,
468
+ "VERB|l-compound": 214,
469
+ "VERB|l-csubj": 215,
470
+ "VERB|l-csubj:outer": 216,
471
+ "VERB|l-nmod": 217,
472
+ "VERB|l-obj": 218,
473
+ "VERB|l-obl": 219,
474
+ "VERB|r-acl": 220,
475
+ "VERB|r-advcl": 221,
476
+ "VERB|r-compound": 222,
477
+ "VERB|root": 223,
478
+ "X": 224,
479
+ "X.": 225,
480
+ "X|_": 226,
481
+ "X|l-nmod": 227,
482
+ "X|r-dep": 228
483
+ },
484
+ "max_position_embeddings": 32768,
485
+ "max_window_layers": 21,
486
+ "model_type": "qwen2",
487
+ "num_attention_heads": 16,
488
+ "num_hidden_layers": 24,
489
+ "num_key_value_heads": 16,
490
+ "rms_norm_eps": 1e-06,
491
+ "rope_scaling": null,
492
+ "rope_theta": 1000000.0,
493
+ "sliding_window": null,
494
+ "tie_word_embeddings": true,
495
+ "torch_dtype": "float32",
496
+ "transformers_version": "4.48.3",
497
+ "use_cache": true,
498
+ "use_sliding_window": false,
499
+ "vocab_size": 151936
500
+ }
maker.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /usr/bin/python3
2
+ src="Kendamarron/Tokara-0.5B-v0.1"
3
+ tgt="KoichiYasuoka/Tokara-0.5B-ud-embeds"
4
+ url="https://github.com/UniversalDependencies/UD_Japanese-GSDLUW"
5
+ import os
6
+ d=os.path.basename(url)
7
+ os.system("test -d "+d+" || git clone --depth=1 "+url)
8
+ os.system("for F in train dev test ; do cp "+d+"/*-$F.conllu $F.conllu ; done")
9
+ class UDEmbedsDataset(object):
10
+ def __init__(self,conllu,tokenizer,oldtokenizer=None,embeddings=None):
11
+ self.conllu=open(conllu,"r",encoding="utf-8")
12
+ self.tokenizer=tokenizer
13
+ self.oldtokenizer=oldtokenizer if oldtokenizer else tokenizer
14
+ self.embeddings=embeddings
15
+ self.seeks=[0]
16
+ label=set(["SYM","SYM.","SYM|_"])
17
+ dep=set()
18
+ s=self.conllu.readline()
19
+ while s!="":
20
+ if s=="\n":
21
+ self.seeks.append(self.conllu.tell())
22
+ else:
23
+ w=s.split("\t")
24
+ if len(w)==10:
25
+ if w[0].isdecimal():
26
+ p=w[3]
27
+ q="" if w[5]=="_" else "|"+w[5]
28
+ d=("|" if w[6]=="0" else "|l-" if int(w[0])<int(w[6]) else "|r-")+w[7]
29
+ for k in [p,p+".","B-"+p,"B-"+p+".","I-"+p,"I-"+p+".",p+q+"|_",p+q+d]:
30
+ label.add(k)
31
+ s=self.conllu.readline()
32
+ self.label2id={l:i for i,l in enumerate(sorted(label))}
33
+ def __call__(*args):
34
+ lid={l:i for i,l in enumerate(sorted(set(sum([list(t.label2id) for t in args],[]))))}
35
+ for t in args:
36
+ t.label2id=lid
37
+ return lid
38
+ def __del__(self):
39
+ self.conllu.close()
40
+ __len__=lambda self:len(self.seeks)-1
41
+ def __getitem__(self,i):
42
+ import torch
43
+ self.conllu.seek(self.seeks[i])
44
+ c,t,s=[],[""],False
45
+ while t[0]!="\n":
46
+ t=self.conllu.readline().split("\t")
47
+ if len(t)==10 and t[0].isdecimal():
48
+ if s:
49
+ t[1]=" "+t[1]
50
+ c.append(t)
51
+ s=t[9].find("SpaceAfter=No")<0
52
+ x=[True if t[6]=="0" or int(t[6])>j or sum([1 if int(c[i][6])==j+1 else 0 for i in range(j+1,len(c))])>0 else False for j,t in enumerate(c)]
53
+ v=self.tokenizer([t[1] for t in c],add_special_tokens=False)["input_ids"]
54
+ ids,upos=[],[]
55
+ for i,(j,k) in enumerate(zip(v,c)):
56
+ if j==[]:
57
+ j=self.tokenizer("〓")["input_ids"]
58
+ p=k[3] if x[i] else k[3]+"."
59
+ ids+=j
60
+ upos+=[p] if len(j)==1 else ["B-"+p]+["I-"+p]*(len(j)-1)
61
+ v=self.oldtokenizer([t[1] for t in c],add_special_tokens=False)["input_ids"]
62
+ p=[t[3] if t[5]=="_" else t[3]+"|"+t[5] for i,t in enumerate(c)]
63
+ d=[t[7] if t[6]=="0" else "l-"+t[7] if int(t[0])<int(t[6]) else "r-"+t[7] for t in c]
64
+ idx=[-1]
65
+ upos.append("SYM|_")
66
+ for i in range(len(x)):
67
+ idx.append(i)
68
+ upos.append(p[i]+"|"+d[i] if c[i][6]=="0" else p[i]+"|_")
69
+ for j in range(i+1,len(x)):
70
+ idx.append(j)
71
+ upos.append(p[j]+"|"+d[j] if int(c[j][6])==i+1 else p[i]+"|"+d[i] if int(c[i][6])==j+1 else p[j]+"|_")
72
+ idx.append(-1)
73
+ upos.append("SYM|_")
74
+ with torch.no_grad():
75
+ m=[]
76
+ for j in v:
77
+ if j==[]:
78
+ j=self.tokenizer("〓")["input_ids"]
79
+ m.append(self.embeddings[j,:].sum(axis=0))
80
+ m.append(self.embeddings[self.tokenizer("<|im_end|>")["input_ids"][0],:])
81
+ emb=torch.stack(m)
82
+ return{"inputs_embeds":torch.vstack((self.embeddings[ids,:],emb[idx,:])),"labels":[self.label2id[p] for p in upos]}
83
+ from transformers import AutoTokenizer,AutoConfig,AutoModelForTokenClassification,DefaultDataCollator,TrainingArguments,Trainer
84
+ from tokenizers.pre_tokenizers import Sequence,Split
85
+ from tokenizers import Regex
86
+ from copy import deepcopy
87
+ otk=AutoTokenizer.from_pretrained(src)
88
+ ntk=deepcopy(otk)
89
+ ntk.backend_tokenizer.pre_tokenizer=Sequence([Split(Regex("[ぁ-ん]"),"isolated"),otk.backend_tokenizer.pre_tokenizer])
90
+ trainDS=UDEmbedsDataset("train.conllu",ntk,otk)
91
+ devDS=UDEmbedsDataset("dev.conllu",ntk,otk)
92
+ testDS=UDEmbedsDataset("test.conllu",ntk,otk)
93
+ lid=trainDS(devDS,testDS)
94
+ cfg=AutoConfig.from_pretrained(src,num_labels=len(lid),label2id=lid,id2label={i:l for l,i in lid.items()},ignore_mismatched_sizes=True,trust_remote_code=True)
95
+ mdl=AutoModelForTokenClassification.from_pretrained(src,config=cfg,ignore_mismatched_sizes=True,trust_remote_code=True)
96
+ trainDS.embeddings=mdl.get_input_embeddings().weight
97
+ arg=TrainingArguments(num_train_epochs=3,per_device_train_batch_size=1,dataloader_pin_memory=False,output_dir=tgt,overwrite_output_dir=True,save_total_limit=2,learning_rate=5e-05,warmup_ratio=0.1,save_safetensors=False)
98
+ trn=Trainer(args=arg,data_collator=DefaultDataCollator(),model=mdl,train_dataset=trainDS)
99
+ trn.train()
100
+ trn.save_model(tgt)
101
+ otk.save_pretrained(tgt)
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa2e032426b5f8645f0b9339d3eb66f94b6f724c7b7f70a4f0d9dbf3cf1a6f61
3
+ size 1856987866
special_tokens_map.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>"
5
+ ],
6
+ "eos_token": {
7
+ "content": "<|endoftext|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "pad_token": {
14
+ "content": "<|endoftext|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ }
20
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_eos_token": true,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "additional_special_tokens": [
31
+ "<|im_start|>",
32
+ "<|im_end|>"
33
+ ],
34
+ "bos_token": "<|endoftext|>",
35
+ "clean_up_tokenization_spaces": false,
36
+ "eos_token": "<|endoftext|>",
37
+ "errors": "replace",
38
+ "extra_special_tokens": {},
39
+ "model_max_length": 32768,
40
+ "pad_token": "<|endoftext|>",
41
+ "split_special_tokens": false,
42
+ "tokenizer_class": "Qwen2Tokenizer",
43
+ "unk_token": null
44
+ }
ud.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy
2
+ from transformers import TokenClassificationPipeline
3
+
4
+ class BellmanFordTokenClassificationPipeline(TokenClassificationPipeline):
5
+ def __init__(self,**kwargs):
6
+ from copy import deepcopy
7
+ from tokenizers import Regex
8
+ from tokenizers.pre_tokenizers import Sequence,Split
9
+ super().__init__(**kwargs)
10
+ self.oldtokenizer=deepcopy(self.tokenizer)
11
+ self.tokenizer.backend_tokenizer.pre_tokenizer=Sequence([Split(Regex("[ぁ-ん]"),"isolated"),self.oldtokenizer.backend_tokenizer.pre_tokenizer])
12
+ x=self.model.config.label2id
13
+ y=[k for k in x if k.find("|")<0 and not k.startswith("I-")]
14
+ self.transition=numpy.full((len(x),len(x)),-numpy.inf)
15
+ for k,v in x.items():
16
+ if k.find("|")<0:
17
+ for j in ["I-"+k[2:]] if k.startswith("B-") else [k]+y if k.startswith("I-") else y:
18
+ self.transition[v,x[j]]=0
19
+ def check_model_type(self,supported_models):
20
+ pass
21
+ def postprocess(self,model_outputs,**kwargs):
22
+ if "logits" not in model_outputs:
23
+ return self.postprocess(model_outputs[0],**kwargs)
24
+ return self.bellman_ford_token_classification(model_outputs,**kwargs)
25
+ def bellman_ford_token_classification(self,model_outputs,**kwargs):
26
+ m=model_outputs["logits"][0].numpy()
27
+ e=numpy.exp(m-numpy.max(m,axis=-1,keepdims=True))
28
+ z=e/e.sum(axis=-1,keepdims=True)
29
+ for i in range(m.shape[0]-1,0,-1):
30
+ m[i-1]+=numpy.max(m[i]+self.transition,axis=1)
31
+ k=[numpy.argmax(m[0]+self.transition[0])]
32
+ for i in range(1,m.shape[0]):
33
+ k.append(numpy.argmax(m[i]+self.transition[k[-1]]))
34
+ w=[{"entity":self.model.config.id2label[j],"start":s,"end":e,"score":z[i,j]} for i,((s,e),j) in enumerate(zip(model_outputs["offset_mapping"][0].tolist(),k)) if s<e]
35
+ if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
36
+ for i,t in reversed(list(enumerate(w))):
37
+ p=t.pop("entity")
38
+ if p.startswith("I-"):
39
+ w[i-1]["score"]=min(w[i-1]["score"],t["score"])
40
+ w[i-1]["end"]=w.pop(i)["end"]
41
+ elif i>0 and w[i-1]["end"]>t["start"]:
42
+ w[i-1]["score"]=min(w[i-1]["score"],t["score"])
43
+ w[i-1]["end"]=w.pop(i)["end"]
44
+ elif p.startswith("B-"):
45
+ t["entity_group"]=p[2:]
46
+ else:
47
+ t["entity_group"]=p
48
+ for t in w:
49
+ t["text"]=model_outputs["sentence"][t["start"]:t["end"]]
50
+ return w
51
+
52
+ class UniversalDependenciesPipeline(BellmanFordTokenClassificationPipeline):
53
+ def __init__(self,**kwargs):
54
+ kwargs["aggregation_strategy"]="simple"
55
+ super().__init__(**kwargs)
56
+ x=self.model.config.label2id
57
+ self.root=numpy.full((len(x)),-numpy.inf)
58
+ self.left_arc=numpy.full((len(x)),-numpy.inf)
59
+ self.right_arc=numpy.full((len(x)),-numpy.inf)
60
+ for k,v in x.items():
61
+ if k.endswith("|root"):
62
+ self.root[v]=0
63
+ elif k.find("|l-")>0:
64
+ self.left_arc[v]=0
65
+ elif k.find("|r-")>0:
66
+ self.right_arc[v]=0
67
+ def postprocess(self,model_outputs,**kwargs):
68
+ import torch
69
+ kwargs["aggregation_strategy"]="simple"
70
+ if "logits" not in model_outputs:
71
+ return self.postprocess(model_outputs[0],**kwargs)
72
+ w=self.bellman_ford_token_classification(model_outputs,**kwargs)
73
+ off=[(t["start"],t["end"]) for t in w]
74
+ for i,(s,e) in reversed(list(enumerate(off))):
75
+ if s<e:
76
+ d=w[i]["text"]
77
+ j=len(d)-len(d.lstrip())
78
+ if j>0:
79
+ d=d.lstrip()
80
+ off[i]=(off[i][0]+j,off[i][1])
81
+ j=len(d)-len(d.rstrip())
82
+ if j>0:
83
+ d=d.rstrip()
84
+ off[i]=(off[i][0],off[i][1]-j)
85
+ if d.strip()=="":
86
+ off.pop(i)
87
+ w.pop(i)
88
+ v=self.oldtokenizer([t["text"] for t in w],add_special_tokens=False)
89
+ x=[not t["entity_group"].endswith(".") for t in w]
90
+ z=model_outputs["input_ids"][0]
91
+ if len(x)<254:
92
+ x=[True]*len(x)
93
+ else:
94
+ k=sum([len(x)-i+1 if b else 0 for i,b in enumerate(x)])+len(z)+1
95
+ for i in numpy.argsort(numpy.array([t["score"] for t in w])):
96
+ if x[i]==False and k+len(x)-i<32768:
97
+ x[i]=True
98
+ k+=len(x)-i+1
99
+ ids=[-1]
100
+ for i in range(len(x)):
101
+ if x[i]:
102
+ ids.append(i)
103
+ for j in range(i+1,len(x)):
104
+ ids.append(j)
105
+ ids.append(-1)
106
+ with torch.no_grad():
107
+ e=self.model.get_input_embeddings().weight
108
+ m=[]
109
+ for j in v["input_ids"]:
110
+ if j==[]:
111
+ j=self.tokenizer("〓")["input_ids"]
112
+ m.append(e[j,:].sum(axis=0))
113
+ m.append(e[self.tokenizer("<|im_end|>")["input_ids"][0],:])
114
+ m=torch.stack(m).to(self.device)
115
+ e=self.model(inputs_embeds=torch.unsqueeze(torch.vstack((e[z,:],m[ids,:])),0))
116
+ m=e.logits[0].cpu().numpy()
117
+ e=numpy.full((len(x),len(x),m.shape[-1]),m.min())
118
+ k=len(z)+1
119
+ for i in range(len(x)):
120
+ if x[i]:
121
+ e[i,i]=m[k]+self.root
122
+ k+=1
123
+ for j in range(1,len(x)-i):
124
+ e[i+j,i]=m[k]+self.left_arc
125
+ e[i,i+j]=m[k]+self.right_arc
126
+ k+=1
127
+ k+=1
128
+ m,p=numpy.max(e,axis=2),numpy.argmax(e,axis=2)
129
+ h=self.chu_liu_edmonds(m)
130
+ z=[i for i,j in enumerate(h) if i==j]
131
+ if len(z)>1:
132
+ k,h=z[numpy.argmax(m[z,z])],numpy.min(m)-numpy.max(m)
133
+ m[:,z]+=[[0 if j in z and (i!=j or i==k) else h for i in z] for j in range(m.shape[0])]
134
+ h=self.chu_liu_edmonds(m)
135
+ q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
136
+ t=model_outputs["sentence"].replace("\n"," ")
137
+ u="# text = "+t+"\n"
138
+ for i,(s,e) in enumerate(off):
139
+ u+="\t".join([str(i+1),t[s:e],"_",q[i][0],"_","_" if len(q[i])<3 else "|".join(q[i][1:-1]),str(0 if h[i]==i else h[i]+1),"root" if q[i][-1]=="root" else q[i][-1][2:],"_","_" if i+1<len(off) and e<off[i+1][0] else "SpaceAfter=No"])+"\n"
140
+ return u+"\n"
141
+ def chu_liu_edmonds(self,matrix):
142
+ h=numpy.argmax(matrix,axis=0)
143
+ x=[-1 if i==j else j for i,j in enumerate(h)]
144
+ for b in [lambda x,i,j:-1 if i not in x else x[i],lambda x,i,j:-1 if j<0 else x[j]]:
145
+ y=[]
146
+ while x!=y:
147
+ y=list(x)
148
+ for i,j in enumerate(x):
149
+ x[i]=b(x,i,j)
150
+ if max(x)<0:
151
+ return h
152
+ y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
153
+ z=matrix-numpy.max(matrix,axis=0)
154
+ m=numpy.block([[z[x,:][:,x],numpy.max(z[x,:][:,y],axis=1).reshape(len(x),1)],[numpy.max(z[y,:][:,x],axis=0),numpy.max(z[y,y])]])
155
+ k=[j if i==len(x) else x[j] if j<len(x) else y[numpy.argmax(z[y,x[i]])] for i,j in enumerate(self.chu_liu_edmonds(m))]
156
+ h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
157
+ i=y[numpy.argmax(z[x[k[-1]],y] if k[-1]<len(x) else z[y,y])]
158
+ h[i]=x[k[-1]] if k[-1]<len(x) else i
159
+ return h
vocab.json ADDED
The diff for this file is too large to render. See raw diff