Views
No views yet
1HUMAN: {human_text}
2ROBOT: {robot_text}annamanaseryan/cozmo-emotion-grpo.microsoft/deberta-v3-basemodeling_emotion.py (EmotionClassifier)Not a drop-inAutoModelForSequenceClassificationcheckpoint. Load with the provided class +best_model.bin.
| 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.| File | Role |
|---|---|
best_model.bin | SFT state_dict for EmotionClassifier |
modeling_emotion.py | Model definition |
emotion_labels.yaml | Label map |
| Tokenizer files | Same tokenizer used in training |
pip install torch transformers pyyaml huggingface_hub1import torch
2import yaml
3from huggingface_hub import hf_hub_download, snapshot_download
4from transformers import AutoTokenizer
5from modeling_emotion import EmotionClassifier # download this file from the repo
6
7REPO = "annamanaseryan/cozmo-emotion-sft"
8device = "cuda" if torch.cuda.is_available() else "cpu"
9
10# Prefer downloading the whole repo once, then import modeling_emotion from that folder
11local = snapshot_download(REPO)
12import sys
13sys.path.insert(0, local)
14from modeling_emotion import EmotionClassifier
15
16with open(f"{local}/emotion_labels.yaml") as f:
17 cfg = yaml.safe_load(f)
18id2desc = {int(i): d["description"] for i, d in cfg["emotions"].items()}
19
20tokenizer = AutoTokenizer.from_pretrained(local)
21model = EmotionClassifier(n_classes=6, model_name="microsoft/deberta-v3-base")
22state = torch.load(f"{local}/best_model.bin", map_location="cpu")
23model.load_state_dict(state)
24model.to(device).eval()
25
26def predict(human: str, robot: str, max_length: int = 256):
27 text = f"HUMAN: {human}\nROBOT: {robot}"
28 inputs = tokenizer(
29 text,
30 return_tensors="pt",
31 max_length=max_length,
32 padding="max_length",
33 truncation=True,
34 ).to(device)
35 with torch.no_grad():
36 logits = model(**inputs)
37 probs = torch.softmax(logits, dim=-1).cpu().squeeze()
38 return {id2desc[i]: float(probs[i]) for i in range(len(probs))}
39
40print(predict("Why is the sky blue?", "because of the light."))inference_example.py there.