주요 한국어 PLM의 fine-tuning을 통해 한국어 개체명 인식 다운스트림 태스크를 진행했습니다. HuggingFace 라이브러리를 활용해 국립국어원 개체명 분석 말뭉치 데이터셋에서 개체명으로 정의된 15개 개체명 유형 (인명, 지명, 문명, 인공물 등)에 대해 개체명 인식기를 구현했습니다.
pip install -r requirements.txt
pip install 'git+https://github.com/SKTBrain/KoBERT.git#egg=kobert_tokenizer&subdirectory=kobert_hf'
| Model | PretrainingCorpus | Tokenization | Vocabulary | Hidden | Layers | Heads | Batch |
|---|---|---|---|---|---|---|---|
| klue/bert-base | 6.5B words incl. Modu, Namuwiki | Mecab +BPE | 32,000 | 768 | 12 | 12 | 256 |
| klue/roberta-base | 6.5B words incl. Modu, Namuwiki | Mecab +BPE | 32,000 | 768 | 12 | 12 | 2048 |
| skt/kobert-base-v1 | Korean Wiki 54M words | SentencePiece | 8,002 | 3072 | 12 | 12 | - |
| monologg/koelectra-base-v3-discriminator | crawled news data and Modu | Wordpiece | 35,000 | 768 | 12 | 12 | 256 |
| monologg/kobigbird-bert-base | crawled news data and Modu | Sentencepiece | 32,500 | 768 | 12 | 12 | 32 |
python ./preprocess/json_to_tsv.py --load_path data/json/19_150tags_NamedEntity/NXNE2102008030.json --save_path data/raw
python ./preprocess/json_to_tsv.py --load_path data/json/21_150tags_NamedEntity --save_path data/raw
python ./preprocess/preprocess.py --load_path data/raw --save_path data/dataset --test_size 0.15 --test_o_size 0.2 --save_all --return_tsv
4 files found : ['SXNE21.pickle', 'SXNE2102007240.pickle', 'NXNE2102008030.pickle', 'NXNE2102203310.pickle']
file 0 : 351568
file 1 : 223962
file 2 : 150082
file 3 : 78170
|data before preprocessing| 803782
|data after preprocessing| 780546 / before dropping O sentences
|train| 663464 / |test| 117082 / before dropping O sentences
|train| 303028 / |test| 66845 / after dropping and sampling O sentences
python ./preprocess/encoding.py --load_fn data/dataset/train.pickle --save_path data/encoded
Tokenizer loaded : klue/roberta-base
Sentences encoded : |input_ids| 66845, |attention_mask| 66845
Token indices sequence length is longer than the specified maximum sequence length for this model (679 > 512). Running this sequence through the model will result in indexing errors
Sequence labeling completed : |labels| 66845
Encoded data saved as data/encoded/test.klue_roberta-base.encoded.pickle
인코딩이 완료된 데이터셋을 사용하여 학습을 진행합니다.
python hf_trainer.py --model_fn models --data_fn data/encoded/train.klue_roberta-base.encoded.pickle --pretrained_model_name klue/roberta-base --use_kfold --n_splits 5
트레이닝과 동일하게 전처리한 테스트 데이터셋(66845개)에 대해 모델별, 폴더별 5개 체크포인트 결과의 평균을 최종값으로 하는 앙상블 기법을 적용합니다. --model_folder는 각 모델의 5개 체크포인트 결과가 들어있는 폴더이고, --test_file은 테스트 파일 이름입니다.
python inference_ensemble.py --model_folder ./model -- test_file ./test_klue_roberta-base.encoded.pickle
| PLMs | F1 Score | Accuracy |
|---|---|---|
| klue/bert-base | 0.865 | 0.974 |
| klue/roberta-base | 0.866 | 0.974 |
| skt/kobert-base-v1 | 0.846 | 0.965 |
| monologg/koelectra-base-v3-discriminator | 0.858 | 0.972 |
| monologg/kobigbird-bert-base | 0.827 | 0.965 |
주요 한국어 PLM의 fine-tuning을 통해 한국어 개체명 인식 다운스트림 태스크를 진행했습니다. HuggingFace 라이브러리를 활용해 국립국어원 개체명 분석 말뭉치 데이터셋에서 개체명으로 정의된 15개 개체명 유형 (인명, 지명, 문명, 인공물 등)에 대해 개체명 인식기를 구현했습니다.
pip install -r requirements.txt
pip install 'git+https://github.com/SKTBrain/KoBERT.git#egg=kobert_tokenizer&subdirectory=kobert_hf'
| Model | PretrainingCorpus | Tokenization | Vocabulary | Hidden | Layers | Heads | Batch |
|---|---|---|---|---|---|---|---|
| klue/bert-base | 6.5B words incl. Modu, Namuwiki | Mecab +BPE | 32,000 | 768 | 12 | 12 | 256 |
| klue/roberta-base | 6.5B words incl. Modu, Namuwiki | Mecab +BPE | 32,000 | 768 | 12 | 12 | 2048 |
| skt/kobert-base-v1 | Korean Wiki 54M words | SentencePiece | 8,002 | 3072 | 12 | 12 | - |
| monologg/koelectra-base-v3-discriminator | crawled news data and Modu | Wordpiece | 35,000 | 768 | 12 | 12 | 256 |
| monologg/kobigbird-bert-base | crawled news data and Modu | Sentencepiece | 32,500 | 768 | 12 | 12 | 32 |
python ./preprocess/json_to_tsv.py --load_path data/json/19_150tags_NamedEntity/NXNE2102008030.json --save_path data/raw
python ./preprocess/json_to_tsv.py --load_path data/json/21_150tags_NamedEntity --save_path data/raw
python ./preprocess/preprocess.py --load_path data/raw --save_path data/dataset --test_size 0.15 --test_o_size 0.2 --save_all --return_tsv
4 files found : ['SXNE21.pickle', 'SXNE2102007240.pickle', 'NXNE2102008030.pickle', 'NXNE2102203310.pickle']
file 0 : 351568
file 1 : 223962
file 2 : 150082
file 3 : 78170
|data before preprocessing| 803782
|data after preprocessing| 780546 / before dropping O sentences
|train| 663464 / |test| 117082 / before dropping O sentences
|train| 303028 / |test| 66845 / after dropping and sampling O sentences
python ./preprocess/encoding.py --load_fn data/dataset/train.pickle --save_path data/encoded
Tokenizer loaded : klue/roberta-base
Sentences encoded : |input_ids| 66845, |attention_mask| 66845
Token indices sequence length is longer than the specified maximum sequence length for this model (679 > 512). Running this sequence through the model will result in indexing errors
Sequence labeling completed : |labels| 66845
Encoded data saved as data/encoded/test.klue_roberta-base.encoded.pickle
인코딩이 완료된 데이터셋을 사용하여 학습을 진행합니다.
python hf_trainer.py --model_fn models --data_fn data/encoded/train.klue_roberta-base.encoded.pickle --pretrained_model_name klue/roberta-base --use_kfold --n_splits 5
트레이닝과 동일하게 전처리한 테스트 데이터셋(66845개)에 대해 모델별, 폴더별 5개 체크포인트 결과의 평균을 최종값으로 하는 앙상블 기법을 적용합니다. --model_folder는 각 모델의 5개 체크포인트 결과가 들어있는 폴더이고, --test_file은 테스트 파일 이름입니다.
python inference_ensemble.py --model_folder ./model -- test_file ./test_klue_roberta-base.encoded.pickle
| PLMs | F1 Score | Accuracy |
|---|---|---|
| klue/bert-base | 0.865 | 0.974 |
| klue/roberta-base | 0.866 | 0.974 |
| skt/kobert-base-v1 | 0.846 | 0.965 |
| monologg/koelectra-base-v3-discriminator | 0.858 | 0.972 |
| monologg/kobigbird-bert-base | 0.827 | 0.965 |