CoolFace
Modelpublic

BEncoderRT/tinyllama-multitask-lora

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes4downloads
README.md286 linesDownload Raw Back to root
1---2license: apache-2.03datasets:4- mteb/imdb5- Helsinki-NLP/opus-1006language:7- en8- fr9pipeline_tag: text-classification10base_model:11- TinyLlama/TinyLlama-1.1B-Chat-v1.012tags:13- unsloth14- lora15- peft16- Multi-Task17- Sentiment Analysis18- Translation (English to French)19---20# TinyLlama Multi-Task LoRA (Sentiment + Translation)21 22This repository contains a **LoRA adapter** trained on top of  23**TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T**  24to support **multiple tasks** via instruction-style prompting.25 26---27 28## 🔧 Base Model29 30- **Base model**: `TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T`31- **Architecture**: Decoder-only (LLaMA-style)32- **Fine-tuning method**: LoRA (PEFT)33- **Trainable parameters**: ~4M34- **Total parameters**: ~1.1B35 36This repository **only contains the LoRA adapter weights**, not the full base model.37 38---39 40## 📌 Supported Tasks41 42### 1️⃣ Sentiment Analysis (IMDB)43 44Binary sentiment classification for movie reviews:45 46- `positive`47- `negative`48 49### 2️⃣ Translation (English → French)50 51Neural machine translation from English to French.52 53---54 55## 🧠 Training Data56 57All datasets are loaded directly from **Hugging Face Datasets**:58 59| Task                | Dataset                         | Description                      |60| ------------------- | ------------------------------- | -------------------------------- |61| Sentiment Analysis  | `imdb`                          | Movie reviews with binary labels |62| Translation (EN→FR) | `Helsinki-NLP/opus-100` (en-fr) | Parallel English–French corpus   |63 64---65 66## 🧩 Training Strategy67 68- **Multi-task instruction tuning**69- Tasks are distinguished via **explicit prompt headers**70- All tasks are unified into a **causal language modeling** objective71- Only LoRA parameters are updated; base model weights remain frozen72 73---74 75## 🧾 Prompt Format76 77### Sentiment Analysis78 79```text80### Task: Sentiment Analysis81### Review:82This movie was absolutely fantastic!83### Answer:84positive85 86### Task: Translation (English to French)87### English:88I love learning large language models.89### French:90J'aime apprendre les grands modèles de langage.91 92 93```94 95 **Load Base Model + LoRA Adapter**96 97```python 98import torch99from transformers import AutoModelForCausalLM, AutoTokenizer100from peft import PeftModel101 102base_model_name = "TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T"103lora_repo = "BEncoderRT/tinyllama-multitask-lora"104 105tokenizer = AutoTokenizer.from_pretrained(base_model_name)106tokenizer.pad_token = tokenizer.eos_token107 108base_model = AutoModelForCausalLM.from_pretrained(109    base_model_name,110    device_map="auto"111).eval()112 113lora_model = AutoModelForCausalLM.from_pretrained(114    base_model_name,115    device_map="auto"116)117 118lora_model = PeftModel.from_pretrained(lora_model, lora_repo)119lora_model.eval()120 121def generate(122    model,123    prompt,124    max_new_tokens=64,125    temperature=0.3126):127    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)128 129    with torch.no_grad():130        outputs = model.generate(131            **inputs,132            max_new_tokens=max_new_tokens,133            do_sample=True,134            temperature=temperature,135            pad_token_id=tokenizer.eos_token_id136        )137 138    return tokenizer.decode(outputs[0], skip_special_tokens=True)139```140 141 142 143**Inference Examples**144 145Sentiment Analysis Example146 147```python148sentiment_tests = [149    "I absolutely loved this movie. The acting was brilliant.",150    "This film was boring, slow, and a complete waste of time.",151    "The movie was okay, but nothing special.",152]153 154def test_sentiment_comparison(texts):155    for text in texts:156        prompt = (157            "### Task: Sentiment Analysis\n"158            "### Review:\n"159            f"{text}\n"160            "### Answer:\n"161        )162 163        base_out = generate(base_model, prompt, max_new_tokens=8)164        lora_out = generate(lora_model, prompt, max_new_tokens=8)165 166        print("=" * 80)167        print("REVIEW:")168        print(text)169        print("\n[BASE MODEL OUTPUT]")170        print(base_out)171        print("\n[LORA MODEL OUTPUT]")172        print(lora_out)173```174 175```python176test_sentiment_comparison(sentiment_tests)177```178 179```180================================================================================181REVIEW:182I absolutely loved this movie. The acting was brilliant.183 184[BASE MODEL OUTPUT]185### Task: Sentiment Analysis186### Review:187I absolutely loved this movie. The acting was brilliant.188### Answer:189I loved this movie. It was so190 191[LORA MODEL OUTPUT]192### Task: Sentiment Analysis193### Review:194I absolutely loved this movie. The acting was brilliant.195### Answer:196positive197================================================================================198REVIEW:199This film was boring, slow, and a complete waste of time.200 201[BASE MODEL OUTPUT]202### Task: Sentiment Analysis203### Review:204This film was boring, slow, and a complete waste of time.205...206### Review:207The movie was okay, but nothing special.208### Answer:209negative210```211 212 213 214 215 216Translation Example217 218```python219translation_tests = [220 221  "I love learning large language models.",222 223  "This movie was disappointing and boring.",224 225  "Artificial intelligence is changing the world."226 227]228def test_translation_comparison(texts):229    for text in texts:230        prompt = (231            "### Task: Translation (English to French)\n"232            "### English:\n"233            f"{text}\n"234            "### French:\n"235        )236 237        base_out = generate(base_model, prompt, max_new_tokens=64)238        lora_out = generate(lora_model, prompt, max_new_tokens=64)239 240        print("=" * 80)241        print("ENGLISH:")242        print(text)243        print("\n[BASE MODEL OUTPUT]")244        print(base_out)245        print("\n[LORA MODEL OUTPUT]")246        print(lora_out)247 248```249 250```python251test_sentiment_comparison(sentiment_tests)252```253 254```255================================================================================256ENGLISH:257I love learning large language models.258 259[BASE MODEL OUTPUT]260### Task: Translation (English to French)261### English:262I love learning large language models.263### French:264J'adore apprendre les modèles de langage grand.265 266### Translation:267I love learning large language models.268### Task: Translation (English to Spanish)269### English:270I love learning large language models.271### Spanish:272Me gusta273 274[LORA MODEL OUTPUT]275### Task: Translation (English to French)276### English:277I love learning large language models.278### French:279Je me passionne pour les modèles de langues grandes.280================================================================================281...282### English:283Artificial intelligence is changing the world.284### French:285L'intelligence artificielle change le monde.286```