Kaggle에 학습을 위해 정제한(아래
clean
처리를 거친) Dataset을 공개하였습니다!
직접 다운받으셔서 다양한 Task에 학습을 진행해보세요 :)
공개된 한국어 BERT는 대부분 한국어 위키, 뉴스 기사, 책 등 잘 정제된 데이터를 기반으로 학습한 모델입니다. 한편, 실제로 NSMC와 같은 댓글형 데이터셋은 정제되지 않았고 구어체 특징에 신조어가 많으며, 오탈자 등 공식적인 글쓰기에서 나타나지 않는 표현들이 빈번하게 등장합니다.
KcBERT는 위와 같은 특성의 데이터셋에 적용하기 위해, 네이버 뉴스에서 댓글과 대댓글을 수집해, 토크나이저와 BERT모델을 처음부터 학습한 Pretrained BERT 모델입니다.
KcBERT는 Huggingface의 Transformers 라이브러리를 통해 간편히 불러와 사용할 수 있습니다. (별도의 파일 다운로드가 필요하지 않습니다.)
*HanBERT의 Size는 Bert Model과 Tokenizer DB를 합친 것입니다.
*
config의 세팅을 그대로 하여 돌린 결과이며, hyperparameter tuning을 추가적으로 할 시 더 좋은 성능이 나올 수 있습니다.
How to use
Requirements
pytorch <= 1.8.0
transformers ~= 3.0.1
transformers ~= 4.0.0
도 호환됩니다.
emoji ~= 0.6.0
soynlp ~= 0.0.493
from transformers import AutoTokenizer, AutoModelWithLMHead
# Base Model (108M)
tokenizer = AutoTokenizer.from_pretrained("beomi/kcbert-base")
model = AutoModelWithLMHead.from_pretrained("beomi/kcbert-base")
# Large Model (334M)
tokenizer = AutoTokenizer.from_pretrained("beomi/kcbert-large")
model = AutoModelWithLMHead.from_pretrained("beomi/kcbert-large")
KcBERT-Base
NSMC Finetuning with PyTorch-Lightning (Colab)
KcBERT-Large
NSMC Finetuning with PyTorch-Lightning (Colab)
위 두 코드는 Pretrain 모델(base, large)와 batch size만 다를 뿐, 나머지 코드는 완전히 동일합니다.
Train Data & Preprocessing
Raw Data
학습 데이터는 2019.01.01 ~ 2020.06.15 사이에 작성된
댓글 많은 뉴스
기사들의
댓글과 대댓글
을 모두 수집한 데이터입니다.
데이터 사이즈는 텍스트만 추출시
약 15.4GB이며, 1억1천만개 이상의 문장
으로 이뤄져 있습니다.
Preprocessing
PLM 학습을 위해서 전처리를 진행한 과정은 다음과 같습니다.
한글 및 영어, 특수문자, 그리고 이모지(🥳)까지!
정규표현식을 통해 한글, 영어, 특수문자를 포함해 Emoji까지 학습 대상에 포함했습니다.
한편, 한글 범위를
ㄱ-ㅎ가-힣
으로 지정해
ㄱ-힣
내의 한자를 제외했습니다.
댓글 내 중복 문자열 축약
ㅋㅋㅋㅋㅋ
와 같이 중복된 글자를
ㅋㅋ
와 같은 것으로 합쳤습니다.
Cased Model
KcBERT는 영문에 대해서는 대소문자를 유지하는 Cased model입니다.
글자 단위 10글자 이하 제거
10글자 미만의 텍스트는 단일 단어로 이뤄진 경우가 많아 해당 부분을 제외했습니다.
중복 제거
중복적으로 쓰인 댓글을 제거하기 위해 중복 댓글을 하나로 합쳤습니다.
이를 통해 만든 최종 학습 데이터는
12.5GB, 8.9천만개 문장
입니다.
아래 명령어로 pip로 설치한 뒤, 아래 clean함수로 클리닝을 하면 Downstream task에서 보다 성능이 좋아집니다. (
[UNK]
감소)
pip install soynlp emoji
아래
clean
함수를 Text data에 사용해주세요.
import re
import emoji
from soynlp.normalizer import repeat_normalize
emojis = list({y for x in emoji.UNICODE_EMOJI.values() for y in x.keys()})
emojis = ''.join(emojis)
pattern = re.compile(f'[^ .,?!/@$%~%·∼()\x00-\x7Fㄱ-ㅣ가-힣{emojis}]+')
url_pattern = re.compile(
r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)')
defclean(x):
x = pattern.sub(' ', x)
x = url_pattern.sub('', x)
x = x.strip()
x = repeat_normalize(x, num_repeats=2)
return x
Cleaned Data (Released on Kaggle)
원본 데이터를 위
clean
함수로 정제한 12GB분량의 txt 파일을 아래 Kaggle Dataset에서 다운받으실 수 있습니다 :)
@inproceedings{lee2020kcbert,
title={KcBERT: Korean Comments BERT},
author={Lee, Junbum},
booktitle={Proceedings of the 32nd Annual Conference on Human and Cognitive Language Technology},
pages={437--440},
year={2020}
}
kcbert-base huggingface.co is an AI model on huggingface.co that provides kcbert-base's model effect (), which can be used instantly with this beomi kcbert-base model. huggingface.co supports a free trial of the kcbert-base model, and also provides paid use of the kcbert-base. Support call kcbert-base model through api, including Node.js, Python, http.
kcbert-base huggingface.co is an online trial and call api platform, which integrates kcbert-base's modeling effects, including api services, and provides a free online trial of kcbert-base, you can try kcbert-base online for free by clicking the link below.
beomi kcbert-base online free url in huggingface.co:
kcbert-base is an open source model from GitHub that offers a free installation service, and any user can find kcbert-base on GitHub to install. At the same time, huggingface.co provides the effect of kcbert-base install, users can directly use kcbert-base installed effect in huggingface.co for debugging and trial. It also supports api for free installation.