Update README.md
Browse files
README.md
CHANGED
@@ -3,368 +3,4 @@ language: ko
|
|
3 |
license: apache-2.0
|
4 |
tags:
|
5 |
- korean
|
6 |
-
---
|
7 |
-
|
8 |
-
# KcBERT: Korean comments BERT
|
9 |
-
|
10 |
-
** Updates on 2021.04.07 **
|
11 |
-
|
12 |
-
- KcELECTRA๊ฐ ๋ฆด๋ฆฌ์ฆ ๋์์ต๋๋ค!๐ค
|
13 |
-
- KcELECTRA๋ ๋ณด๋ค ๋ ๋ง์ ๋ฐ์ดํฐ์
, ๊ทธ๋ฆฌ๊ณ ๋ ํฐ General vocab์ ํตํด KcBERT ๋๋น **๋ชจ๋ ํ์คํฌ์์ ๋ ๋์ ์ฑ๋ฅ**์ ๋ณด์
๋๋ค.
|
14 |
-
- ์๋ ๊นํ ๋งํฌ์์ ์ง์ ์ฌ์ฉํด๋ณด์ธ์!
|
15 |
-
- https://github.com/Beomi/KcELECTRA
|
16 |
-
|
17 |
-
** Updates on 2021.03.14 **
|
18 |
-
|
19 |
-
- KcBERT Paper ์ธ์ฉ ํ๊ธฐ๋ฅผ ์ถ๊ฐํ์์ต๋๋ค.(bibtex)
|
20 |
-
- KcBERT-finetune Performance score๋ฅผ ๋ณธ๋ฌธ์ ์ถ๊ฐํ์์ต๋๋ค.
|
21 |
-
|
22 |
-
** Updates on 2020.12.04 **
|
23 |
-
|
24 |
-
Huggingface Transformers๊ฐ v4.0.0์ผ๋ก ์
๋ฐ์ดํธ๋จ์ ๋ฐ๋ผ Tutorial์ ์ฝ๋๊ฐ ์ผ๋ถ ๋ณ๊ฒฝ๋์์ต๋๋ค.
|
25 |
-
|
26 |
-
์
๋ฐ์ดํธ๋ KcBERT-Large NSMC Finetuning Colab: <a href="https://colab.research.google.com/drive/1dFC0FL-521m7CL_PSd8RLKq67jgTJVhL?usp=sharing">
|
27 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
28 |
-
</a>
|
29 |
-
|
30 |
-
** Updates on 2020.09.11 **
|
31 |
-
|
32 |
-
KcBERT๋ฅผ Google Colab์์ TPU๋ฅผ ํตํด ํ์ตํ ์ ์๋ ํํ ๋ฆฌ์ผ์ ์ ๊ณตํฉ๋๋ค! ์๋ ๋ฒํผ์ ๋๋ฌ๋ณด์ธ์.
|
33 |
-
|
34 |
-
Colab์์ TPU๋ก KcBERT Pretrain ํด๋ณด๊ธฐ: <a href="https://colab.research.google.com/drive/1lYBYtaXqt9S733OXdXvrvC09ysKFN30W">
|
35 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
36 |
-
</a>
|
37 |
-
|
38 |
-
ํ
์คํธ ๋ถ๋๋ง ์ ์ฒด 12G ํ
์คํธ ์ค ์ผ๋ถ(144MB)๋ก ์ค์ฌ ํ์ต์ ์งํํฉ๋๋ค.
|
39 |
-
|
40 |
-
ํ๊ตญ์ด ๋ฐ์ดํฐ์
/์ฝํผ์ค๋ฅผ ์ข๋ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ [Korpora](https://github.com/ko-nlp/Korpora) ํจํค์ง๋ฅผ ์ฌ์ฉํฉ๋๋ค.
|
41 |
-
|
42 |
-
** Updates on 2020.09.08 **
|
43 |
-
|
44 |
-
Github Release๋ฅผ ํตํด ํ์ต ๋ฐ์ดํฐ๋ฅผ ์
๋ก๋ํ์์ต๋๋ค.
|
45 |
-
|
46 |
-
๋ค๋ง ํ ํ์ผ๋น 2GB ์ด๋ด์ ์ ์ฝ์ผ๋ก ์ธํด ๋ถํ ์์ถ๋์ด์์ต๋๋ค.
|
47 |
-
|
48 |
-
์๋ ๋งํฌ๋ฅผ ํตํด ๋ฐ์์ฃผ์ธ์. (๊ฐ์
์์ด ๋ฐ์ ์ ์์ด์. ๋ถํ ์์ถ)
|
49 |
-
|
50 |
-
๋ง์ฝ ํ ํ์ผ๋ก ๋ฐ๊ณ ์ถ์ผ์๊ฑฐ๋/Kaggle์์ ๋ฐ์ดํฐ๋ฅผ ์ดํด๋ณด๊ณ ์ถ์ผ์๋ค๋ฉด ์๋์ ์บ๊ธ ๋ฐ์ดํฐ์
์ ์ด์ฉํด์ฃผ์ธ์.
|
51 |
-
|
52 |
-
- Github๋ฆด๋ฆฌ์ฆ: https://github.com/Beomi/KcBERT/releases/tag/TrainData_v1
|
53 |
-
|
54 |
-
** Updates on 2020.08.22 **
|
55 |
-
|
56 |
-
Pretrain Dataset ๊ณต๊ฐ
|
57 |
-
|
58 |
-
- ์บ๊ธ: https://www.kaggle.com/junbumlee/kcbert-pretraining-corpus-korean-news-comments (ํ ํ์ผ๋ก ๋ฐ์ ์ ์์ด์. ๋จ์ผํ์ผ)
|
59 |
-
|
60 |
-
Kaggle์ ํ์ต์ ์ํด ์ ์ ํ(์๋ `clean`์ฒ๋ฆฌ๋ฅผ ๊ฑฐ์น) Dataset์ ๊ณต๊ฐํ์์ต๋๋ค!
|
61 |
-
|
62 |
-
์ง์ ๋ค์ด๋ฐ์ผ์
์ ๋ค์ํ Task์ ํ์ต์ ์งํํด๋ณด์ธ์ :)
|
63 |
-
|
64 |
-
---
|
65 |
-
|
66 |
-
๊ณต๊ฐ๋ ํ๊ตญ์ด BERT๋ ๋๋ถ๋ถ ํ๊ตญ์ด ์ํค, ๋ด์ค ๊ธฐ์ฌ, ์ฑ
๋ฑ ์ ์ ์ ๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ์ตํ ๋ชจ๋ธ์
๋๋ค. ํํธ, ์ค์ ๋ก NSMC์ ๊ฐ์ ๋๊ธํ ๋ฐ์ดํฐ์
์ ์ ์ ๋์ง ์์๊ณ ๊ตฌ์ด์ฒด ํน์ง์ ์ ์กฐ์ด๊ฐ ๋ง์ผ๋ฉฐ, ์คํ์ ๋ฑ ๊ณต์์ ์ธ ๊ธ์ฐ๊ธฐ์์ ๋ํ๋์ง ์๋ ํํ๋ค์ด ๋น๋ฒํ๊ฒ ๋ฑ์ฅํฉ๋๋ค.
|
67 |
-
|
68 |
-
KcBERT๋ ์์ ๊ฐ์ ํน์ฑ์ ๋ฐ์ดํฐ์
์ ์ ์ฉํ๊ธฐ ์ํด, ๋ค์ด๋ฒ ๋ด์ค์์ ๋๊ธ๊ณผ ๋๋๊ธ์ ์์งํด, ํ ํฌ๋์ด์ ์ BERT๋ชจ๋ธ์ ์ฒ์๋ถํฐ ํ์ตํ Pretrained BERT ๋ชจ๋ธ์
๋๋ค.
|
69 |
-
|
70 |
-
KcBERT๋ Huggingface์ Transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํตํด ๊ฐํธํ ๋ถ๋ฌ์ ์ฌ์ฉํ ์ ์์ต๋๋ค. (๋ณ๋์ ํ์ผ ๋ค์ด๋ก๋๊ฐ ํ์ํ์ง ์์ต๋๋ค.)
|
71 |
-
|
72 |
-
## KcBERT Performance
|
73 |
-
|
74 |
-
- Finetune ์ฝ๋๋ https://github.com/Beomi/KcBERT-finetune ์์ ์ฐพ์๋ณด์ค ์ ์์ต๋๋ค.
|
75 |
-
|
76 |
-
| | Size<br/>(์ฉ๋) | **NSMC**<br/>(acc) | **Naver NER**<br/>(F1) | **PAWS**<br/>(acc) | **KorNLI**<br/>(acc) | **KorSTS**<br/>(spearman) | **Question Pair**<br/>(acc) | **KorQuaD (Dev)**<br/>(EM/F1) |
|
77 |
-
| :-------------------- | :---: | :----------------: | :--------------------: | :----------------: | :------------------: | :-----------------------: | :-------------------------: | :---------------------------: |
|
78 |
-
| KcBERT-Base | 417M | 89.62 | 84.34 | 66.95 | 74.85 | 75.57 | 93.93 | 60.25 / 84.39 |
|
79 |
-
| KcBERT-Large | 1.2G | **90.68** | 85.53 | 70.15 | 76.99 | 77.49 | 94.06 | 62.16 / 86.64 |
|
80 |
-
| KoBERT | 351M | 89.63 | 86.11 | 80.65 | 79.00 | 79.64 | 93.93 | 52.81 / 80.27 |
|
81 |
-
| XLM-Roberta-Base | 1.03G | 89.49 | 86.26 | 82.95 | 79.92 | 79.09 | 93.53 | 64.70 / 88.94 |
|
82 |
-
| HanBERT | 614M | 90.16 | **87.31** | 82.40 | **80.89** | 83.33 | 94.19 | 78.74 / 92.02 |
|
83 |
-
| KoELECTRA-Base | 423M | **90.21** | 86.87 | 81.90 | 80.85 | 83.21 | 94.20 | 61.10 / 89.59 |
|
84 |
-
| KoELECTRA-Base-v2 | 423M | 89.70 | 87.02 | **83.90** | 80.61 | **84.30** | **94.72** | **84.34 / 92.58** |
|
85 |
-
| DistilKoBERT | 108M | 88.41 | 84.13 | 62.55 | 70.55 | 73.21 | 92.48 | 54.12 / 77.80 |
|
86 |
-
|
87 |
-
|
88 |
-
\*HanBERT์ Size๋ Bert Model๊ณผ Tokenizer DB๋ฅผ ํฉ์น ๊ฒ์
๋๋ค.
|
89 |
-
|
90 |
-
\***config์ ์ธํ
์ ๊ทธ๋๋ก ํ์ฌ ๋๋ฆฐ ๊ฒฐ๊ณผ์ด๋ฉฐ, hyperparameter tuning์ ์ถ๊ฐ์ ์ผ๋ก ํ ์ ๋ ์ข์ ์ฑ๋ฅ์ด ๋์ฌ ์ ์์ต๋๋ค.**
|
91 |
-
|
92 |
-
## How to use
|
93 |
-
|
94 |
-
### Requirements
|
95 |
-
|
96 |
-
- `pytorch <= 1.8.0`
|
97 |
-
- `transformers ~= 3.0.1`
|
98 |
-
- `transformers ~= 4.0.0` ๋ ํธํ๋ฉ๋๋ค.
|
99 |
-
- `emoji ~= 0.6.0`
|
100 |
-
- `soynlp ~= 0.0.493`
|
101 |
-
|
102 |
-
```python
|
103 |
-
from transformers import AutoTokenizer, AutoModelWithLMHead
|
104 |
-
|
105 |
-
# Base Model (108M)
|
106 |
-
|
107 |
-
tokenizer = AutoTokenizer.from_pretrained("beomi/kcbert-base")
|
108 |
-
|
109 |
-
model = AutoModelWithLMHead.from_pretrained("beomi/kcbert-base")
|
110 |
-
|
111 |
-
# Large Model (334M)
|
112 |
-
|
113 |
-
tokenizer = AutoTokenizer.from_pretrained("beomi/kcbert-large")
|
114 |
-
|
115 |
-
model = AutoModelWithLMHead.from_pretrained("beomi/kcbert-large")
|
116 |
-
```
|
117 |
-
|
118 |
-
### Pretrain & Finetune Colab ๋งํฌ ๋ชจ์
|
119 |
-
|
120 |
-
#### Pretrain Data
|
121 |
-
|
122 |
-
- [๋ฐ์ดํฐ์
๋ค์ด๋ก๋(Kaggle, ๋จ์ผํ์ผ, ๋ก๊ทธ์ธ ํ์)](https://www.kaggle.com/junbumlee/kcbert-pretraining-corpus-korean-news-comments)
|
123 |
-
- [๋ฐ์ดํฐ์
๋ค์ด๋ก๋(Github, ์์ถ ์ฌ๋ฌํ์ผ, ๋ก๊ทธ์ธ ๋ถํ์)](https://github.com/Beomi/KcBERT/releases/tag/TrainData_v1)
|
124 |
-
|
125 |
-
#### Pretrain Code
|
126 |
-
|
127 |
-
Colab์์ TPU๋ก KcBERT Pretrain ํด๋ณด๊ธฐ: <a href="https://colab.research.google.com/drive/1lYBYtaXqt9S733OXdXvrvC09ysKFN30W">
|
128 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
129 |
-
</a>
|
130 |
-
|
131 |
-
#### Finetune Samples
|
132 |
-
|
133 |
-
**KcBERT-Base** NSMC Finetuning with PyTorch-Lightning (Colab) <a href="https://colab.research.google.com/drive/1fn4sVJ82BrrInjq6y5655CYPP-1UKCLb?usp=sharing">
|
134 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
135 |
-
</a>
|
136 |
-
|
137 |
-
**KcBERT-Large** NSMC Finetuning with PyTorch-Lightning (Colab) <a href="https://colab.research.google.com/drive/1dFC0FL-521m7CL_PSd8RLKq67jgTJVhL?usp=sharing">
|
138 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
139 |
-
</a>
|
140 |
-
|
141 |
-
> ์ ๋ ์ฝ๋๋ Pretrain ๋ชจ๋ธ(base, large)์ batch size๋ง ๋ค๋ฅผ ๋ฟ, ๋๋จธ์ง ์ฝ๋๋ ์์ ํ ๋์ผํฉ๋๋ค.
|
142 |
-
|
143 |
-
## Train Data & Preprocessing
|
144 |
-
|
145 |
-
### Raw Data
|
146 |
-
|
147 |
-
ํ์ต ๋ฐ์ดํฐ๋ 2019.01.01 ~ 2020.06.15 ์ฌ์ด์ ์์ฑ๋ **๋๊ธ ๋ง์ ๋ด์ค** ๊ธฐ์ฌ๋ค์ **๋๊ธ๊ณผ ๋๋๊ธ**์ ๋ชจ๋ ์์งํ ๋ฐ์ดํฐ์
๋๋ค.
|
148 |
-
|
149 |
-
๋ฐ์ดํฐ ์ฌ์ด์ฆ๋ ํ
์คํธ๋ง ์ถ์ถ์ **์ฝ 15.4GB์ด๋ฉฐ, 1์ต1์ฒ๋ง๊ฐ ์ด์์ ๋ฌธ์ฅ**์ผ๋ก ์ด๋ค์ ธ ์์ต๋๋ค.
|
150 |
-
|
151 |
-
### Preprocessing
|
152 |
-
|
153 |
-
PLM ํ์ต์ ์ํด์ ์ ์ฒ๋ฆฌ๋ฅผ ์งํํ ๊ณผ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
|
154 |
-
|
155 |
-
1. ํ๊ธ ๋ฐ ์์ด, ํน์๋ฌธ์, ๊ทธ๋ฆฌ๊ณ ์ด๋ชจ์ง(๐ฅณ)๊น์ง!
|
156 |
-
|
157 |
-
์ ๊ทํํ์์ ํตํด ํ๊ธ, ์์ด, ํน์๋ฌธ์๋ฅผ ํฌํจํด Emoji๊น์ง ํ์ต ๋์์ ํฌํจํ์ต๋๋ค.
|
158 |
-
|
159 |
-
ํํธ, ํ๊ธ ๋ฒ์๋ฅผ `ใฑ-ใ
๊ฐ-ํฃ` ์ผ๋ก ์ง์ ํด `ใฑ-ํฃ` ๋ด์ ํ์๋ฅผ ์ ์ธํ์ต๋๋ค.
|
160 |
-
|
161 |
-
2. ๋๊ธ ๋ด ์ค๋ณต ๋ฌธ์์ด ์ถ์ฝ
|
162 |
-
|
163 |
-
`ใ
ใ
ใ
ใ
ใ
`์ ๊ฐ์ด ์ค๋ณต๋ ๊ธ์๋ฅผ `ใ
ใ
`์ ๊ฐ์ ๊ฒ์ผ๋ก ํฉ์ณค์ต๋๋ค.
|
164 |
-
|
165 |
-
3. Cased Model
|
166 |
-
|
167 |
-
KcBERT๋ ์๋ฌธ์ ๋ํด์๋ ๋์๋ฌธ์๋ฅผ ์ ์งํ๋ Cased model์
๋๋ค.
|
168 |
-
|
169 |
-
4. ๊ธ์ ๋จ์ 10๊ธ์ ์ดํ ์ ๊ฑฐ
|
170 |
-
|
171 |
-
10๊ธ์ ๋ฏธ๋ง์ ํ
์คํธ๋ ๋จ์ผ ๋จ์ด๋ก ์ด๋ค์ง ๊ฒฝ์ฐ๊ฐ ๋ง์ ํด๋น ๋ถ๋ถ์ ์ ์ธํ์ต๋๋ค.
|
172 |
-
|
173 |
-
5. ์ค๋ณต ์ ๊ฑฐ
|
174 |
-
|
175 |
-
์ค๋ณต์ ์ผ๋ก ์ฐ์ธ ๋๊ธ์ ์ ๊ฑฐํ๊ธฐ ์ํด ์ค๋ณต ๋๊ธ์ ํ๋๋ก ํฉ์ณค์ต๋๋ค.
|
176 |
-
|
177 |
-
์ด๋ฅผ ํตํด ๋ง๋ ์ต์ข
ํ์ต ๋ฐ์ดํฐ๋ **12.5GB, 8.9์ฒ๋ง๊ฐ ๋ฌธ์ฅ**์
๋๋ค.
|
178 |
-
|
179 |
-
์๋ ๋ช
๋ น์ด๋ก pip๋ก ์ค์นํ ๋ค, ์๋ cleanํจ์๋ก ํด๋ฆฌ๋์ ํ๋ฉด Downstream task์์ ๋ณด๋ค ์ฑ๋ฅ์ด ์ข์์ง๋๋ค. (`[UNK]` ๊ฐ์)
|
180 |
-
|
181 |
-
```bash
|
182 |
-
pip install soynlp emoji
|
183 |
-
```
|
184 |
-
|
185 |
-
์๋ `clean` ํจ์๋ฅผ Text data์ ์ฌ์ฉํด์ฃผ์ธ์.
|
186 |
-
|
187 |
-
```python
|
188 |
-
import re
|
189 |
-
import emoji
|
190 |
-
from soynlp.normalizer import repeat_normalize
|
191 |
-
|
192 |
-
emojis = list({y for x in emoji.UNICODE_EMOJI.values() for y in x.keys()})
|
193 |
-
emojis = ''.join(emojis)
|
194 |
-
pattern = re.compile(f'[^ .,?!/@$%~๏ผ
ยทโผ()\x00-\x7Fใฑ-ใ
ฃ๊ฐ-ํฃ{emojis}]+')
|
195 |
-
url_pattern = re.compile(
|
196 |
-
r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)')
|
197 |
-
|
198 |
-
def clean(x):
|
199 |
-
x = pattern.sub(' ', x)
|
200 |
-
x = url_pattern.sub('', x)
|
201 |
-
x = x.strip()
|
202 |
-
x = repeat_normalize(x, num_repeats=2)
|
203 |
-
return x
|
204 |
-
```
|
205 |
-
|
206 |
-
### Cleaned Data (Released on Kaggle)
|
207 |
-
|
208 |
-
์๋ณธ ๋ฐ์ดํฐ๋ฅผ ์ `clean`ํจ์๋ก ์ ์ ํ 12GB๋ถ๋์ txt ํ์ผ์ ์๋ Kaggle Dataset์์ ๋ค์ด๋ฐ์ผ์ค ์ ์์ต๋๋ค :)
|
209 |
-
|
210 |
-
https://www.kaggle.com/junbumlee/kcbert-pretraining-corpus-korean-news-comments
|
211 |
-
|
212 |
-
|
213 |
-
## Tokenizer Train
|
214 |
-
|
215 |
-
Tokenizer๋ Huggingface์ [Tokenizers](https://github.com/huggingface/tokenizers) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํตํด ํ์ต์ ์งํํ์ต๋๋ค.
|
216 |
-
|
217 |
-
๊ทธ ์ค `BertWordPieceTokenizer` ๋ฅผ ์ด์ฉํด ํ์ต์ ์งํํ๊ณ , Vocab Size๋ `30000`์ผ๋ก ์งํํ์ต๋๋ค.
|
218 |
-
|
219 |
-
Tokenizer๋ฅผ ํ์ตํ๋ ๊ฒ์๋ `1/10`๋ก ์ํ๋งํ ๋ฐ์ดํฐ๋ก ํ์ต์ ์งํํ๊ณ , ๋ณด๋ค ๊ณจ๊ณ ๋ฃจ ์ํ๋งํ๊ธฐ ์ํด ์ผ์๋ณ๋ก stratify๋ฅผ ์ง์ ํ ๋ค ํ์ต์ ์งํํ์ต๋๋ค.
|
220 |
-
|
221 |
-
## BERT Model Pretrain
|
222 |
-
|
223 |
-
- KcBERT Base config
|
224 |
-
|
225 |
-
```json
|
226 |
-
{
|
227 |
-
"max_position_embeddings": 300,
|
228 |
-
"hidden_dropout_prob": 0.1,
|
229 |
-
"hidden_act": "gelu",
|
230 |
-
"initializer_range": 0.02,
|
231 |
-
"num_hidden_layers": 12,
|
232 |
-
"type_vocab_size": 2,
|
233 |
-
"vocab_size": 30000,
|
234 |
-
"hidden_size": 768,
|
235 |
-
"attention_probs_dropout_prob": 0.1,
|
236 |
-
"directionality": "bidi",
|
237 |
-
"num_attention_heads": 12,
|
238 |
-
"intermediate_size": 3072,
|
239 |
-
"architectures": [
|
240 |
-
"BertForMaskedLM"
|
241 |
-
],
|
242 |
-
"model_type": "bert"
|
243 |
-
}
|
244 |
-
```
|
245 |
-
|
246 |
-
- KcBERT Large config
|
247 |
-
|
248 |
-
```json
|
249 |
-
{
|
250 |
-
"type_vocab_size": 2,
|
251 |
-
"initializer_range": 0.02,
|
252 |
-
"max_position_embeddings": 300,
|
253 |
-
"vocab_size": 30000,
|
254 |
-
"hidden_size": 1024,
|
255 |
-
"hidden_dropout_prob": 0.1,
|
256 |
-
"model_type": "bert",
|
257 |
-
"directionality": "bidi",
|
258 |
-
"pad_token_id": 0,
|
259 |
-
"layer_norm_eps": 1e-12,
|
260 |
-
"hidden_act": "gelu",
|
261 |
-
"num_hidden_layers": 24,
|
262 |
-
"num_attention_heads": 16,
|
263 |
-
"attention_probs_dropout_prob": 0.1,
|
264 |
-
"intermediate_size": 4096,
|
265 |
-
"architectures": [
|
266 |
-
"BertForMaskedLM"
|
267 |
-
]
|
268 |
-
}
|
269 |
-
```
|
270 |
-
|
271 |
-
BERT Model Config๋ Base, Large ๊ธฐ๋ณธ ์ธํ
๊ฐ์ ๊ทธ๋๋ก ์ฌ์ฉํ์ต๋๋ค. (MLM 15% ๋ฑ)
|
272 |
-
|
273 |
-
TPU `v3-8` ์ ์ด์ฉํด ๊ฐ๊ฐ 3์ผ, N์ผ(Large๋ ํ์ต ์งํ ์ค)์ ์งํํ๊ณ , ํ์ฌ Huggingface์ ๊ณต๊ฐ๋ ๋ชจ๋ธ์ 1m(100๋ง) step์ ํ์ตํ ckpt๊ฐ ์
๋ก๋ ๋์ด์์ต๋๋ค.
|
274 |
-
|
275 |
-
๋ชจ๋ธ ํ์ต Loss๋ Step์ ๋ฐ๋ผ ์ด๊ธฐ 200k์ ๊ฐ์ฅ ๋น ๋ฅด๊ฒ Loss๊ฐ ์ค์ด๋ค๋ค 400k์ดํ๋ก๋ ์กฐ๊ธ์ฉ ๊ฐ์ํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
|
276 |
-
|
277 |
-
- Base Model Loss
|
278 |
-
|
279 |
-
![KcBERT-Base Pretraining Loss](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200719183852243.38b124.png)
|
280 |
-
|
281 |
-
- Large Model Loss
|
282 |
-
|
283 |
-
![KcBERT-Large Pretraining Loss](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200806160746694.d56fa1.png)
|
284 |
-
|
285 |
-
ํ์ต์ GCP์ TPU v3-8์ ์ด์ฉํด ํ์ต์ ์งํํ๊ณ , ํ์ต ์๊ฐ์ Base Model ๊ธฐ์ค 2.5์ผ์ ๋ ์งํํ์ต๋๋ค. Large Model์ ์ฝ 5์ผ์ ๋ ์งํํ ๋ค ๊ฐ์ฅ ๋ฎ์ loss๋ฅผ ๊ฐ์ง ์ฒดํฌํฌ์ธํธ๋ก ์ ํ์ต๋๋ค.
|
286 |
-
|
287 |
-
## Example
|
288 |
-
|
289 |
-
### HuggingFace MASK LM
|
290 |
-
|
291 |
-
[HuggingFace kcbert-base ๋ชจ๋ธ](https://huggingface.co/beomi/kcbert-base?text=์ค๋์+๋ ์จ๊ฐ+[MASK]) ์์ ์๋์ ๊ฐ์ด ํ
์คํธ ํด ๋ณผ ์ ์์ต๋๋ค.
|
292 |
-
|
293 |
-
![์ค๋์ ๋ ์จ๊ฐ "์ข๋ค์", KcBERT-Base](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200719205919389.5670d6.png)
|
294 |
-
|
295 |
-
๋ฌผ๋ก [kcbert-large ๋ชจ๋ธ](https://huggingface.co/beomi/kcbert-large?text=์ค๋์+๋ ์จ๊ฐ+[MASK]) ์์๋ ํ
์คํธ ํ ์ ์์ต๋๋ค.
|
296 |
-
|
297 |
-
![image-20200806160624340](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200806160624340.58f9be.png)
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
### NSMC Binary Classification
|
302 |
-
|
303 |
-
[๋ค์ด๋ฒ ์ํํ ์ฝํผ์ค](https://github.com/e9t/nsmc) ๋ฐ์ดํฐ์
์ ๋์์ผ๋ก Fine Tuning์ ์งํํด ์ฑ๋ฅ์ ๊ฐ๋จํ ํ
์คํธํด๋ณด์์ต๋๋ค.
|
304 |
-
|
305 |
-
Base Model์ Fine Tuneํ๋ ์ฝ๋๋ <a href="https://colab.research.google.com/drive/1fn4sVJ82BrrInjq6y5655CYPP-1UKCLb?usp=sharing">
|
306 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
307 |
-
</a> ์์ ์ง์ ์คํํด๋ณด์ค ์ ์์ต๋๋ค.
|
308 |
-
|
309 |
-
Large Model์ Fine Tuneํ๋ ์ฝ๋๋ <a href="https://colab.research.google.com/drive/1dFC0FL-521m7CL_PSd8RLKq67jgTJVhL?usp=sharing">
|
310 |
-
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
311 |
-
</a> ์์ ์ง์ ์คํํด๋ณผ ์ ์์ต๋๋ค.
|
312 |
-
|
313 |
-
- GPU๋ P100 x1๋ ๊ธฐ์ค 1epoch์ 2-3์๊ฐ, TPU๋ 1epoch์ 1์๊ฐ ๋ด๋ก ์์๋ฉ๋๋ค.
|
314 |
-
- GPU RTX Titan x4๋ ๊ธฐ์ค 30๋ถ/epoch ์์๋ฉ๋๋ค.
|
315 |
-
- ์์ ์ฝ๋๋ [pytorch-lightning](https://github.com/PyTorchLightning/pytorch-lightning)์ผ๋ก ๊ฐ๋ฐํ์ต๋๋ค.
|
316 |
-
|
317 |
-
#### ์คํ๊ฒฐ๊ณผ
|
318 |
-
|
319 |
-
- KcBERT-Base Model ์คํ๊ฒฐ๊ณผ: Val acc `.8905`
|
320 |
-
|
321 |
-
![KcBERT Base finetune on NSMC](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200719201102895.ddbdfc.png)
|
322 |
-
|
323 |
-
- KcBERT-Large Model ์คํ ๊ฒฐ๊ณผ: Val acc `.9089`
|
324 |
-
|
325 |
-
![image-20200806190242834](https://raw.githubusercontent.com/Beomi/KcBERT/master/img/image-20200806190242834.56d6ee.png)
|
326 |
-
|
327 |
-
> ๋ ๋ค์ํ Downstream Task์ ๋ํด ํ
์คํธ๋ฅผ ์งํํ๊ณ ๊ณต๊ฐํ ์์ ์
๋๋ค.
|
328 |
-
|
329 |
-
## ์ธ์ฉํ๊ธฐ/Citation
|
330 |
-
|
331 |
-
KcBERT๋ฅผ ์ธ์ฉํ์ค ๋๋ ์๋ ์์์ ํตํด ์ธ์ฉํด์ฃผ์ธ์.
|
332 |
-
|
333 |
-
```
|
334 |
-
@inproceedings{lee2020kcbert,
|
335 |
-
title={KcBERT: Korean Comments BERT},
|
336 |
-
author={Lee, Junbum},
|
337 |
-
booktitle={Proceedings of the 32nd Annual Conference on Human and Cognitive Language Technology},
|
338 |
-
pages={437--440},
|
339 |
-
year={2020}
|
340 |
-
}
|
341 |
-
```
|
342 |
-
|
343 |
-
- ๋
ผ๋ฌธ์ง ๋ค์ด๋ก๋ ๋งํฌ: http://hclt.kr/dwn/?v=bG5iOmNvbmZlcmVuY2U7aWR4OjMy (*ํน์ http://hclt.kr/symp/?lnb=conference )
|
344 |
-
|
345 |
-
## Acknowledgement
|
346 |
-
|
347 |
-
KcBERT Model์ ํ์ตํ๋ GCP/TPU ํ๊ฒฝ์ [TFRC](https://www.tensorflow.org/tfrc?hl=ko) ํ๋ก๊ทธ๋จ์ ์ง์์ ๋ฐ์์ต๋๋ค.
|
348 |
-
|
349 |
-
๋ชจ๋ธ ํ์ต ๊ณผ์ ์์ ๋ง์ ์กฐ์ธ์ ์ฃผ์ [Monologg](https://github.com/monologg/) ๋ ๊ฐ์ฌํฉ๋๋ค :)
|
350 |
-
|
351 |
-
## Reference
|
352 |
-
|
353 |
-
### Github Repos
|
354 |
-
|
355 |
-
- [BERT by Google](https://github.com/google-research/bert)
|
356 |
-
- [KoBERT by SKT](https://github.com/SKTBrain/KoBERT)
|
357 |
-
- [KoELECTRA by Monologg](https://github.com/monologg/KoELECTRA/)
|
358 |
-
|
359 |
-
- [Transformers by Huggingface](https://github.com/huggingface/transformers)
|
360 |
-
- [Tokenizers by Hugginface](https://github.com/huggingface/tokenizers)
|
361 |
-
|
362 |
-
### Papers
|
363 |
-
|
364 |
-
- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)
|
365 |
-
|
366 |
-
### Blogs
|
367 |
-
|
368 |
-
- [Monologg๋์ KoELECTRA ํ์ต๊ธฐ](https://monologg.kr/categories/NLP/ELECTRA/)
|
369 |
-
- [Colab์์ TPU๋ก BERT ์ฒ์๋ถํฐ ํ์ต์ํค๊ธฐ - Tensorflow/Google ver.](https://beomi.github.io/2020/02/26/Train-BERT-from-scratch-on-colab-TPU-Tensorflow-ver/)
|
370 |
-
|
|
|
3 |
license: apache-2.0
|
4 |
tags:
|
5 |
- korean
|
6 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|