Views
No views yet
One‑line summary: Decoder‑only LLMs (e.g., Llama‑3.2‑1B) fine‑tuned for multi‑label text classification using LoRA adapters, with optional 4‑bit QLoRA quantization for memory‑efficient training and inference. A clean CLI and YAML config make it easy to reproduce results and swap backbones.
Note: This card describes a training pipeline + example checkpoints. If you push a specific checkpoint to the Hub, please fill in exact dataset splits, metrics, and license at upload time.
meta-llama/Llama-3.2-1B) using LoRA adapters, and optionally enables 4‑bit quantization (QLoRA‑style) for reduced memory footprint during training and inference. The repository exposes a single CLI for train/eval/predict and a YAML configuration to control data paths, model choice, and hyperparameters.amirhossein-yousefi; Hugging Face: Amirhossein75)meta-llama/Llama-3.2-1B) is under the Llama 3.2 Community License. The LoRA adapter you publish should declare its own license and acknowledge base‑model terms.meta-llama/Llama-3.2-1B (foundation)python -m llm_cls.cli predict --config ...) producing JSONL predictions.model.model_name in the config to try other decoders or encoders (set use_4bit=false for encoders).bitsandbytes support.BASE_MODEL and ADAPTER_REPO with your IDs.1from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "meta-llama/Llama-3.2-1B"
6ADAPTER_REPO = "Amirhossein75/LLM-Decoder-Tuning-Text-Classification" # or your own adapter
7
8tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, use_fast=True)
9base = AutoModelForCausalLM.from_pretrained(
10 BASE_MODEL,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13)
14model = PeftModel.from_pretrained(base, ADAPTER_REPO)
15model.eval()
16
17# Simple prompt format for multi-label classification (adjust to your training format).
18labels = ["books","movies_tv","music","pop","literature_fiction","movies","education_reference","rock","used_rental_textbooks","new"]
19text = "A thrilling space opera with deep character arcs and rich world-building."
20
21prompt = (
22 "You are a classifier. Given the text, return a JSON list of applicable labels from this set: "
23 + ", ".join(labels) + ".\n"
24 + f"Text: {text}\nLabels: "
25)
26
27pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
28out = pipe(prompt, max_new_tokens=64, do_sample=False)
29print(out[0]["generated_text"])1# Train
2python -m llm_cls.cli train --config configs/default.yaml
3
4# Predict
5python -m llm_cls.cli predict --config configs/default.yaml --input_csv data/test.csv --output_jsonl preds.jsonlconfigs/default.yaml.split_amazon_13k_data.py in the repo).meta-llama/Llama-3.2-1Bmulti_label_classificationuse_4bit: true (QLoRA‑style); torch_dtype: bfloat16 for computationr=2, alpha=2, dropout=0.05["q_proj","k_proj","v_proj","o_proj","gate_proj","down_proj","up_proj"]4 (with gradient_accumulation_steps=8)1024optim_8bit_when_4bit: true)20 with early stopping (patience=2)f1_microoutputs/<model_name>/<dataset_name>/run_<i>/f1_micro, f1_macro, eval loss, throughput (steps/s, samples/s).Interpretation: going from 4 → 5 epochs gives the best micro‑F1; 6 epochs squeezes out the top macro‑F1, hinting at slightly better coverage of minority classes with a tiny trade‑off in micro‑F1.
| Run | Epochs | Train Loss | Eval Loss | F1 (micro) | F1 (macro) | Train Time (s) | Train steps/s | Train samples/s | Eval Time (s) |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 4 | 1.400 | 0.157 | 0.824 | 0.738 | 1309.6 | 0.962 | 30.543 | 33.6 |
| 2 | 5 | 1.220 | 0.159 | 0.830 | 0.743 | 1640.3 | 0.768 | 24.385 | 34.0 |
| 3 | 6 | 1.063 | 0.162 | 0.826 | 0.752 | 1984.2 | 0.635 | 20.159 | 34.4 |
| 4 | 5 | 1.265 | 0.165 | 0.816 | 0.729 | 1639.3 | 0.769 | 24.401 | 34.0 |
0.830 at 5 epochs0.752 at 6 epochs0.824, macro‑F1 0.741, eval loss 0.1611@article{Hu2021LoRA,
2 title={LoRA: Low-Rank Adaptation of Large Language Models},
3 author={Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Lu Wang and Weizhu Chen},
4 journal={arXiv preprint arXiv:2106.09685},
5 year={2021}
6}
7
8@article{Dettmers2023QLoRA,
9 title={QLoRA: Efficient Finetuning of Quantized LLMs},
10 author={Tim Dettmers and Artidoro Pagnoni and Ari Holtzman and Luke Zettlemoyer},
11 journal={arXiv preprint arXiv:2305.14314},
12 year={2023}
13}llm_cls/cli.py) and example YAML config (configs/default.yaml) to reproduce results.bitsandbytes is unavailable, disable 4‑bit and train in standard precision.amirhossein-yousefi / Amirhossein75)Amirhossein75.