2021년도 1학기 고려대학교 산업경영공학과 비정형데이터분석 수업 팀프로젝트 repository입니다.
본 README에서는 KoBART Fine-tuning을 위한 과정을 안내합니다.
먼저 아래의 명령어를 사용하여 KoBART를 다운로드합니다.
pip install git+https://github.com/SKT-AI/KoBART#egg=kobart
그 후 requirements.txt의 패키지를 설치합니다. Dockerfile로도 설치할 수 있습니다.
# KoBART 문서요약 관련 코드
src/summarization/
└─ data/
└─ cached/ # tokenized indice without special tokens
├─ cached_train.jsonl
├─ cached_dev.jsonl
└─ cached_test.jsonl
├─ train.jsonl # raw data with many meta-data
├─ dev.jsonl
├─ test.jsonl
├─ processed_train.jsonl # only src, tgt text
├─ processed_dev.jsonl
└─ processed_test.jsonl
└─ metric/
├─ get_rouge.py
└─ rouge_metric.py
├─ 1. data_sample.ipynb
├─ 2. tokenizer_sample.ipynb
├─ 3. dataset_sample.ipynb
├─ 4. inference_sample.ipynb
├─ config.py
├─ dataset.py
├─ distilbart.py
├─ inference.py
├─ main.py
├─ preprocess.py
├─ trainer.py
└─ utils.py
- Data: 한국어 생성요약 뉴스 데이터 일부 (Bflysoft - AI Hub에 공개)
- Train 260,697개 / Valid 10,000개 / Test 10,000개
- Model: KoBART, DistilKoBART
- DistilKoBART는 huggingface의 Pre-trained Summarization Distillation(2020) 논문에서 제안된 방법론으로, Fine-tuning 시 Pre-trained 레이어의 일부만을 사용하는 모델입니다.
- Data: 네이버 오디오북, 밀리의서재
- Train 3,752개
- Model: Tacotron2, Waveglow
train.jsonl
/ dev.jsonl
/ test.jsonl
은 미리 다운로드받아 위 구조에 맞게 배치해야 합니다.
src/summarization/
경로에서 아래 명령어를 실행하면 됩니다.
# train
python preprocess.py --mode train
# dev
python preprocess.py --mode dev
# test
python preprocess.py --mode test
Root 경로에서 아래 명령어를 실행하면 됩니다.
sh run_kobart.sh
# 실행 위치에 따른 경로 수정이 필요할 수 있습니다.
from inference import get_summarized_text
ckpt: str = """ 학습된 체크포인트 경로를 입력합니다. """
text: str = """ 요약을 수행할 텍스트를 입력합니다. """
n_enc: int = """ DistilKoBART를 사용하는 경우에만 인코더 레이어 개수를 명시해 주면 됩니다. """
n_dec: int = """ DistilKoBART를 사용하는 경우에만 디코더 레이어 개수를 명시해 주면 됩니다. """
summary = get_summarized_text(ckpt, text, n_enc, n_dec)
print(summary)
여기에서 몇 개의 예시 데이터를 사용한 결과를 확인하실 수 있습니다.
10000개의 test data로 성능을 측정하였고, Dacon 한국어 문서 생성요약 AI 경진대회의 metric을 사용하였습니다. Mecab 라이브러리 설치가 필요하신 분은 이 블로그를 참고해주세요.
모델 뒤에 표기된 숫자는 인코더-디코더에 해당하는 레이어의 수입니다.
- Number of Parameters: 123,859,968
Rouge-1 | Rouge-2 | Rouge-L | |
---|---|---|---|
Precision | 0.467 | 0.314 | 0.373 |
Recall | 0.601 | 0.399 | 0.476 |
F1-Score | 0.507 | 0.339 | 0.403 |
- Number of Parameters: 102,596,352
Rouge-1 | Rouge-2 | Rouge-L | |
---|---|---|---|
Precision | 0.462 | 0.307 | 0.366 |
Recall | 0.587 | 0.385 | 0.461 |
F1-Score | 0.496 | 0.327 | 0.392 |
- Number of Parameters: 95,504,640
Rouge-1 | Rouge-2 | Rouge-L | |
---|---|---|---|
Precision | 0.481 | 0.324 | 0.386 |
Recall | 0.582 | 0.386 | 0.464 |
F1-Score | 0.510 | 0.340 | 0.408 |
- Number of Parameters: 74,241,024
Rouge-1 | Rouge-2 | Rouge-L | |
---|---|---|---|
Precision | 0.472 | 0.314 | 0.378 |
Recall | 0.575 | 0.377 | 0.457 |
F1-Score | 0.501 | 0.331 | 0.399 |
문서요약 모델, 음역모듈, 그리고 음성합성 모델의 정성적인 결과는 데모 페이지에서 확인하실 수 있습니다.
Hyeongwon Kang, Subin Kim, Jina Kim, Takyoung Kim
음성합성 관련 작업에서는 Jounghee Kim의 도움을 받았습니다.