Skip to content

monologg/korean-hate-speech-koelectra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Korean Hate Speech Classification

KoELECTRA์™€ Korean Hate Speech Dataset์„ ์ด์šฉํ•œ Bias & Hate Classification

Dataset

# of data
train 7,896
validate 471
test 974
  • Bias (gender, other, none), Hate (hate, offensive, none)

Requirements

  • torch==1.5.0
  • transformers==2.11.0
  • soynlp==0.0.493

Details

Model

[CLS] token์—์„œ bias์™€ hate๋ฅผ ๋™์‹œ์— ์˜ˆ์ธกํ•˜๋Š” Joint Architecture

  • loss = bias_coef * bias_loss + hate_coef * hate_loss (bias_loss_coef, hate_loss_coef ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ)
  • model.py์˜ ElectraForBiasClassification ์ฐธ๊ณ 

Input

  • [CLS] comment [SEP] title [SEP]์œผ๋กœ comment์™€ title์„ ์ด์–ด ๋ถ™์—ฌ Input์œผ๋กœ ๋„ฃ์Œ
  • ์ „์ฒ˜๋ฆฌ์˜ ๊ฒฝ์šฐ [] ๋“ฑ์˜ brace๋กœ ๋ฌถ์ธ ๋‹จ์–ด ์ œ๊ฑฐ, ๋”ฐ์˜ดํ‘œ ํ†ต์ผ, ๋ถˆํ•„์š”ํ•œ ๋”ฐ์˜ดํ‘œ ์ œ๊ฑฐ, normalization ๋“ฑ ๊ฐ„๋‹จํ•œ ๊ฒƒ๋งŒ ์ ์šฉ

Hyperparameters

Parameters
Batch Size 16
Learning Rate 5e-5
Epochs 10
Warmup Proportion 0.1
Max Seq Length 100
Bias Loss Coefficient 0.5
Hate Loss Coefficient 1.0

Metric

๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ(Bias, Hate)์˜ Weighted F1 ์‚ฐ์ถœ ํ›„ ์‚ฐ์ˆ  ํ‰๊ท 

  • mean_weighted_f1 = (bias_weighted_f1 + hate_weighted_f1) / 2
  • Dev dataset ๊ธฐ์ค€์œผ๋กœ mean_weighted_f1์˜ ๊ฐ’์ด ๊ฐ€์žฅ ๋†’์€ ๋ชจ๋ธ์„ ์ตœ์ข…์ ์œผ๋กœ ์ €์žฅ

Train

$ python3 main.py --model_type koelectra-base-v2 \
                  --model_name_or_path monologg/koelectra-base-v2-discriminator \
                  --model_dir {$MODEL_DIR} \
                  --prediction_file prediction.csv \
                  --do_train

Prediction

Test file์— ๋Œ€ํ•œ ์˜ˆ์ธก๊ฐ’์„ csv ํ˜•ํƒœ๋กœ ์ €์žฅ

$ python3 main.py --model_type koelectra-base-v2 \
                  --model_name_or_path {$MODEL_DIR} \
                  --pred_dir preds \
                  --prediction_file prediction.csv \
                  --do_pred
bias,hate
none,offensive
gender,hate
none,none
others,none
...

Result

(๊ฐ€๋ณ๊ฒŒ ์ œ์ž‘ํ•œ Baseline์ด์—ฌ์„œ ์ ์ˆ˜ ๊ฐœ์„ ์˜ ์—ฌ์ง€๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค)

(Weighted F1) Bias F1 Hate F1 Mean F1
Dev Dataset 82.28 67.25 74.77

Reference

Releases

No releases published

Packages

No packages published

Languages