|
| 1 | + |
| 2 | + |
| 3 | +# BERT base Japanese (IPA dictionary, whole word masking enabled) |
| 4 | + |
| 5 | +This is a [BERT](https://github.com/google-research/bert) model pretrained on texts in the Japanese language. |
| 6 | + |
| 7 | +This version of the model processes input texts with word-level tokenization based on the IPA dictionary, followed by the WordPiece subword tokenization. |
| 8 | + |
| 9 | +Additionally, the model is trained with the whole word masking enabled for the masked language modeling (MLM) objective. |
| 10 | + |
| 11 | +The codes for the pretraining are available at [cl-tohoku/bert-japanese](https://github.com/cl-tohoku/bert-japanese/tree/v1.0). |
| 12 | + |
| 13 | +## Model architecture |
| 14 | + |
| 15 | +The model architecture is the same as the original BERT base model; 12 layers, 768 dimensions of hidden states, and 12 attention heads. |
| 16 | + |
| 17 | +## Training Data |
| 18 | + |
| 19 | +The model is trained on Japanese Wikipedia as of September 1, 2019. |
| 20 | + |
| 21 | +To generate the training corpus, [WikiExtractor](https://github.com/attardi/wikiextractor) is used to extract plain texts from a dump file of Wikipedia articles. |
| 22 | + |
| 23 | +The text files used for the training are 2.6GB in size, consisting of approximately 17M sentences. |
| 24 | + |
| 25 | +## Tokenization |
| 26 | + |
| 27 | +The texts are first tokenized by [MeCab](https://taku910.github.io/mecab/) morphological parser with the IPA dictionary and then split into subwords by the WordPiece algorithm. |
| 28 | + |
| 29 | +The vocabulary size is 32000. |
| 30 | + |
| 31 | +## Training |
| 32 | + |
| 33 | +The model is trained with the same configuration as the original BERT; 512 tokens per instance, 256 instances per batch, and 1M training steps. |
| 34 | + |
| 35 | +For the training of the MLM (masked language modeling) objective, we introduced the **Whole Word Masking** in which all of the subword tokens corresponding to a single word (tokenized by MeCab) are masked at once. |
| 36 | + |
| 37 | +## Licenses |
| 38 | + |
| 39 | +The pretrained models are distributed under the terms of the [Creative Commons Attribution-ShareAlike 3.0](https://creativecommons.org/licenses/by-sa/3.0/). |
| 40 | + |
| 41 | +## Acknowledgments |
| 42 | + |
| 43 | +For training models, we used Cloud TPUs provided by [TensorFlow Research Cloud](https://www.tensorflow.org/tfrc/) program. |
| 44 | + |
| 45 | +## Usage |
| 46 | +```python |
| 47 | +import paddle |
| 48 | +from paddlenlp.transformers import BertJapaneseTokenizer, BertForMaskedLM |
| 49 | + |
| 50 | +path = "iverxin/bert-base-japanese-whole-word-masking/" |
| 51 | +tokenizer = BertJapaneseTokenizer.from_pretrained(path) |
| 52 | +model = BertForMaskedLM.from_pretrained(path) |
| 53 | +text1 = "こんにちは" |
| 54 | + |
| 55 | +model.eval() |
| 56 | +inputs = tokenizer(text1) |
| 57 | +inputs = {k: paddle.to_tensor([v]) for (k, v) in inputs.items()} |
| 58 | +output = model(**inputs) |
| 59 | +print(output.shape) |
| 60 | +``` |
| 61 | + |
| 62 | +## Weights source |
| 63 | +https://huggingface.co/cl-tohoku/bert-base-japanese-whole-word-masking |
0 commit comments