Views
No views yet
gabrielct1/llama-aas-related-classificationmeta-llama/Meta-Llama-3.1-8B)meta-llama/Meta-Llama-3.1-8B), using 4-bit NF4 quantization, multilabel stratified cross-validation, and per-label threshold tuning on validation F1.| ID | Label | Description |
|---|---|---|
| 0 | Autorrelato (Self-report) | Includes comments that explicitly declare anabolic steroid use by the author themselves. This covers direct mentions of substances such as testosterone, oxandrolone, steroids, cycles, or brand names, as well as personal experience reports. It may also include references to dosage, duration of use, injection sites, or combinations with other substances, as long as the comment indicates self-use. |
| 1 | Sintomas / Efeitos Colaterais (Symptoms / Side Effects) | Includes comments that mention symptoms, adverse reactions, or side effects related to anabolic steroid use, regardless of who experienced them. This includes physical, emotional, or physiological changes such as acne, gynecomastia, hair loss, aggressiveness, infertility, among others. Comments that speculate about these effects should also be labeled in this category. |
| Item | Value |
|---|---|
| Method | QLoRA (PEFT) |
| Base model | Meta Llama 3.1 8B (meta-llama/Meta-Llama-3.1-8B) |
| Quantization | 4-bit NF4 (BitsAndBytes) |
| Framework setup | QLoRA setup aligned with the Kelora/PEFT pipeline |
| LoRA rank (r) | 16 |
| LoRA alpha | 32 |
| LoRA dropout | 0.1 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj |
| Max sequence length | 128 |
| Learning rate | 2e-4 |
| Optimizer | AdamW |
| Weight decay | 0.01 |
| LR scheduler | Cosine schedule |
| Warmup ratio | 0.05 |
| Batch size | 12 |
| Max epochs | 50 (early stopping enabled) |
| Validation protocol | 5-fold multilabel stratified CV (cyclic: val=r, test=r+1) |
| Loss function | BCEWithLogitsLoss with class-specific pos_weight = (N - pos) / pos |
| Early stopping criterion | Validation loss (patience = 3, min delta = 1e-4) |
| Best checkpoint criterion | Macro F1 |
| Post-processing | Per-label threshold optimization by validation F1 using precision-recall curves |
| Threshold search range | 0.05 to 0.95 |
pip install torch transformers peft bitsandbytes accelerate huggingface_hubmeta-llama/Meta-Llama-3.1-8B).meta-llama/Meta-Llama-3.1-8B) on Hugging Face.huggingface-cli login) or set an environment token:export HF_TOKEN="your_huggingface_token"1import os
2import json
3import torch
4from huggingface_hub import hf_hub_download
5from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
6from peft import PeftModel
7
8BASE_MODEL = "meta-llama/Meta-Llama-3.1-8B"
9ADAPTER_REPO = "gabrielct1/llama-aas-related-classification"
10HF_TOKEN = os.getenv("HF_TOKEN")
11
12thr_path = hf_hub_download(repo_id=ADAPTER_REPO, filename="thresholds.json", token=HF_TOKEN)
13with open(thr_path, "r", encoding="utf-8") as f:
14 thresholds = torch.tensor(json.load(f)["thresholds"])
15
16label_map = {
17 0: "Autorrelato",
18 1: "Sintomas / Efeitos Colaterais",
19}
20
21bnb_cfg = BitsAndBytesConfig(
22 load_in_4bit=True,
23 bnb_4bit_quant_type="nf4",
24 bnb_4bit_use_double_quant=True,
25 bnb_4bit_compute_dtype=torch.float16,
26)
27
28tokenizer = AutoTokenizer.from_pretrained(ADAPTER_REPO, token=HF_TOKEN)
29if tokenizer.pad_token is None:
30 tokenizer.pad_token = tokenizer.eos_token
31
32base_model = AutoModelForSequenceClassification.from_pretrained(
33 BASE_MODEL,
34 quantization_config=bnb_cfg,
35 num_labels=2,
36 device_map="auto",
37 token=HF_TOKEN,
38)
39base_model.config.pad_token_id = tokenizer.pad_token_id
40
41model = PeftModel.from_pretrained(base_model, ADAPTER_REPO, token=HF_TOKEN)
42model.eval()
43
44text = "Usei por algumas semanas e comecei a ter queda de cabelo e acne."
45inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128).to(model.device)
46
47with torch.no_grad():
48 logits = model(**inputs).logits
49 probs = torch.sigmoid(logits).squeeze(0).cpu()
50 pred = (probs >= thresholds).int().tolist()
51
52for i, name in label_map.items():
53 print(f"{name}: prob={probs[i].item():.4f} pred={pred[i]}")thresholds.json in the Hub repository.BitsAndBytesConfig(...) and load the base model in standard precision.