KoichiYasuoka commited on
Commit
cf6f740
1 Parent(s): 47cf2d1

initial release

Browse files
Files changed (9) hide show
  1. README.md +25 -0
  2. config.json +181 -0
  3. maker.sh +22 -0
  4. pytorch_model.bin +3 -0
  5. special_tokens_map.json +37 -0
  6. tokenizer.json +0 -0
  7. tokenizer_config.json +62 -0
  8. upos.py +46 -0
  9. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - "bo"
4
+ tags:
5
+ - "tibetan"
6
+ - "token-classification"
7
+ - "pos"
8
+ base_model: KoichiYasuoka/roberta-base-tibetan
9
+ license: "cc-by-sa-4.0"
10
+ pipeline_tag: "token-classification"
11
+ ---
12
+
13
+ # roberta-base-tibetan-upos
14
+
15
+ ## Model Description
16
+
17
+ This is a RoBERTa model for POS-tagging, derived from [roberta-base-tibetan](https://huggingface.co/KoichiYasuoka/roberta-base-tibetan). Every word is tagged by [UPOS](https://universaldependencies.org/u/pos/) (Universal Part-Of-Speech).
18
+
19
+ ## How to Use
20
+
21
+ ```py
22
+ from transformers import pipeline
23
+ nlp=pipeline("upos","KoichiYasuoka/roberta-base-tibetan-upos",trust_remote_code=True,aggregation_strategy="simple")
24
+ ```
25
+
config.json ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForTokenClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "custom_pipelines": {
9
+ "upos": {
10
+ "impl": "upos.BellmanFordTokenClassificationPipeline",
11
+ "pt": "AutoModelForTokenClassification"
12
+ }
13
+ },
14
+ "eos_token_id": 2,
15
+ "hidden_act": "gelu",
16
+ "hidden_dropout_prob": 0.1,
17
+ "hidden_size": 768,
18
+ "id2label": {
19
+ "0": "ADJ",
20
+ "1": "ADP",
21
+ "2": "ADV",
22
+ "3": "AUX",
23
+ "4": "B-ADJ",
24
+ "5": "B-ADJ+ADP",
25
+ "6": "B-ADP",
26
+ "7": "B-ADV",
27
+ "8": "B-AUX",
28
+ "9": "B-AUX+PART",
29
+ "10": "B-AUX+SCONJ",
30
+ "11": "B-DET",
31
+ "12": "B-INTJ",
32
+ "13": "B-NOUN",
33
+ "14": "B-NOUN+ADP",
34
+ "15": "B-NUM",
35
+ "16": "B-NUM+ADP",
36
+ "17": "B-PART",
37
+ "18": "B-PRON",
38
+ "19": "B-PRON+ADP",
39
+ "20": "B-PROPN",
40
+ "21": "B-PROPN+ADP",
41
+ "22": "B-PROPN+SCONJ",
42
+ "23": "B-PUNCT",
43
+ "24": "B-PUNCT+NOUN",
44
+ "25": "B-SCONJ",
45
+ "26": "B-VERB",
46
+ "27": "B-VERB+ADP",
47
+ "28": "B-VERB+PART",
48
+ "29": "B-VERB+SCONJ",
49
+ "30": "B-X",
50
+ "31": "DET",
51
+ "32": "I-ADJ",
52
+ "33": "I-ADJ+ADP",
53
+ "34": "I-ADP",
54
+ "35": "I-ADV",
55
+ "36": "I-AUX",
56
+ "37": "I-AUX+PART",
57
+ "38": "I-AUX+SCONJ",
58
+ "39": "I-DET",
59
+ "40": "I-INTJ",
60
+ "41": "I-NOUN",
61
+ "42": "I-NOUN+ADP",
62
+ "43": "I-NUM",
63
+ "44": "I-NUM+ADP",
64
+ "45": "I-PART",
65
+ "46": "I-PRON",
66
+ "47": "I-PRON+ADP",
67
+ "48": "I-PROPN",
68
+ "49": "I-PROPN+ADP",
69
+ "50": "I-PROPN+SCONJ",
70
+ "51": "I-PUNCT",
71
+ "52": "I-PUNCT+NOUN",
72
+ "53": "I-SCONJ",
73
+ "54": "I-VERB",
74
+ "55": "I-VERB+ADP",
75
+ "56": "I-VERB+PART",
76
+ "57": "I-VERB+SCONJ",
77
+ "58": "I-X",
78
+ "59": "INTJ",
79
+ "60": "NOUN",
80
+ "61": "NUM",
81
+ "62": "PART",
82
+ "63": "PART+NOUN",
83
+ "64": "PART+PUNCT",
84
+ "65": "PRON",
85
+ "66": "PROPN",
86
+ "67": "PUNCT",
87
+ "68": "SCONJ",
88
+ "69": "SYM",
89
+ "70": "VERB",
90
+ "71": "X"
91
+ },
92
+ "initializer_range": 0.02,
93
+ "intermediate_size": 3072,
94
+ "label2id": {
95
+ "ADJ": 0,
96
+ "ADP": 1,
97
+ "ADV": 2,
98
+ "AUX": 3,
99
+ "B-ADJ": 4,
100
+ "B-ADJ+ADP": 5,
101
+ "B-ADP": 6,
102
+ "B-ADV": 7,
103
+ "B-AUX": 8,
104
+ "B-AUX+PART": 9,
105
+ "B-AUX+SCONJ": 10,
106
+ "B-DET": 11,
107
+ "B-INTJ": 12,
108
+ "B-NOUN": 13,
109
+ "B-NOUN+ADP": 14,
110
+ "B-NUM": 15,
111
+ "B-NUM+ADP": 16,
112
+ "B-PART": 17,
113
+ "B-PRON": 18,
114
+ "B-PRON+ADP": 19,
115
+ "B-PROPN": 20,
116
+ "B-PROPN+ADP": 21,
117
+ "B-PROPN+SCONJ": 22,
118
+ "B-PUNCT": 23,
119
+ "B-PUNCT+NOUN": 24,
120
+ "B-SCONJ": 25,
121
+ "B-VERB": 26,
122
+ "B-VERB+ADP": 27,
123
+ "B-VERB+PART": 28,
124
+ "B-VERB+SCONJ": 29,
125
+ "B-X": 30,
126
+ "DET": 31,
127
+ "I-ADJ": 32,
128
+ "I-ADJ+ADP": 33,
129
+ "I-ADP": 34,
130
+ "I-ADV": 35,
131
+ "I-AUX": 36,
132
+ "I-AUX+PART": 37,
133
+ "I-AUX+SCONJ": 38,
134
+ "I-DET": 39,
135
+ "I-INTJ": 40,
136
+ "I-NOUN": 41,
137
+ "I-NOUN+ADP": 42,
138
+ "I-NUM": 43,
139
+ "I-NUM+ADP": 44,
140
+ "I-PART": 45,
141
+ "I-PRON": 46,
142
+ "I-PRON+ADP": 47,
143
+ "I-PROPN": 48,
144
+ "I-PROPN+ADP": 49,
145
+ "I-PROPN+SCONJ": 50,
146
+ "I-PUNCT": 51,
147
+ "I-PUNCT+NOUN": 52,
148
+ "I-SCONJ": 53,
149
+ "I-VERB": 54,
150
+ "I-VERB+ADP": 55,
151
+ "I-VERB+PART": 56,
152
+ "I-VERB+SCONJ": 57,
153
+ "I-X": 58,
154
+ "INTJ": 59,
155
+ "NOUN": 60,
156
+ "NUM": 61,
157
+ "PART": 62,
158
+ "PART+NOUN": 63,
159
+ "PART+PUNCT": 64,
160
+ "PRON": 65,
161
+ "PROPN": 66,
162
+ "PUNCT": 67,
163
+ "SCONJ": 68,
164
+ "SYM": 69,
165
+ "VERB": 70,
166
+ "X": 71
167
+ },
168
+ "layer_norm_eps": 1e-12,
169
+ "max_position_embeddings": 512,
170
+ "model_type": "roberta",
171
+ "num_attention_heads": 12,
172
+ "num_hidden_layers": 12,
173
+ "pad_token_id": 1,
174
+ "position_embedding_type": "absolute",
175
+ "tokenizer_class": "BertTokenizerFast",
176
+ "torch_dtype": "float32",
177
+ "transformers_version": "4.39.3",
178
+ "type_vocab_size": 2,
179
+ "use_cache": true,
180
+ "vocab_size": 8094
181
+ }
maker.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/sh
2
+ for D in classical-tibetan-corpus old-tibetan-corpus modern-tibetan-corpus
3
+ do test -d $D || git clone --depth=1 https://github.com/tibetan-nlp/$D
4
+ done
5
+ ( for F in *-tibetan-corpus/conllu/*.conllu
6
+ do case $F in
7
+ *-translated.conllu) : ;;
8
+ *) cat $F ;;
9
+ esac
10
+ done
11
+ ) | awk '
12
+ {
13
+ if($0==""){
14
+ if(u!~/\tNOTAG\t/)
15
+ print u;
16
+ u="";
17
+ }
18
+ else
19
+ u=u$0"\n";
20
+ }'> all.conllu
21
+ python3 -m esupar.train KoichiYasuoka/roberta-base-tibetan KoichiYasuoka/roberta-base-tibetan-upos 24 /tmp all.conllu
22
+ exit 0
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61e6c8c1160a2a0d9e7169b2c28ee602c3718a47b35017112021016edadb2b1a
3
+ size 366957990
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[CLS]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[PAD]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": false,
48
+ "keep_accents": true,
49
+ "mask_token": "[MASK]",
50
+ "max_length": 510,
51
+ "model_max_length": 512,
52
+ "never_split": null,
53
+ "pad_token": "[PAD]",
54
+ "sep_token": "[SEP]",
55
+ "stride": 0,
56
+ "strip_accents": null,
57
+ "tokenize_chinese_chars": true,
58
+ "tokenizer_class": "BertTokenizerFast",
59
+ "truncation_side": "right",
60
+ "truncation_strategy": "longest_first",
61
+ "unk_token": "[UNK]"
62
+ }
upos.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TokenClassificationPipeline
2
+
3
+ class BellmanFordTokenClassificationPipeline(TokenClassificationPipeline):
4
+ def __init__(self,**kwargs):
5
+ import numpy
6
+ super().__init__(**kwargs)
7
+ x=self.model.config.label2id
8
+ y=[k for k in x if not k.startswith("I-")]
9
+ self.transition=numpy.full((len(x),len(x)),numpy.nan)
10
+ for k,v in x.items():
11
+ for j in ["I-"+k[2:]] if k.startswith("B-") else [k]+y if k.startswith("I-") else y:
12
+ self.transition[v,x[j]]=0
13
+ def check_model_type(self,supported_models):
14
+ pass
15
+ def postprocess(self,model_outputs,**kwargs):
16
+ import numpy
17
+ if "logits" not in model_outputs:
18
+ return self.postprocess(model_outputs[0],**kwargs)
19
+ m=model_outputs["logits"][0].numpy()
20
+ e=numpy.exp(m-numpy.max(m,axis=-1,keepdims=True))
21
+ z=e/e.sum(axis=-1,keepdims=True)
22
+ for i in range(m.shape[0]-1,0,-1):
23
+ m[i-1]+=numpy.nanmax(m[i]+self.transition,axis=1)
24
+ k=[numpy.nanargmax(m[0]+self.transition[0])]
25
+ for i in range(1,m.shape[0]):
26
+ k.append(numpy.nanargmax(m[i]+self.transition[k[-1]]))
27
+ 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]
28
+ if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
29
+ for i,t in reversed(list(enumerate(w))):
30
+ p=t.pop("entity")
31
+ if p.startswith("I-"):
32
+ w[i-1]["score"]=min(w[i-1]["score"],t["score"])
33
+ w[i-1]["end"]=w.pop(i)["end"]
34
+ elif p.startswith("B-"):
35
+ t["entity_group"]=p[2:]
36
+ else:
37
+ t["entity_group"]=p
38
+ s=model_outputs["sentence"]
39
+ for i,t in enumerate(w):
40
+ if t["end"]<len(s):
41
+ if s[t["end"]] in {"\u0f0b","\u0f0c"}:
42
+ if len(w)-i==1 or t["end"]<w[i+1]["start"]:
43
+ t["end"]+=1
44
+ t["text"]=s[t["start"]:t["end"]]
45
+ return w
46
+
vocab.txt ADDED
The diff for this file is too large to render. See raw diff