File size: 5,647 Bytes
7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb 7d5542f 464ceeb d4220b1 464ceeb d4220b1 464ceeb d4220b1 7d5542f d4220b1 7d5542f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
---
license: apache-2.0
language:
- en
- fr
pipeline_tag: text-generation
tags:
- lora
- peft
- multi-task
- sentiment-analysis
- translation
- tinyllama
- adapter-fusion
base_model: TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T
---
- # LoRA Fusion: IMDB Sentiment + EN-FR Translation on TinyLlama-1.1B
This repository contains a **fully merged multi-task model** created by **sequentially fusing two independently trained LoRA adapters** into a single TinyLlama-1.1B base model.
The final model supports **multiple tasks within one unified set of weights**, without requiring PEFT or LoRA adapters at inference time.
------
## π§ Tasks Supported
The model is capable of performing the following tasks via prompt-based inference:
- π§ **Sentiment Analysis**
Binary sentiment classification (positive / negative) trained on the **IMDB movie review dataset**.
- π **English β French Translation**
Neural machine translation trained on **OPUS-100 (EN-FR)** data.
------
## π§ How This Model Was Built
### Base Model
- **TinyLlama-1.1B**
```
TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T
```
### Independent LoRA Adapters
Two LoRA adapters were trained **independently**, each specializing in a single task:
1. **IMDB Sentiment Analysis LoRA**
```
BEncoderRT/IMDB-Sentiment-LoRA-TinyLlama-1.1B
```
2. **English β French Translation LoRA**
```
BEncoderRT/EN-FR-Translation-LoRA-TinyLlama-1.1B
```
### Fusion Method: Sequential LoRA Merge
The final model was created using **sequential LoRA fusion**:
1. Load the frozen TinyLlama base model
2. Merge the sentiment analysis LoRA into the base model
3. Treat the merged model as a new base
4. Merge the translation LoRA into the updated base
5. Export the final merged weights
This process uses `merge_and_unload()` from **PEFT**, resulting in a **standard `LlamaForCausalLM` model**.
> β οΈ **Important**
> This repository does **NOT** contain LoRA adapters.
> It contains a **fully merged model** and should **NOT** be loaded with `PeftModel`.
---
## π§ Architecture
ββββββββββββββββββββββββββββ
β TinyLlama-1.1B Base LMβ
β (Frozen Parameters) β
ββββββββββββββ¬ββββββββββββββ
β
βββββββββββββββββββ΄ββββββββββββββββββ
β β
ββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β Sentiment LoRA Adapter β βTranslation LoRA Adapterβ
β (IMDB) β β (EN β FR) β
ββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
set_adapter("sentiment") set_adapter("translation")
---
# Usage Example
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
repo_id = "BEncoderRT/LoRA_Fusion_IMDB-Sentiment_EN-FR"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
tokenizer.pad_token = tokenizer.eos_token
model = AutoModelForCausalLM.from_pretrained(
repo_id,
device_map="auto",
torch_dtype="auto"
)
model.eval()
```
```
LlamaForCausalLM(
(model): LlamaModel(
(embed_tokens): Embedding(32000, 2048)
(layers): ModuleList(
(0-21): 22 x LlamaDecoderLayer(
(self_attn): LlamaAttention(
(q_proj): Linear(in_features=2048, out_features=2048, bias=False)
(k_proj): Linear(in_features=2048, out_features=256, bias=False)
(v_proj): Linear(in_features=2048, out_features=256, bias=False)
(o_proj): Linear(in_features=2048, out_features=2048, bias=False)
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=2048, out_features=5632, bias=False)
(up_proj): Linear(in_features=2048, out_features=5632, bias=False)
(down_proj): Linear(in_features=5632, out_features=2048, bias=False)
(act_fn): SiLUActivation()
)
(input_layernorm): LlamaRMSNorm((2048,), eps=1e-05)
(post_attention_layernorm): LlamaRMSNorm((2048,), eps=1e-05)
)
)
(norm): LlamaRMSNorm((2048,), eps=1e-05)
(rotary_emb): LlamaRotaryEmbedding()
)
```
```python
def generate(prompt, max_new_tokens=32):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
temperature=0.3,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(output[0], skip_special_tokens=True)
```
```python
print(generate(
"### Task: Sentiment Analysis\n### Review:\nThis movie was amazing.\n### Answer:\n",
8
))
```
```
The following generation flags are not valid and may be ignored: ['temperature']. Set `TRANSFORMERS_VERBOSITY=info` for more details.
### Task: Sentiment Analysis
### Review:
This movie was amazing.
### Answer:
positive
```
```python
print(generate(
"### Task: Translation (English to French)\n### English:\nI love deep learning.\n### French:\n",
32
))
```
```
### Task: Translation (English to French)
### English:
I love deep learning.
### French:
Je tiens Γ la deep learning.
```
|