declare-lab/MELD
Updated • 5.89k • 25
How to use seivd/gemma3-4b-lora-meld with PEFT:
Task type is invalid.
How to use seivd/gemma3-4b-lora-meld with Transformers:
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("seivd/gemma3-4b-lora-meld", device_map="auto")Configuration Parsing Warning:In adapter_config.json: "peft.task_type" must be a string
Adaptateurs LoRA et tête de classification entraînés pour classer chaque réplique d'un dialogue en 7 émotions : neutral, anger, disgust, fear, joy, sadness, surprise. Le projet complet est décrit dans le README principal.
| Fichier | Contenu | Dans ce dépôt |
|---|---|---|
head.pt |
Couche linéaire 2 560 → 7, en float32 | Oui, et sur Hugging Face |
lora/ |
Adaptateurs LoRA (adapter_config.json, adapter_model.safetensors) |
Non (trop volumineux pour Git) : disponibles sur Hugging Face |
google/gemma-3-4b-it, gelé, en bfloat16.q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj et down_proj de la partie langage (encodeur d'images exclu). 119 209 984 paramètres entraînables, soit 2,70 %.[CTX] contexte [UTT] réplique [SEP].| Accuracy | F1 pondéré | F1 macro |
|---|---|---|
| 64,7 % | 64,6 % | 46,3 % |
Les poids sont téléchargés automatiquement depuis Hugging Face. Il faut avoir accepté la licence de google/gemma-3-4b-it.
import torch
from transformers import AutoTokenizer, AutoModel
from peft import PeftModel
from huggingface_hub import hf_hub_download
BASE = 'google/gemma-3-4b-it'
ADAPTER = 'seivd/gemma3-4b-lora-meld'
LABELS = ['neutral', 'anger', 'disgust', 'fear', 'joy', 'sadness', 'surprise'] # ordre utilisé à l'entraînement
tok = AutoTokenizer.from_pretrained(BASE)
tok.padding_side, tok.truncation_side = 'right', 'left'
base = AutoModel.from_pretrained(BASE, dtype=torch.bfloat16)
model = PeftModel.from_pretrained(base, ADAPTER).eval()
head = torch.nn.Linear(base.config.text_config.hidden_size, len(LABELS))
head.load_state_dict(torch.load(hf_hub_download(ADAPTER, 'head.pt'), map_location='cpu')); head.eval()
def predict(utterance, context=()):
text = f"[CTX] {' '.join(context) or 'none'} [UTT] {utterance} [SEP]"
enc = tok(text, return_tensors='pt', truncation=True, max_length=512)
with torch.no_grad():
h = model(input_ids=enc['input_ids'], attention_mask=enc['attention_mask']).last_hidden_state.float()
m = enc['attention_mask'].unsqueeze(-1).float()
probs = head((h * m).sum(1) / m.sum(1)).softmax(-1)[0]
return dict(sorted(zip(LABELS, probs.tolist()), key=lambda x: -x[1]))
print(predict("I can't believe you did that!", ["Hey, I borrowed your car.", "And I crashed it."]))
Sur un Mac, ajoutez base = base.to('mps') et déplacez enc et head sur le même appareil pour accélérer.