File size: 5,460 Bytes
b0b72af
 
3721ad6
 
 
 
 
 
 
 
 
 
 
 
b0b72af
3721ad6
 
 
 
 
 
 
 
 
 
 
 
c8716cf
 
 
 
3721ad6
 
 
 
 
85e238b
3721ad6
 
85e238b
 
3721ad6
 
fda7b62
3721ad6
fda7b62
 
 
 
 
 
 
1ea9980
 
fda7b62
3721ad6
91b135b
 
3721ad6
1ea9980
3721ad6
 
 
 
 
1ea9980
 
3721ad6
 
 
 
62570c6
 
3721ad6
 
 
 
 
1ea9980
 
 
6ef0e58
 
 
 
 
1ea9980
 
 
 
3721ad6
 
 
 
 
1ea9980
3721ad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8716cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
license: apache-2.0
datasets:
- wiki40b
language:
- ja
tags:
- ja
- japanese
- text-generation
- lm
- jax
- flax
- lm1b
---
# transformer-lm-japanese-0.1b

## Model Description

This is a JAX/Flax-based transformer language model trained on a Japanese dataset. It is based on the official Flax example code ([lm1b](https://github.com/google/flax/tree/main/examples/lm1b)).

## Model Sources

We've modified Flax's 'lm1b' example to train on Japanese dataset. You can find the code on Github.

* [transformer-lm-japanese](https://github.com/FookieMonster/transformer-lm-japanese)

## Model's Blog Post

Read our [blog post](https://zenn.dev/fukugawa/articles/4446573ec0f697) to learn more about our model.

## Model Details

| Model | Params | Layers | Dim | Heads | PPL | Dataset | Training time |
|-|-|-|-|-|-|-|-|
| lm1b-default | 0.05B | 6 | 512 | 8 | 22.67 | lm1b | 0.5 days |
| transformer-lm-japanese-default | 0.05B | 6 | 512 | 8 | 66.38 | cc100/ja | 0.5 days |
| transformer-lm-japanese-0.1b | 0.1B | 12 | 768 | 12 | 35.22 | wiki40b/ja | 1.5 days |

![tensor-board](./tensorboard-v1.png)

## Usage

Here, we explain the procedure to generate text from pretrained weights using a CPU. We used the following instance on GCE for the Python 3.8 environment.

* Machine Type: c2-standard-4 (4 CPUs, 16GB Memory)
* Disk: 100GB (Standard Persistent Disk)
* OS: Ubuntu 20.04 LTS x86/64

Install Python 3.8 and pip.

```
sudo apt-get update
sudo apt-get install python3.8 python3-pip build-essential
```

Install the huggingface_hub library.

```
pip install --upgrade huggingface_hub
```

Run the Python interpreter and download the model files.

```
cd $HOME
python3
```

```python
>>> from huggingface_hub import hf_hub_download
>>> hf_hub_download(repo_id="fukugawa/transformer-lm-japanese-0.1b", filename="sentencepiece_model", revision="v1", local_dir="./logs/japanese_0.1b_v1", local_dir_use_symlinks=False)
>>> hf_hub_download(repo_id="fukugawa/transformer-lm-japanese-0.1b", filename="checkpoint_499999", revision="v1", local_dir="./logs/japanese_0.1b_v1", local_dir_use_symlinks=False)
```

Clone the source code and install the necessary Python packages.

```
git clone -b 1.0.0.RC2 https://github.com/FookieMonster/transformer-lm-japanese
cd ./transformer-lm-japanese/transformer_lm
pip install -r requirements.txt
```

Install the necessary Python packages to run on the CPU.

```
pip install jax[cpu]==0.3.2
pip install chex==0.1.5
pip install protobuf==3.20.3
pip install typing-extensions==3.10.0.2
```

Text generation using downloaded model files.

```
python3 generate_text.py --workdir=$HOME/logs/japanese_0.1b_v1 \
    --config=configs/japanese_0.1b_v1.py \
    --config.sampling_temperature=0.6 \
    --config.sampling_top_k=20 \
    --config.seed=0 \
    --config.prompts="夏目漱石は、" \
    --num_generated_texts=10
```

```
Generating text.
Sample: 夏目漱石は、自分の作品を「文学の本」として出版することを構想していた。
Generating text.
Sample: 夏目漱石は、明治の文学運動を「文学の原点に立ち帰る」と位置づけ、漱石が「文学の本質をあらわすのが文学である」との認識を、当時の知識人たちが持っていたことを指摘している。
Generating text.
Sample: 夏目漱石は、小説『坊っちゃん』で、この「坊っちゃん」を「坊っちゃん」に置き換えた。「坊っちゃん」は、坊っちゃんの「坊」の字を、「坊」は「坊」の字をもじってつけられた。
Generating text.
Sample: 夏目漱石は、漱石の『坊っちゃん』を読んで、「漱石は、私に『坊っちゃん』をおもしろおかしく書かせた。これは、私に『坊っちゃん』を書かせるのを、私に教えてくれたからだ」と述懐している。
Generating text.
Sample: 夏目漱石は、自身の著作『漱石全集』の中で「漱石が生涯のほとんどを漱石の文学に捧げた」と評価している。
Generating text.
Sample: 夏目漱石は、漱石が「『吾輩は猫』を観るのが嫌だ」と言ったのを、漱石が「あんなに怖いとは思わなかった」と返している。
Generating text.
Sample: 夏目漱石は、自身の日記の中で「文学の本質と現実との間には、対立関係があり、また対立関係があっても、それが文学の本質と現実との間には関係がある」と書いている。
Generating text.
Sample: 夏目漱石は、夏目が漱石の『吾輩は猫である』を読んでいた時に、漱石の『吾輩は猫である』を読んだという。漱石は「猫は猫である」と書いていたが、漱石は「猫である」と書いた。
Generating text.
Sample: 夏目漱石は、小説『坊っちゃん』の中で、主人公が「おばあさん」と「おばあさん」の2人で暮らしていると、その家から「おばあさん」と「おばあさん」が飛び出してくるという話を紹介している。
Generating text.
Sample: 夏目漱石は、漱石の「吾輩は猫である」という言葉を、漱石が「猫を飼っている人は猫である」という誤解から誤解したのだろうと、著書『猫の散歩道』で述べている。
```

## Dataset

* wiki40b/ja
 
## Tokenization

* [sentencepiece](https://github.com/google/sentencepiece)

## Author

[Ryoichi Fukugawa](https://zenn.dev/fukugawa)