Views
No views yet
| This repo | Not included here |
|---|---|
LoRA weights (adapter_model.safetensors) | Full DeBERTa weights |
adapter_config.json | SFT best_model.bin (required separately) |
microsoft/deberta-v3-base (encoder backbone, from Hugging Face)annamanaseryan/cozmo-emotion-sft (best_model.bin + tokenizer + EmotionClassifier)1HUMAN: {human_text}
2ROBOT: {robot_text}| Id | Description |
|---|---|
| 0 | anger_frustration |
| 1 | interest_desire |
| 2 | confusion_sorrow_boredom |
| 3 | joy_hope |
| 4 | understanding_gratitude_relief |
| 5 | disgust_surprise_alarm_fear |
emotion_labels.yaml.r=8, lora_alpha=16, lora_dropout=0.05query_proj, key_proj, value_projpip install torch transformers peft pyyaml huggingface_hub1import sys
2import torch
3import yaml
4from huggingface_hub import snapshot_download
5from transformers import AutoTokenizer
6from peft import PeftModel
7
8SFT_REPO = "annamanaseryan/cozmo-emotion-sft"
9GRPO_REPO = "annamanaseryan/cozmo-emotion-grpo"
10device = "cuda" if torch.cuda.is_available() else "cpu"
11
12sft_dir = snapshot_download(SFT_REPO)
13grpo_dir = snapshot_download(GRPO_REPO)
14
15sys.path.insert(0, sft_dir)
16from modeling_emotion import EmotionClassifier
17
18with open(f"{sft_dir}/emotion_labels.yaml") as f:
19 cfg = yaml.safe_load(f)
20id2desc = {int(i): d["description"] for i, d in cfg["emotions"].items()}
21
22tokenizer = AutoTokenizer.from_pretrained(sft_dir)
23base = EmotionClassifier(n_classes=6, model_name="microsoft/deberta-v3-base")
24base.load_state_dict(torch.load(f"{sft_dir}/best_model.bin", map_location="cpu"))
25model = PeftModel.from_pretrained(base, grpo_dir)
26model.to(device).eval()
27
28def predict(human: str, robot: str, max_length: int = 256):
29 text = f"HUMAN: {human}\nROBOT: {robot}"
30 inputs = tokenizer(
31 text,
32 return_tensors="pt",
33 max_length=max_length,
34 padding="max_length",
35 truncation=True,
36 ).to(device)
37 with torch.no_grad():
38 logits = model(**inputs)
39 probs = torch.softmax(logits, dim=-1).cpu().squeeze()
40 out = {id2desc[i]: float(probs[i]) for i in range(len(probs))}
41 pred = max(out, key=out.get)
42 return pred, out
43
44label, dist = predict("Do you have empathy?", "i try to understand.")
45print(label)
46print(dist)inference_example.py.