Distillation of KoBERT from SKTBrain (Lightweight KoBERT)
Distillation of KoBERT (SKTBrain KoBERT
경량화)
January 27th, 2020 - Update: 10GB의 Corpus를 가지고 새로 학습하였습니다. Subtask에서 성능이 소폭 상승했습니다.
May 14th, 2020 - Update: 기존 Transformers의 padding_idx
이슈를 해결하였습니다. 자세한 사항은 KoBERT-Transformers를 참고하시면 됩니다.
>>> from transformers import BertModel, DistilBertModel
>>> bert_model = BertModel.from_pretrained('monologg/kobert')
>>> distilbert_model = DistilBertModel.from_pretrained('monologg/distilkobert')
tokenization_kobert.py
파일을 복사한 후, KoBertTokenizer
를 임포트하면 됩니다.
>>> from tokenization_kobert import KoBertTokenizer
>>> tokenizer = KoBertTokenizer.from_pretrained('monologg/kobert') # monologg/distilkobert도 동일
>>> tokenizer.tokenize("[CLS] 한국어 모델을 공유합니다. [SEP]")
['[CLS]', '▁한국', '어', '▁모델', '을', '▁공유', '합니다', '.', '[SEP]']
>>> tokenizer.convert_tokens_to_ids(['[CLS]', '▁한국', '어', '▁모델', '을', '▁공유', '합니다', '.', '[SEP]'])
[2, 4958, 6855, 2046, 7088, 1050, 7843, 54, 3]
DistilBert는 기존의 Bert와 달리 token-type embedding을 사용하지 않습니다.
token_type_ids
를 넣을 필요가 없습니다.또한 DistilBert는 pooler를 사용하지 않습니다.
sequence_output, pooled_output, (hidden_states), (attentions)
을 뽑아내지만, DistilBertModel의 경우 sequence_output, (hidden_states), (attentions)
를 뽑아냅니다.[CLS]
토큰을 뽑아내려면 sequence_output[0][:, 0]
를 적용해야 합니다.KoBERT | DistilKoBERT | Bert-multilingual | |
---|---|---|---|
Model Size (MB) | 351 | 108 | 681 |
NSMC (acc) | 89.63 | 88.41 | 87.07 |
Naver NER (F1) | 86.11 | 84.13 | 84.20 |
KorQuAD (Dev) (EM/F1) | 52.81/80.27 | 54.12/77.80 | 77.04/87.85 |
이 코드를 연구용으로 사용하는 경우 아래와 같이 인용해주세요.
@misc{park2019distilkobert,
author = {Park, Jangwon},
title = {DistilKoBERT: Distillation of KoBERT},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/monologg/DistilKoBERT}}
}