Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
|
| 3 |
+
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
tags:
|
| 6 |
+
- llama-factory
|
| 7 |
+
- lora
|
| 8 |
+
- transformers
|
| 9 |
+
model-index:
|
| 10 |
+
- name: llama31-8b-hatexplain-lora (checkpoint-3500)
|
| 11 |
+
results:
|
| 12 |
+
- task:
|
| 13 |
+
type: text-classification
|
| 14 |
+
name: Hate speech classification
|
| 15 |
+
dataset:
|
| 16 |
+
name: HateXplain
|
| 17 |
+
type: hatexplain
|
| 18 |
+
split: validation
|
| 19 |
+
metrics:
|
| 20 |
+
- type: accuracy
|
| 21 |
+
value: 0.7196
|
| 22 |
+
- type: f1
|
| 23 |
+
name: macro_f1
|
| 24 |
+
value: 0.6998
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
# Llama 3.1 8B Instruct — HateXplain (LoRA adapter, ckpt-3500)
|
| 28 |
+
|
| 29 |
+
- Base model: `meta-llama/Meta-Llama-3.1-8B-Instruct`
|
| 30 |
+
- Adapter: LoRA (rank=8, alpha=16, dropout=0.05, target=all)
|
| 31 |
+
- Trainable params: ~0.26% (≈20.97M / 8.05B)
|
| 32 |
+
- Task: hate speech detection (3 classes: `hatespeech`, `offensive`, `normal`)
|
| 33 |
+
- Dataset: HateXplain (train/validation)
|
| 34 |
+
- Epochs: 3
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 40 |
+
from peft import PeftModel
|
| 41 |
+
import torch
|
| 42 |
+
|
| 43 |
+
base = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 44 |
+
adapter = "<your-username>/<your-adapter-repo>" # or local path to this checkpoint
|
| 45 |
+
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained(base)
|
| 47 |
+
model = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.bfloat16, device_map="auto")
|
| 48 |
+
model = PeftModel.from_pretrained(model, adapter)
|
| 49 |
+
|
| 50 |
+
# Build a llama3-style prompt and generate the label ("hatespeech"/"offensive"/"normal")
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Training Configuration
|
| 54 |
+
|
| 55 |
+
- Finetuning type: LoRA
|
| 56 |
+
- LoRA: rank=8, alpha=16, dropout=0.05, target=all
|
| 57 |
+
- Precision: bf16 (with gradient checkpointing)
|
| 58 |
+
- Per-device batch size: 1
|
| 59 |
+
- Gradient accumulation: 8 (effective batch = 8)
|
| 60 |
+
- Learning rate: 5e-5, scheduler: cosine, warmup ratio: 0.05
|
| 61 |
+
- Epochs: 3
|
| 62 |
+
- Template: `llama3`, cutoff length: 2048
|
| 63 |
+
- Output dir: `saves/llama31-8b/hatexplain/lora`
|
| 64 |
+
|
| 65 |
+
## Data
|
| 66 |
+
|
| 67 |
+
- Source: HateXplain (`datasets`), majority-vote label from annotators
|
| 68 |
+
- Splits: train (15,383), validation (1,922)
|
| 69 |
+
- Format: Alpaca-style with `instruction` + `input` → label as assistant response
|
| 70 |
+
|
| 71 |
+
## Evaluation (validation)
|
| 72 |
+
|
| 73 |
+
Overall:
|
| 74 |
+
- Accuracy: 0.7196
|
| 75 |
+
- Macro-F1: 0.6998
|
| 76 |
+
|
| 77 |
+
Per-class report:
|
| 78 |
+
|
| 79 |
+
```
|
| 80 |
+
precision recall f1-score support
|
| 81 |
+
|
| 82 |
+
hatespeech 0.7252 0.8634 0.7883 593
|
| 83 |
+
offensive 0.6152 0.4726 0.5346 548
|
| 84 |
+
normal 0.7698 0.7836 0.7766 781
|
| 85 |
+
|
| 86 |
+
accuracy 0.7196 1922
|
| 87 |
+
macro avg 0.7034 0.7065 0.6998 1922
|
| 88 |
+
weighted avg 0.7120 0.7196 0.7112 1922
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Notes:
|
| 92 |
+
- Decoding is greedy with short label strings; loss-based and log-likelihood scoring produce similar ordering.
|
| 93 |
+
- Ensure tokenizer uses `pad_token = eos_token` for batched evaluation.
|
| 94 |
+
|
| 95 |
+
## Limitations and Intended Use
|
| 96 |
+
|
| 97 |
+
- For moderated content classification; not intended for generating harmful content.
|
| 98 |
+
- Biases present in the dataset may be reflected in predictions.
|
| 99 |
+
|
| 100 |
+
## Acknowledgements
|
| 101 |
+
|
| 102 |
+
- Built with [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) and PEFT.
|
| 103 |
+
|