first commit
Browse files- README.md +103 -0
- config.json +37 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +9 -0
- spm.model +3 -0
- tokenization_deberta_v2_jumanpp.py +30 -0
- tokenization_deberta_v2_jumanpp_fast.py +64 -0
- tokenizer.json +0 -0
- tokenizer_config.json +21 -0
README.md
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: ja
|
3 |
+
license: cc-by-sa-4.0
|
4 |
+
library_name: transformers
|
5 |
+
tags:
|
6 |
+
- deberta
|
7 |
+
- deberta-v2
|
8 |
+
- fill-mask
|
9 |
+
datasets:
|
10 |
+
- wikipedia
|
11 |
+
- cc100
|
12 |
+
- oscar
|
13 |
+
metrics:
|
14 |
+
- accuracy
|
15 |
+
mask_token: "[MASK]"
|
16 |
+
widget:
|
17 |
+
- text: "京都大学で自然言語処理を[MASK]する。"
|
18 |
+
---
|
19 |
+
|
20 |
+
# Model Card for Japanese DeBERTa V2 base
|
21 |
+
|
22 |
+
## Model description
|
23 |
+
|
24 |
+
This is a Japanese DeBERTa V2 base model pre-trained on Japanese Wikipedia, the Japanese portion of CC-100, and the Japanese portion of OSCAR.
|
25 |
+
|
26 |
+
## How to use
|
27 |
+
|
28 |
+
You can use this model for masked language modeling as follows:
|
29 |
+
|
30 |
+
```python
|
31 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained('ku-nlp/deberta-v2-base-japanese', trust_remote_code=True)
|
33 |
+
model = AutoModelForMaskedLM.from_pretrained('ku-nlp/deberta-v2-base-japanese')
|
34 |
+
|
35 |
+
sentence = '京都大学で自然言語処理を[MASK]する。'
|
36 |
+
encoding = tokenizer(sentence, return_tensors='pt')
|
37 |
+
...
|
38 |
+
```
|
39 |
+
|
40 |
+
You can also fine-tune this model on downstream tasks.
|
41 |
+
|
42 |
+
## Tokenization
|
43 |
+
|
44 |
+
~~The input text should be segmented into words by [Juman++](https://github.com/ku-nlp/jumanpp) in advance. [Juman++ 2.0.0-rc3](https://github.com/ku-nlp/jumanpp/releases/tag/v2.0.0-rc3) was used for pre-training. Each word is tokenized into subwords by [sentencepiece](https://github.com/google/sentencepiece).~~
|
45 |
+
|
46 |
+
UPDATE: The input text is internally segmented by [Juman++](https://github.com/ku-nlp/jumanpp) within `DebertaV2JumanppTokenizer(Fast)`, so there's no need to segment it in advance. To use `DebertaV2JumanppTokenizer(Fast)`, you need to install [Juman++ 2.0.0-rc3](https://github.com/ku-nlp/jumanpp/releases/tag/v2.0.0-rc3) and [rhoknp](https://github.com/ku-nlp/rhoknp).
|
47 |
+
|
48 |
+
## Training data
|
49 |
+
|
50 |
+
We used the following corpora for pre-training:
|
51 |
+
|
52 |
+
- Japanese Wikipedia (as of 20221020, 3.2GB, 27M sentences, 1.3M documents)
|
53 |
+
- Japanese portion of CC-100 (85GB, 619M sentences, 66M documents)
|
54 |
+
- Japanese portion of OSCAR (54GB, 326M sentences, 25M documents)
|
55 |
+
|
56 |
+
Note that we filtered out documents annotated with "header", "footer", or "noisy" tags in OSCAR.
|
57 |
+
Also note that Japanese Wikipedia was duplicated 10 times to make the total size of the corpus comparable to that of CC-100 and OSCAR. As a result, the total size of the training data is 171GB.
|
58 |
+
|
59 |
+
## Training procedure
|
60 |
+
|
61 |
+
We first segmented texts in the corpora into words using [Juman++](https://github.com/ku-nlp/jumanpp).
|
62 |
+
Then, we built a sentencepiece model with 32000 tokens including words ([JumanDIC](https://github.com/ku-nlp/JumanDIC)) and subwords induced by the unigram language model of [sentencepiece](https://github.com/google/sentencepiece).
|
63 |
+
|
64 |
+
We tokenized the segmented corpora into subwords using the sentencepiece model and trained the Japanese DeBERTa model using [transformers](https://github.com/huggingface/transformers) library.
|
65 |
+
The training took three weeks using 8 NVIDIA A100-SXM4-40GB GPUs.
|
66 |
+
|
67 |
+
The following hyperparameters were used during pre-training:
|
68 |
+
|
69 |
+
- learning_rate: 2e-4
|
70 |
+
- per_device_train_batch_size: 44
|
71 |
+
- distributed_type: multi-GPU
|
72 |
+
- num_devices: 8
|
73 |
+
- gradient_accumulation_steps: 6
|
74 |
+
- total_train_batch_size: 2,112
|
75 |
+
- max_seq_length: 512
|
76 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-06
|
77 |
+
- lr_scheduler_type: linear schedule with warmup
|
78 |
+
- training_steps: 500,000
|
79 |
+
- warmup_steps: 10,000
|
80 |
+
|
81 |
+
The accuracy of the trained model on the masked language modeling task was 0.779.
|
82 |
+
The evaluation set consists of 5,000 randomly sampled documents from each of the training corpora.
|
83 |
+
|
84 |
+
## Fine-tuning on NLU tasks
|
85 |
+
|
86 |
+
We fine-tuned the following models and evaluated them on the dev set of JGLUE.
|
87 |
+
We tuned learning rate and training epochs for each model and task following [the JGLUE paper](https://www.jstage.jst.go.jp/article/jnlp/30/1/30_63/_pdf/-char/ja).
|
88 |
+
|
89 |
+
| Model | MARC-ja/acc | JSTS/pearson | JSTS/spearman | JNLI/acc | JSQuAD/EM | JSQuAD/F1 | JComQA/acc |
|
90 |
+
|-------------------------------|-------------|--------------|---------------|----------|-----------|-----------|------------|
|
91 |
+
| Waseda RoBERTa base | 0.965 | 0.913 | 0.876 | 0.905 | 0.853 | 0.916 | 0.853 |
|
92 |
+
| Waseda RoBERTa large (seq512) | 0.969 | 0.925 | 0.890 | 0.928 | 0.910 | 0.955 | 0.900 |
|
93 |
+
| LUKE Japanese base* | 0.965 | 0.916 | 0.877 | 0.912 | - | - | 0.842 |
|
94 |
+
| LUKE Japanese large* | 0.965 | 0.932 | 0.902 | 0.927 | - | - | 0.893 |
|
95 |
+
| DeBERTaV2 base | 0.970 | 0.922 | 0.886 | 0.922 | 0.899 | 0.951 | 0.873 |
|
96 |
+
| DeBERTaV2 large | 0.968 | 0.925 | 0.892 | 0.924 | 0.912 | 0.959 | 0.890 |
|
97 |
+
|
98 |
+
*The scores of LUKE are from [the official repository](https://github.com/studio-ousia/luke).
|
99 |
+
|
100 |
+
## Acknowledgments
|
101 |
+
|
102 |
+
This work was supported by Joint Usage/Research Center for Interdisciplinary Large-scale Information Infrastructures (JHPCN) through General Collaboration Project no. jh221004, "Developing a Platform for Constructing and Sharing of Large-Scale Japanese Language Models".
|
103 |
+
For training models, we used the mdx: a platform for the data-driven future.
|
config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"DebertaV2ForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_head_size": 64,
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"conv_act": "gelu",
|
8 |
+
"conv_kernel_size": 3,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 3072,
|
14 |
+
"layer_norm_eps": 1e-07,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"max_relative_positions": -1,
|
17 |
+
"model_type": "deberta-v2",
|
18 |
+
"norm_rel_ebd": "layer_norm",
|
19 |
+
"num_attention_heads": 12,
|
20 |
+
"num_hidden_layers": 12,
|
21 |
+
"pad_token_id": 0,
|
22 |
+
"pooler_dropout": 0,
|
23 |
+
"pooler_hidden_act": "gelu",
|
24 |
+
"pooler_hidden_size": 768,
|
25 |
+
"pos_att_type": [
|
26 |
+
"p2c",
|
27 |
+
"c2p"
|
28 |
+
],
|
29 |
+
"position_biased_input": false,
|
30 |
+
"position_buckets": 256,
|
31 |
+
"relative_attention": true,
|
32 |
+
"share_att_key": true,
|
33 |
+
"torch_dtype": "float32",
|
34 |
+
"transformers_version": "4.23.1",
|
35 |
+
"type_vocab_size": 0,
|
36 |
+
"vocab_size": 32000
|
37 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:57fb86bf188376f5d1230e5835270f9e7bb00e5db5aaedfb9445df7b571ba9c3
|
3 |
+
size 548197213
|
special_tokens_map.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "[CLS]",
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"eos_token": "[SEP]",
|
5 |
+
"mask_token": "[MASK]",
|
6 |
+
"pad_token": "[PAD]",
|
7 |
+
"sep_token": "[SEP]",
|
8 |
+
"unk_token": "[UNK]"
|
9 |
+
}
|
spm.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c111c16e2e52366dcac46b886e40650bb843fe2938a65f5970271fc5697a127
|
3 |
+
size 805061
|
tokenization_deberta_v2_jumanpp.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import DebertaV2Tokenizer
|
2 |
+
|
3 |
+
|
4 |
+
class DebertaV2JumanppTokenizer(DebertaV2Tokenizer):
|
5 |
+
def __init__(self, *args, **kwargs):
|
6 |
+
super().__init__(*args, **kwargs)
|
7 |
+
self.juman_tokenizer = JumanppTokenizer()
|
8 |
+
|
9 |
+
def prepare_for_tokenization(self, text, is_split_into_words=False, **kwargs) -> tuple[str, dict]:
|
10 |
+
text = self.juman_tokenizer.tokenize(text)
|
11 |
+
|
12 |
+
add_prefix_space = kwargs.pop("add_prefix_space", False)
|
13 |
+
if is_split_into_words or add_prefix_space:
|
14 |
+
text = " " + text
|
15 |
+
return (text, kwargs)
|
16 |
+
|
17 |
+
|
18 |
+
class JumanppTokenizer:
|
19 |
+
def __init__(self):
|
20 |
+
try:
|
21 |
+
import rhoknp
|
22 |
+
except ImportError:
|
23 |
+
raise ImportError(
|
24 |
+
"You need to install rhoknp to use JumanppPreTokenizer. "
|
25 |
+
"See https://github.com/ku-nlp/rhoknp for installation."
|
26 |
+
)
|
27 |
+
self.juman = rhoknp.Jumanpp()
|
28 |
+
|
29 |
+
def tokenize(self, text: str) -> str:
|
30 |
+
return " ".join([morpheme.surf for morpheme in self.juman.apply_to_sentence(text).morphemes])
|
tokenization_deberta_v2_jumanpp_fast.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
|
3 |
+
from tokenizers import NormalizedString, PreTokenizedString, normalizers, pre_tokenizers
|
4 |
+
from transformers import DebertaV2TokenizerFast
|
5 |
+
|
6 |
+
|
7 |
+
class DebertaV2JumanppTokenizerFast(DebertaV2TokenizerFast):
|
8 |
+
def __init__(self, *args, **kwargs):
|
9 |
+
super().__init__(*args, **kwargs)
|
10 |
+
self.juman_normalizer = normalizers.Sequence(
|
11 |
+
[
|
12 |
+
# cf. https://github.com/ku-nlp/rhoknp/blob/v1.3.0/src/rhoknp/units/sentence.py#L36
|
13 |
+
normalizers.Replace("\r", ""),
|
14 |
+
normalizers.Replace("\n", ""),
|
15 |
+
# cf. https://github.com/ku-nlp/jumanpp/blob/v2.0.0-rc3/src/jumandic/shared/juman_format.cc#L44-L61
|
16 |
+
normalizers.Replace("\t", "\\t"),
|
17 |
+
normalizers.Replace(" ", " "),
|
18 |
+
normalizers.Replace('"', "”"),
|
19 |
+
normalizers.Replace("<", "<"),
|
20 |
+
normalizers.Replace(">", ">"),
|
21 |
+
]
|
22 |
+
)
|
23 |
+
self.juman_pre_tokenizer = pre_tokenizers.PreTokenizer.custom(JumanppPreTokenizer())
|
24 |
+
|
25 |
+
self.default_normalizer = copy.deepcopy(self.backend_tokenizer.normalizer)
|
26 |
+
self.default_pre_tokenizer = copy.deepcopy(self.backend_tokenizer.pre_tokenizer)
|
27 |
+
|
28 |
+
self.backend_tokenizer.normalizer = normalizers.Sequence(
|
29 |
+
[self.juman_normalizer, self.backend_tokenizer.normalizer]
|
30 |
+
)
|
31 |
+
self.backend_tokenizer.pre_tokenizer = pre_tokenizers.Sequence(
|
32 |
+
[self.juman_pre_tokenizer, self.backend_tokenizer.pre_tokenizer]
|
33 |
+
)
|
34 |
+
|
35 |
+
def save_pretrained(self, *args, **kwargs):
|
36 |
+
self.backend_tokenizer.normalizer = self.default_normalizer
|
37 |
+
self.backend_tokenizer.pre_tokenizer = self.default_pre_tokenizer
|
38 |
+
super().save_pretrained(*args, **kwargs)
|
39 |
+
|
40 |
+
self.backend_tokenizer.normalizer = normalizers.Sequence(
|
41 |
+
[self.juman_normalizer, self.backend_tokenizer.normalizer]
|
42 |
+
)
|
43 |
+
self.backend_tokenizer.pre_tokenizer = pre_tokenizers.Sequence(
|
44 |
+
[self.juman_pre_tokenizer, self.backend_tokenizer.pre_tokenizer]
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
+
class JumanppPreTokenizer:
|
49 |
+
def __init__(self):
|
50 |
+
try:
|
51 |
+
import rhoknp
|
52 |
+
except ImportError:
|
53 |
+
raise ImportError(
|
54 |
+
"You need to install rhoknp to use JumanppPreTokenizer. "
|
55 |
+
"See https://github.com/ku-nlp/rhoknp for installation."
|
56 |
+
)
|
57 |
+
self.juman = rhoknp.Jumanpp()
|
58 |
+
|
59 |
+
def pre_tokenize(self, pretok: PreTokenizedString):
|
60 |
+
pretok.split(self.jumanpp_split)
|
61 |
+
|
62 |
+
def jumanpp_split(self, i: int, normalized_string: NormalizedString) -> list[NormalizedString]:
|
63 |
+
offsets = [morpheme.span for morpheme in self.juman.apply_to_sentence(str(normalized_string)).morphemes]
|
64 |
+
return [normalized_string[offset[0]:offset[1]] for offset in offsets]
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "[CLS]",
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"do_lower_case": false,
|
5 |
+
"eos_token": "[SEP]",
|
6 |
+
"keep_accents": true,
|
7 |
+
"mask_token": "[MASK]",
|
8 |
+
"pad_token": "[PAD]",
|
9 |
+
"sep_token": "[SEP]",
|
10 |
+
"sp_model_kwargs": {},
|
11 |
+
"special_tokens_map_file": null,
|
12 |
+
"split_by_punct": false,
|
13 |
+
"tokenizer_class": "DebertaV2JumanppTokenizer",
|
14 |
+
"unk_token": "[UNK]",
|
15 |
+
"auto_map": {
|
16 |
+
"AutoTokenizer": [
|
17 |
+
"tokenization_deberta_v2_jumanpp.DebertaV2JumanppTokenizer",
|
18 |
+
"tokenization_deberta_v2_jumanpp_fast.DebertaV2JumanppTokenizerFast"
|
19 |
+
]
|
20 |
+
}
|
21 |
+
}
|