|
Download README.md from thlee00/ct-nlp: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/thlee00/ct-nlp/resolve/main/README.md
- Command line
-
hf download hf://thlee00/ct-nlp/README.md
-
curl -L -o README.md https://huggingface.co/thlee00/ct-nlp/resolve/main/README.md
3.17 kB
| language: | |
| - ko | |
| base_model: klue/bert-base | |
| tags: | |
| - bert | |
| - text-classification | |
| - korean | |
| - safety | |
| - harm-detection | |
| - mental-health | |
| license: cc-by-4.0 | |
| pipeline_tag: text-classification | |
| # CT-NLP Harm Direction Classifier | |
| **Safe Sustained Disagreement** ํ๋ก์ ํธ์ 1๋จ๊ณ ํตํฉ ์ธ์ดํ๊ฐ๋ ํต์ฌ ๋ถํ. | |
| KLUE-BERT-base๋ฅผ fine-tuneํด ํ๋ฅด์๋ ๋ฐํ๊ฐ **์น๋ฃ์ ๊ณผ์ฅ์ธ์ง ํด๋ก์ด ์ฆํญ์ธ์ง** ๋ฐฉํฅ์ ํ์งํฉ๋๋ค. | |
| ## ๋ชจ๋ธ ๊ฐ์ | |
| ๋ฐํ์ **๊ฐ๋๊ฐ ์๋ ๋ฐฉํฅ**์ผ๋ก ๋ถ๋ฅํฉ๋๋ค. ๊ฐํ ๋ถ์ ์ ์ ์์ฒด๋ ์น๋ฃ์ ์ผ ์ ์์ผ๋ฉฐ, | |
| ๋ฌด๋ง๊ฐยท์๊ธฐ๋ฌด๊ฐ์นยท์ํด ๋ฐฉํฅ์ผ๋ก์ ์ด๋๋ง ํด๋กญ์ต๋๋ค. | |
| | ๋ผ๋ฒจ | ์ค๋ช | | |
| |---|---| | |
| | `therapeutic_exaggeration` (0) | ์น๋ฃ์ ๊ณผ์ฅ โ ๊ฐํ์ง๋ง ํ์ ยท๊ฐ์ญ์ , ๊ด์ ๋ณต๊ท ๊ฐ๋ฅ | | |
| | `borderline` (1) | ๊ฒฝ๊ณ โ ๋ฐฉํฅ ๋ชจํธ, ๋ณด์์ ์ฒ๋ฆฌ ํ์ | | |
| | `harmful_amplification` (2) | ํด๋ก์ด ์ฆํญ โ ๋ฌด๋ง๊ฐยท๋ฌด๊ฐ์นยท์ํด ๋ฐฉํฅ์ผ๋ก ์ด๋ | | |
| ### 5์ถ ํ๋ณ ๊ธฐ์ค | |
| 1. **๊ท์ธ ๋ฐฉํฅ** โ ์์ยท์ ๋ฐยท๋ด๋ถ ๊ท์ธ โโ ์ํฉ์ ยท์ผ์์ | |
| 2. **ํฌ๋งยทํ์์ฑ** โ "๋ฐฉ๋ฒ ์๋ค/๋๋ฌ๋ค" โโ ๊ฐ๋ฅ์ฑยทํต์ ๊ฐ ๋ณด์กด | |
| 3. **์๊ธฐ๊ฐ์น** โ ๋ฌด๊ฐ์นยท์๊ธฐ๊ฒฝ๋ฉธ โโ ํ์ ๋ ์๊ธฐ๋นํ | |
| 4. **์ํดยท์๋จ** โ ์ํด ์ฌ๊ณ ยท๋ฐฉ๋ฒ ์ธ๊ธ (๊ท์น ๊ธฐ๋ฐ ํ๋๊ฒ์ดํธ) | |
| 5. **๊ฐ์ญ์ฑยทํด์ arc** โ ์ด์ฒดํยท๋ฌดํด์ โโ ํ์ ยท๊ฐ์ญยท๊ด์ ๋ณต๊ท | |
| ## ํ์ต ์ ๋ณด | |
| | ํญ๋ชฉ | ๊ฐ | | |
| |---|---| | |
| | Base model | klue/bert-base | | |
| | ํ์ต ๋ฐ์ดํฐ | ํ๊ตญ์ด ๊ทน๋จ ํ๋ฅด์๋ ํ ๋ก ๋ฐํ 9,756๊ฑด (group-split) | | |
| | Epochs | 4 | | |
| | Weighted CE | ํด๋์ค ๋ถ๊ท ํ ๋ณด์ | | |
| | Accuracy | 0.786 | | |
| | Macro F1 | 0.733 | | |
| | **Harmful F1** | **0.842** (recall 0.81) | | |
| | Therapeutic F1 | 0.870 | | |
| | Borderline F1 | 0.488 (๋ผ๋ฒจ ๋ ธ์ด์ฆยท๊ฒฝ๊ณ ํด๋์ค) | | |
| ## ์ฌ์ฉ๋ฒ | |
| ```python | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| tok = AutoTokenizer.from_pretrained("thlee00/ct-nlp") | |
| model = AutoModelForSequenceClassification.from_pretrained("thlee00/ct-nlp") | |
| model.eval() | |
| text = "์ด์ฐจํผ ๋๋ ๋ญ ํด๋ ์ ๋ผ. ์ด๋ฒ์๋ ๋งํ๊ณ ์์ผ๋ก๋ ๊ทธ๋ด ๊ฑฐ์ผ." | |
| inputs = tok(text, return_tensors="pt", truncation=True, max_length=512) | |
| with torch.no_grad(): | |
| logits = model(**inputs).logits | |
| label = model.config.id2label[logits.argmax(-1).item()] | |
| print(label) # harmful_amplification | |
| ``` | |
| ### ํตํฉ ์ธ์ดํ๊ฐ๋๋ก ์ฌ์ฉ | |
| ```python | |
| from ctnlp.safeguard.safeguard import Safeguard | |
| sg = Safeguard() # models/harm_direction ์๋ ๋ก๋ | |
| result = sg.gate_input("๊ฑฑ์ ๋ฌธ์ฅ") | |
| # {"action": "allow" | "route" | "block", "label": ..., "score": ...} | |
| ``` | |
| ## ์ฃผ์์ฌํญ | |
| - ์ด ๋ชจ๋ธ์ **ํ ๋ก ๋ฐํ**๋ก ํ์ต๋์ด ์ฌ์ฉ์ ์ ๋ ฅ๊ณผ ๋ ์ง์คํฐ ์ฐจ์ด๊ฐ ์์ต๋๋ค (๋๋ฉ์ธ ์ํํธ). | |
| - ์ ๋ ฅ ๊ฒ์ดํธ ์ ์ฉ ์ ์๊ณ๊ฐ **0.4** ๊ถ์ฅ (๋ฌด๋ง๊ฐ ์ฌํ์จ 100% @ ์คํ 2.3%). | |
| - ์์ ์ง๋จ ๋ชฉ์ ์ผ๋ก ์ฌ์ฉํ์ง ๋ง์ญ์์ค. | |
| ## ํ๋ก์ ํธ | |
| - ์ฝ๋: [CT-NLP-project](https://github.com/thlee00/CT-NLP-project) | |
| - SFT ๋ชจ๋ธ: [thlee00/ct-nlp-sft](https://huggingface.co/thlee00/ct-nlp-sft) | |