All Projects → SKplanet → Dialog-KoELECTRA

SKplanet / Dialog-KoELECTRA

Licence: Apache-2.0 License
ELECTRA기반 한국어 대화체 언어모델

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Dialog-KoELECTRA

Android-Shortify
An Android library used for making an Android application more faster with less amount of code. Shortify for Android provides basic functionalities of view and resource binding, view customization, JSON parsing, AJAX, various readymade dialogs and much more.
Stars: ✭ 21 (-44.74%)
Mutual labels:  dialog
permuted-bAbI-dialog-tasks
Dataset for 'Learning End-to-End Goal-Oriented Dialog with Multiple Answers' EMNLP 2018
Stars: ✭ 17 (-55.26%)
Mutual labels:  dialog
ak-vue3
组件库包含了 AutoForm 自动表单、BackTop 返回顶部、Breadcrumb 面包屑、 Button 按钮、Cascader 级联选择器、Checkbox 多选框、Collapse 折叠面板、ColorPicker 颜色选择器、DataPicker 时间选择器、Dialog 弹层对话框、Alert 弹框、Echarts 图形图表、Form 表单、Input 输入框、Lazy 图片延时加载、Loading 加载等待、Menu 菜单、Pagination 分页、Progress 进度条、Radio 单选框、Select 选择器、Steps 步骤条、Swiper 图片轮播、Switch 开关、Table 表格、Tabs 标签页、Textarea 文本框、Tooltip 提示、Tr…
Stars: ✭ 24 (-36.84%)
Mutual labels:  dialog
DSTC6-End-to-End-Conversation-Modeling
DSTC6: End-to-End Conversation Modeling Track
Stars: ✭ 56 (+47.37%)
Mutual labels:  dialog
Licenser
An android library to display the licenses of your application libraries in a easy way.
Stars: ✭ 75 (+97.37%)
Mutual labels:  dialog
AVSD-DSTC10 Official
Audio Visual Scene-Aware Dialog (AVSD) Challenge at the 10th Dialog System Technology Challenge (DSTC)
Stars: ✭ 22 (-42.11%)
Mutual labels:  dialog
P-tuning-v2
Source code and data for ACL 2022 paper "P-tuning v2: Prompt Tuning Can Be Comparable to Fine-tuning Across Scales and Tasks"
Stars: ✭ 373 (+881.58%)
Mutual labels:  pretrained-language-model
FRDialog
用Builder模式重新打造一个dialog
Stars: ✭ 86 (+126.32%)
Mutual labels:  dialog
AudioVisualSceneAwareDialog
No description or website provided.
Stars: ✭ 22 (-42.11%)
Mutual labels:  dialog
TaskDialog
.NET implementation of the Windows Task Dialog.
Stars: ✭ 48 (+26.32%)
Mutual labels:  dialog
react-native-wxui
A UI package for React Native
Stars: ✭ 21 (-44.74%)
Mutual labels:  dialog
opensnips
Open source projects related to Snips https://snips.ai/.
Stars: ✭ 50 (+31.58%)
Mutual labels:  dialog
android-versioninfo
A version info widget for Android. Material style.
Stars: ✭ 21 (-44.74%)
Mutual labels:  dialog
plain-modal
The simple library for customizable modal window.
Stars: ✭ 21 (-44.74%)
Mutual labels:  dialog
ContrastiveLearning4Dialogue
The codebase for "Group-wise Contrastive Learning for Neural Dialogue Generation" (Cai et al., Findings of EMNLP 2020)
Stars: ✭ 54 (+42.11%)
Mutual labels:  dialog
bootstrap-cookie-consent-settings
A modal dialog (cookie banner) and framework to handle the German and EU law about cookies in a website. Needs Bootstrap.
Stars: ✭ 25 (-34.21%)
Mutual labels:  dialog
TheBashMenu
A useful bash script allowing you to easily create your own menu, which uses the directional keys! Quickly add your title, options and commands and you're good to go!
Stars: ✭ 52 (+36.84%)
Mutual labels:  dialog
JavaUltimateTools
A Large Repository Of Awesome Code For Java.
Stars: ✭ 24 (-36.84%)
Mutual labels:  dialog
soloalert
A customizable lightweight Alert Library with Material UI and awesome features.
Stars: ✭ 18 (-52.63%)
Mutual labels:  dialog
CODER
CODER: Knowledge infused cross-lingual medical term embedding for term normalization. [JBI, ACL-BioNLP 2022]
Stars: ✭ 24 (-36.84%)
Mutual labels:  pretrained-language-model

license

한국어 대화체 언어모델 (Dialog-KoELECTRA)

facebook_cover_photo_2

모델 소개

Dialog-KoELECTRA는 대화체에 특화된 언어 모델입니다. 대화체는 채팅이나 통화에서 사용하는 어체를 말합니다. 기존 언어 모델들이 문어체를 기반으로 학습 되었기 때문에 저희는 대화체에 적합한 언어 모델을 만들게 되었습니다. 또한, 실제 서비스에 적합한 가벼운 모델을 만들고자 하여 small 모델부터 공개하게 되었습니다. Dialog-KoELECTRA 모델은 가볍지만 대화체 태스크에서는 기존 base 모델과 비슷한 성능을 보여줍니다.

Dialog-KoELECTRA 모델은 22GB의 대화체 및 문어체 한글 텍스트 데이터로 훈련되었습니다. Dialog-KoELECTRA 모델은 ELECTRA 모델을 기반으로 만들어졌습니다. ELECTRA는 자가지도 언어 표현 학습 방법으로 비교적 적은 계산을 사용하여 사전 언어 모델을 훈련할 수 있습니다. ELECTRA 모델은 GAN과 유사하게 생성자가 생성한 "가짜" 입력 토큰과 "실제" 입력 토큰을 판별자가 구별하도록 훈련되었습니다. ELECTRA는 단일 GPU에서 학습했을 때도 강력한 결과를 얻을 수 있는 장점을 가지고 있습니다.

모델 차별점

  • 최적의 어휘 사전 생성
    • 여러 파라미터 값 조합 실험을 통해 어휘 사전 생성시 최적의 값으로 설정
  • 최적의 대화체/문어체 데이터 비율 구성
    • 대화체와 문어체 데이터 비율 조합을 통해 대화체 성능 향상
  • 형태소 분석 기반 토크나이저 사용
    • 한글 처리에 적합한 형태소 분석 결과를 subword 기반의 tokenizer 입력으로 사용하여 어휘 사전 생성
  • 사전 학습시 mixed precision 적용
    • 사전 훈련 중에 mixed precision 옵션을 사용하여 학습 속도 향상 및 메모리 절약
  • fine-tuning시 NNI 옵션 사용 가능
    • 모델 fine-tuning시 NNI 옵션을 사용하여 파라미터 최적화가 가능

모델 배포

서비스에 적합한 small 버전을 먼저 출시하였고 향후 base 모델 등 다른 모델도 출시 할 예정입니다.
아래 두가지 방법을 통해 학습된 모델을 받아 사용할 수 있습니다.

Model Layers Hidden Size Params Max
Seq Len
Learning
Rate
Batch Size Train Steps Train Time
Dialog-KoELECTRA-Small 12 256 14M 128 1e-4 512 1M 28일

1. transformers 라이브러리

Dialog-KoELECTRA 모델은 Hugging Face에 업로드되어 있어 쉽게 사용 가능합니다.

from transformers import ElectraTokenizer, ElectraForSequenceClassification
  
tokenizer = ElectraTokenizer.from_pretrained("skplanet/dialog-koelectra-small-discriminator")

model = ElectraForSequenceClassification.from_pretrained("skplanet/dialog-koelectra-small-discriminator")

2. 직접 다운로드

Transformers 라이브러리를 사용하지 않고 직접 모델을 다운로드하려면 아래 링크를 통해 다운로드 할 수 있습니다.


Model Pytorch-Generator Pytorch-Discriminator Tensorflow-v1 ONNX
Dialog-KoELECTRA-Small link link link link

모델 성능

대화체 문어체
NSMC (acc) Question Pair (acc) Korean-Hate-Speech (F1) Naver NER (F1) KorNLI (acc) KorSTS (spearman)
DistilKoBERT 88.60 92.48 60.72 84.65 72.00 72.59
KoELECTRA-Small 89.36 94.85 63.07 85.40 78.60 80.79
Dialog-KoELECTRA-Small 90.01 94.99 68.26 85.51 78.54 78.96

학습 데이터

corpus name size
대화체 Aihub Korean dialog corpus 7GB
NIKL Spoken corpus
Korean chatbot data
KcBERT
문어체 NIKL Newspaper corpus 15GB
namuwikitext

어휘 사전

어휘 사전 생성시 huggingface_konlpy를 이용한 형태소 분석을 적용했습니다.
실험 결과, 형태소 분석을 적용하지 않고 만든 어휘 사전보다 더 나은 성능을 보였습니다.

vocabulary size unused token size limit alphabet min frequency
40,000 500 6,000 3

데모


코드 사용 방법

Pre-training

1. 전처리

preprocess.py를 사용하여 데이터 전처리를 수행합니다. 데이터 전처리는 반복되는 문자를 축약하고 한자를 제거하는 작업을 수행합니다.

  • --corpus_dir: 텍스트 파일을 포함하는 디렉토리
  • --output_file: 전처리 후 생성 되는 파일명

실행 예시

python3 preprocess.py \
    --corpus_dir raw_data_dir \
    --output_file preprocessed_data.txt \

2. 어휘 사전 생성

build_vocab.py를 사용하여 텍스트 데이터에서 어휘 파일을 만듭니다.

  • --corpus: 어휘 파일로 변환 할 텍스트 파일
  • --tokenizer: wordpiece / mecab_wordpiece와 같은 토크나이저 (기본값 : wordpiece)
  • --vocab_size: 어휘사전 단어 수 (기본값 : 40000)
  • --min_frequency: 토큰 페어가 병합 작업을 수행하는데 필요한 최소 빈도 (기본값 : 3)
  • --limit_alphabet: 병합을 계산하기 전에 보관할 수있는 초기 토큰 수 (기본값 : 6000)
  • --unused_size: 사전의 범용성을 위한 unused 개수 (기본값 : 500)

실행 예시

python3 build_vocab.py \
    --corpus preprocessed_data.txt \
    --tokenizer mecab_wordpiece \
    --vocab_size 40000 \
    --min_frequency 3 \
    --limit_alphabet 6000 \
    --unused_size 500

3. tfrecord 생성

build_pretraining_dataset.py를 사용하여 사전학습을 위한 tfrecord를 생성합니다.

  • --corpus_dir: tfrecord로 전환 할 텍스트 파일이 포함 된 디렉토리
  • --vocab_file: build_vocab.py을 통해 만든 어휘 파일
  • --output_dir: tfrecord 생성 디렉토리
  • --max_seq_length: 최대 토큰 수 (기본값 : 128개)
  • --num_processes: 프로세스 병렬화 개수 (기본값 : 1)
  • --blanks-separate-docs: 빈 줄이 문서 경계를 나타내는 지 여부 (기본값 : False)
  • --do-lower-case/--no-lower-case: 입력 텍스트의 소문자 여부 (기본값 : False)
  • --tokenizer_type: wordpiece / mecab_wordpiece와 같은 토크나이저 (기본값 : wordpiece)

실행 예시

python3 build_pretraining_dataset.py \
    --corpus_dir data/train_data/raw/split_normalize \
    --vocab_file data/vocab/vocab.txt \
    --tokenizer_type wordpiece \
    --output_dir data/train_data/tfrecord/pretrain_tfrecords_len_128_wordpiece_train \
    --max_seq_length 128 \
    --num_processes 8

4. 사전 학습 수행

run_pretraining.py를 사용하여 사전 학습을 수행합니다.

  • --data_dir: 사전 훈련 데이터, 모델 가중치 등이 저장되는 디렉토리
  • --model_name: 훈련중인 모델의 이름. 모델 가중치는 기본적으로<data-dir> / models / <model-name>에 저장
  • --hparams (optional): 모델 매개 변수, 데이터 경로 등을 포함하는 JSON 파일 경로 (지원되는 매개 변수는configure_pretraining.py 참조)
  • --use_tpu (optional): 모델을 훈련 할 때 tpu를 사용하는 옵션
  • --mixed_precision (optional): 모델 훈련시 혼합 정밀도를 사용할지 여부에 대한 옵션

실행 예시

python3 run_pretraining.py \
    --data_dir data/train_data/tfrecord/pretrain_tfrecords_len_128_wordpiece_train \
    --model_name data/ckpt/pretrain_ckpt_len_128_small_wordpiece_train \
    --hparams data/config/small_config_kor_wordpiece_train.json \
    --mixed_precision

5. tf모델 -> pytorch모델 변환

pytorch_convert.py를 사용하여 tf 모델을 pytorch 모델로 변환합니다.

  • --tf_ckpt_path: 체크포인트 파일이 저장되는 디렉토리
  • --pt_discriminator_path: pytorch 판별 모델을 작성할 위치
  • --pt_generator_path (optional): pytorch 생성 모델을 작성할 위치 실행 예시
python3 pytorch_convert.py \
    --tf_ckpt_path model/ckpt/pretrain_ckpt_len_128_small \
    --pt_discriminator_path model/pytorch/dialog-koelectra-small-discriminator \
    --pt_generator_path model/pytorch/dialog-koelectra-small-generator \

Fine-tuning

run_finetuning.py를 사용하여 다운스트림 NLP 태스크에서 Dialog-KoELECTRA 모델을 미세 조정하고 평가합니다.

  • --config_file: 모델 하이퍼 파라미터, 데이터 경로 등을 포함하는 YAML 파일 (필수)
  • --do_nni: 모델을 미세 조정할 때 nni를 사용할지 여부 (옵션)
  • --do_reinit: 모델을 미세 조정할 때 re-init을 적용할지 여부 (옵션)

실행 예시

python3 run_finetune.py --config_file conf/hate-speech/electra-small.yaml

References

  • ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators.
  • KoELECTRA: Pretrained ELECTRA Model for Korean

Contact Info

Dialog-KoELECTRA 사용에 대한 도움이나 문제가 있는 경우 GitHub issue에 올려주세요.


Citation

이 라이브러리를 프로젝트 및 연구에 적용하는 경우, 아래와 같이 인용 부탁드립니다.

@misc{DialogKoELECTRA,
  author       = {Wonchul Kim and Junseok Kim and Okkyun Jeong},
  title        = {Dialog-KoELECTRA: Korean conversational language model based on ELECTRA model},
  howpublished = {\url{https://github.com/skplanet/Dialog-KoELECTRA}},
  year         = {2021},
}

License

Dialog-KoELECTRA 프로젝트는 Apache License 2.0 라이센스를 기반으로 합니다.

 Copyright 2020 ~ present SK Planet Co. RB Dialog solution

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.      
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].