KoichiYasuoka commited on
Commit
91a7f09
·
1 Parent(s): fdafef3

initial release

Browse files
Files changed (8) hide show
  1. README.md +30 -0
  2. config.json +48 -0
  3. maker.py +25 -0
  4. pytorch_model.bin +3 -0
  5. special_tokens_map.json +7 -0
  6. tokenizer.json +0 -0
  7. tokenizer_config.json +64 -0
  8. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - "lzh"
4
+ tags:
5
+ - "classical chinese"
6
+ - "literary chinese"
7
+ - "ancient chinese"
8
+ - "masked-lm"
9
+ base_model: KoichiYasuoka/modernbert-small-classical-chinese-traditional
10
+ license: "apache-2.0"
11
+ pipeline_tag: "fill-mask"
12
+ mask_token: "[MASK]"
13
+ widget:
14
+ - text: "孟子[MASK]梁惠王"
15
+ ---
16
+
17
+ # modernbert-small-classical-chinese
18
+
19
+ ## Model Description
20
+
21
+ This is a ModernBERT model pre-trained on [Kanripo](https://www.kanripo.org) texts. Character-embeddings are enhanced into traditional/simplified characters. You can fine-tune `modernbert-small-classical-chinese` for downstream tasks, such as sentence-segmentation, POS-tagging, dependency-parsing, and so on.
22
+
23
+ ## How to Use
24
+
25
+ ```py
26
+ from transformers import AutoTokenizer,AutoModelForMaskedLM
27
+ tokenizer=AutoTokenizer.from_pretrained("KoichiYasuoka/modernbert-small-classical-chinese")
28
+ model=AutoModelForMaskedLM.from_pretrained("KoichiYasuoka/modernbert-small-classical-chinese")
29
+ ```
30
+
config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "KoichiYasuoka/modernbert-small-classical-chinese-traditional",
3
+ "architectures": [
4
+ "ModernBertForMaskedLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 0,
9
+ "classifier_activation": "gelu",
10
+ "classifier_bias": false,
11
+ "classifier_dropout": 0.0,
12
+ "classifier_pooling": "mean",
13
+ "cls_token_id": 0,
14
+ "decoder_bias": true,
15
+ "deterministic_flash_attn": false,
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 2,
18
+ "global_attn_every_n_layers": 3,
19
+ "global_rope_theta": 160000.0,
20
+ "gradient_checkpointing": false,
21
+ "hidden_activation": "gelu",
22
+ "hidden_size": 256,
23
+ "initializer_cutoff_factor": 2.0,
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 768,
26
+ "layer_norm_eps": 1e-05,
27
+ "local_attention": 128,
28
+ "local_rope_theta": 10000.0,
29
+ "max_position_embeddings": 8192,
30
+ "mlp_bias": false,
31
+ "mlp_dropout": 0.0,
32
+ "model_type": "modernbert",
33
+ "norm_bias": false,
34
+ "norm_eps": 1e-05,
35
+ "num_attention_heads": 8,
36
+ "num_hidden_layers": 16,
37
+ "pad_token_id": 1,
38
+ "position_embedding_type": "absolute",
39
+ "reference_compile": false,
40
+ "repad_logits_with_grad": false,
41
+ "sep_token_id": 2,
42
+ "sparse_pred_ignore_index": -100,
43
+ "sparse_prediction": false,
44
+ "tokenizer_class": "BertTokenizerFast",
45
+ "torch_dtype": "float32",
46
+ "transformers_version": "4.48.3",
47
+ "vocab_size": 25078
48
+ }
maker.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /usr/bin/python3
2
+ src="KoichiYasuoka/modernbert-small-classical-chinese-traditional"
3
+ tgt="KoichiYasuoka/modernbert-small-classical-chinese"
4
+ import torch
5
+ from transformers import BertTokenizerFast,AutoModelForMaskedLM
6
+ from esupar.tradify import tradify
7
+ from tokenizers.pre_tokenizers import Sequence,Whitespace,Split
8
+ from tokenizers import Regex
9
+ tkz=BertTokenizerFast.from_pretrained(src)
10
+ mdl=AutoModelForMaskedLM.from_pretrained(src)
11
+ c=[(k,v) for k,v in tradify.items() if tkz.add_tokens([k,v])==1]
12
+ e=mdl.resize_token_embeddings(len(tkz))
13
+ with torch.no_grad():
14
+ for k,v in c:
15
+ t=sorted(tkz.convert_tokens_to_ids([k,v]))
16
+ e.weight[t[1],:]=e.weight[t[0],:]
17
+ mdl.set_input_embeddings(e)
18
+ mdl.save_pretrained(tgt,safe_serialization=False)
19
+ with open(tgt+"/vocab.txt","w",encoding="utf-8") as w:
20
+ print("\n".join(tkz.convert_ids_to_tokens(range(len(tkz)))),file=w)
21
+ s=["[CLS]","[PAD]","[SEP]","[UNK]","[MASK]"]
22
+ tkz=BertTokenizerFast(vocab_file=tgt+"/vocab.txt",never_split=s,do_lower_case=False,strip_accents=False,tokenize_chinese_chars=True)
23
+ tkz.backend_tokenizer.pre_tokenizer=Sequence([Whitespace(),Split(Regex("."),"isolated")])
24
+ tkz.backend_tokenizer.decoder.prefix=tkz.backend_tokenizer.model.continuing_subword_prefix=""
25
+ tkz.save_pretrained(tgt)
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:269d677fb2bbfbd0cac02012d8c421c6acf13b96c38f03846704f821d316651f
3
+ size 80634974
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "never_split": [
52
+ "[CLS]",
53
+ "[PAD]",
54
+ "[SEP]",
55
+ "[UNK]",
56
+ "[MASK]"
57
+ ],
58
+ "pad_token": "[PAD]",
59
+ "sep_token": "[SEP]",
60
+ "strip_accents": false,
61
+ "tokenize_chinese_chars": true,
62
+ "tokenizer_class": "BertTokenizer",
63
+ "unk_token": "[UNK]"
64
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff