File size: 14,629 Bytes
5adba92 cbb814d 5adba92 6a532b4 5adba92 7f8fe9d 5adba92 249d3ad 5adba92 7f8fe9d 5adba92 7f8fe9d 5adba92 7f8fe9d 5adba92 cbb814d 5adba92 cbb814d 5adba92 7f8fe9d 5adba92 | 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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | ---
license: apache-2.0
language:
- en
- es
- fr
- de
- it
- pt
- nl
- pl
- ru
- tr
- ar
- hi
- zh
- ja
- ko
- multilingual
base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
pipeline_tag: text-classification
library_name: onnx
tags:
- reachy-mini
- robotics
- gestures
- emotion
- distillation
- onnx
datasets:
- HuggingFaceM4/reachy-gestures-data
---
# Reachy Mini gesture model
**A small multilingual model that picks the gesture Reachy Mini plays as it talks.**
Every sentence the robot says, and every turn it hears, goes through this model. It picks one of Reachy Mini's recorded emotions, or none, in under 100 ms on the robot's Raspberry Pi CM4. That's fast enough to start the move with the sentence's audio, without adding latency to the conversation and without asking the LLM.
| Sentence | Heard or said | Gesture |
|---|---|---|
| "We did it, the demo worked!" | said | `success1` |
| "Mi perro muriรณ ayer." | heard | `downcast1` |
| "Danke, das ist wirklich lieb von dir!" | heard | `grateful1` |
| "ๅ๏ผ่ฟๅคชไธๅฏๆ่ฎฎไบ๏ผ" | heard | `amazed1` |
| "Hmm, I'm not sure about that." | said | `uncertain1` |
| "Le train part ร 18 h 40." | said | none |
## See it move
<table>
<tr>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/success1.gif" width="180" alt="Reachy Mini playing success1"/><br/><code>success1</code><br/><sub>A task went well</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/laughing2.gif" width="180" alt="Reachy Mini playing laughing2"/><br/><code>laughing2</code><br/><sub>Something is funny</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/grateful1.gif" width="180" alt="Reachy Mini playing grateful1"/><br/><code>grateful1</code><br/><sub>Thanks</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/welcoming2.gif" width="180" alt="Reachy Mini playing welcoming2"/><br/><code>welcoming2</code><br/><sub>Hello, welcome</sub></td>
</tr>
<tr>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/amazed1.gif" width="180" alt="Reachy Mini playing amazed1"/><br/><code>amazed1</code><br/><sub>Something extraordinary</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/downcast1.gif" width="180" alt="Reachy Mini playing downcast1"/><br/><code>downcast1</code><br/><sub>Sadness</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/fear1.gif" width="180" alt="Reachy Mini playing fear1"/><br/><code>fear1</code><br/><sub>Fright, shock</sub></td>
<td align="center"><img src="https://huggingface.co/HuggingFaceM4/reachy-gestures/resolve/main/assets/irritated1.gif" width="180" alt="Reachy Mini playing irritated1"/><br/><code>irritated1</code><br/><sub>Annoyance</sub></td>
</tr>
</table>
Eight of the 22 gestures, played the way the conversation app plays them: cut to at most 3 seconds and easing to a stop. They're rendered in the Reachy Mini MuJoCo simulator from the recorded moves.
## At a glance
| | |
|---|---|
| **Architecture** | Multilingual MiniLM-L12 encoder with two linear output layers |
| **Parameters** | 118M |
| **Shipped file** | `model_qint8.onnx`, 118 MB (int8) |
| **Speed on Reachy Mini (CM4, one thread)** | 62 ms median for heard turns, 97 ms for said sentences |
| **Languages** | Trained in 15 languages, tested on real text in over 20 |
| **Outputs** | 22 gestures for what the robot says, 15 for what it hears, plus "none" |
## How it works
1. The sentence is tokenized with the base model's tokenizer. A long turn keeps its **last** 64 tokens, so the robot reacts to how the person finished.
2. The encoder's token embeddings are mean-pooled and L2-normalized.
3. One of two linear output layers scores the gestures:
- `say` for what the robot says;
- `react` for what it hears.
4. The most likely gesture, leaving `none` aside, is played if its probability reaches a threshold. Otherwise the sentence gets no gesture. A gesture can play even when `none` is likelier, which is what lets a low threshold make the robot more expressive. See [Choosing a threshold](#choosing-a-threshold).
The robot uses separate output layers because the right move depends on who's talking. When the user says "my dog died", the robot should look sad, not celebrate having understood.
## Usage
```python
import json
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from tokenizers import Tokenizer
REPO = "HuggingFaceM4/reachy-gestures"
tokenizer = Tokenizer.from_file(hf_hub_download(REPO, "tokenizer.json"))
tokenizer.no_truncation()
session = ort.InferenceSession(hf_hub_download(REPO, "model_qint8.onnx"), providers=["CPUExecutionProvider"])
heads = np.load(hf_hub_download(REPO, "gesture_heads.npz"))
labels = json.load(open(hf_hub_download(REPO, "gesture_labels.json")))
def pick_gesture(text: str, kind: str = "say", threshold: float = 0.4) -> tuple[str, float]:
"""kind is "say" for what the robot says, "react" for what it hears.
Returns the most likely gesture and its probability, or "none" when that probability is under the threshold.
"""
ids = tokenizer.encode(text).ids
ids = [ids[0], *ids[1:-1][-62:], ids[-1]] # long turns keep their last 64 tokens
input_ids = np.array([ids], dtype=np.int64)
tokens = session.run(None, {
"input_ids": input_ids,
"attention_mask": np.ones_like(input_ids),
"token_type_ids": np.zeros_like(input_ids),
})[0][0]
embedding = tokens.mean(axis=0)
embedding /= np.linalg.norm(embedding)
logits = heads[f"{kind}_weight"] @ (embedding * 10.0) + heads[f"{kind}_bias"]
probs = np.exp(logits - logits.max())
probs /= probs.sum()
none = labels[kind].index("none")
best = max((i for i in range(len(probs)) if i != none), key=lambda i: probs[i])
return (labels[kind][best] if probs[best] >= threshold else "none"), float(probs[best])
print(pick_gesture("We did it, the demo worked!", "say")) # ('success1', 0.99)
print(pick_gesture("Mi perro muriรณ ayer.", "react")) # ('downcast1', 0.99)
print(pick_gesture("Le train part ร 18 h 40.", "say")) # ('none', 0.0007)
```
The names are moves from [`pollen-robotics/reachy-mini-emotions-library`](https://huggingface.co/datasets/pollen-robotics/reachy-mini-emotions-library). On the robot, the [Reachy Mini conversation app](https://github.com/pollen-robotics/reachy_mini_conversation_app) plays them through its movement manager, cut to at most 3 seconds.
## Gestures
| Gesture | When | Said | Heard |
|---|---|:-:|:-:|
| `success1` | A task went well | โ | โ |
| `success2` | Celebrating good news or an achievement | โ | |
| `laughing2` | Something is funny | โ | โ |
| `grateful1` | Thanks for a compliment or help | โ | โ |
| `loving1` | Warmth, affection, a fond goodbye | โ | โ |
| `welcoming2` | Hello, welcome, the pleasure is mine | โ | โ |
| `helpful1` | Happy to help | โ | โ |
| `surprised1` | Something unexpected | โ | โ |
| `amazed1` | Something extraordinary or admirable | โ | โ |
| `relief1` | A stressful situation is over | โ | โ |
| `calming1` | Soothing someone stressed or upset | โ | โ |
| `thoughtful2` | Thinking of an idea | โ | โ |
| `understanding2` | A nod of understanding | โ | |
| `yes1` | A clear yes | โ | |
| `no1` | A firm no | โ | |
| `uncertain1` | No strong opinion, not sure | โ | |
| `resigned1` | A sad yes, a grumpy OK | โ | |
| `downcast1` | Sadness, discouragement | โ | โ |
| `fear1` | Danger, fright, shock | โ | โ |
| `disgusted1` | Disgust | โ | โ |
| `irritated1` | Annoyance, a small failure | โ | โ |
| `rage1` | Anger, injustice | โ | |
Some moves only make sense as the robot's own reply (yes, no, unsure, resigned, anger, celebrating), so they only exist on the `say` side.
## Training
Everything needed to retrain this model is public in [`HuggingFaceM4/reachy-gestures-data`](https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data): the sentences, the labels, the training code and the exact commands ([how to reproduce it](https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data#reproduce-it)). The teacher is [`HuggingFaceM4/reachy-gestures-teacher`](https://huggingface.co/HuggingFaceM4/reachy-gestures-teacher).
- **Sentences:** about 38k labelled sentences.
- Written by `google/gemma-4-31B-it` and `openai/gpt-oss-120b` in 15 languages: English, Spanish, French, German, Italian, Portuguese, Dutch, Polish, Russian, Turkish, Arabic, Hindi, Chinese, Japanese and Korean.
- Plus real chat and social text from [OpenAssistant (oasst2)](https://huggingface.co/datasets/OpenAssistant/oasst2), [GoEmotions](https://huggingface.co/datasets/google-research-datasets/go_emotions) and [BRIGHTER](https://huggingface.co/datasets/brighter-dataset/BRIGHTER-emotion-categories).
- **Labels:** `openai/gpt-oss-120b` and `moonshotai/Kimi-K3` each labelled every sentence. They agreed on 78% of them.
- The teacher was fine-tuned on the 30k sentences where they agree.
- Each label is a set of acceptable moves, so a sentence can accept more than one gesture.
- **Teacher:** [`Qwen/Qwen3-Embedding-8B`](https://huggingface.co/Qwen/Qwen3-Embedding-8B) with the same two output layers, published as [`reachy-gestures-teacher`](https://huggingface.co/HuggingFaceM4/reachy-gestures-teacher).
- It beat the smaller teachers tried (e5-large, bge-m3, EmbeddingGemma, Qwen3-Embedding 0.6B and 4B).
- **Distillation:** the teacher scored about 370k multilingual sentences.
- The student, [`paraphrase-multilingual-MiniLM-L12-v2`](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2), learned from those scores (temperature 4) and from the labelled set.
- 15 epochs, AdamW, learning rate 4e-5 for the encoder and 2e-3 for the output layers, batch 64, 64 tokens. Trained on Hugging Face Jobs.
- `training.json` has the full settings and per-epoch scores.
- **Quantization:** dynamic int8 quantization with ONNX Runtime. It changes each test score by less than a point.
## Evaluation
All test sets are held out from training. Each sentence lists its acceptable answers, which can include no gesture. A prediction counts as correct when it is one of them.
| Model | GLM-written test (462) | Real conversation text (411) | Hard cases (119) | Opposite-feeling gestures |
|---|---|---|---|---|
| Phrase lookup (the approach this replaced) | 41.3% | 82.5% | 77.3% | 23 |
| **This model, int8** | **83.5%** | **94.9%** | **83.2%** | **6** |
- **GLM-written test:** 462 sentences written by `zai-org/GLM-5.3` in the 15 training languages. A different model wrote this set than the ones that wrote the training data.
- **Real conversation text:** 411 sentences from OpenAssistant, GoEmotions and BRIGHTER in over 20 languages. Several of them, such as Vietnamese, Thai, Catalan, Basque and Esperanto, are outside the 15 generated languages.
- **Hard cases:** 119 hand-written sentences that trip up simple approaches. They cover feelings stated plainly, implied feelings ("I got the job."), negation, neutral questions that need no gesture, and the same feelings in other languages.
- **Opposite-feeling gestures:** mistakes where the gesture has the opposite feeling to the right one, such as celebrating bad news. These are the errors people notice most.
### Choosing a threshold
The threshold trades how often the robot gestures against how often it picks a gesture that doesn't fit. This table runs the decision rule above, on the same test sets, at the four levels of the conversation app's **Expressiveness** setting:
| Threshold (app level) | Real text: gestured | Real text: correct | GLM-written: gestured | GLM-written: correct | Opposite-feeling gestures (GLM-written) |
|---|---|---|---|---|---|
| 0.8 (when necessary) | 21% | 93.7% | 51% | 74.2% | 0 |
| **0.4 (when sure, the default)** | **22%** | **93.9%** | **68%** | **83.5%** | **5** |
| 0.05 (even when unsure) | 27% | 91.7% | 74% | 82.9% | 7 |
- **0.4 scored best on the validation set.** It makes the same decision as the rule the scores above were measured with on all but 5 of the 992 test sentences.
- **The model is decisive.** Most real conversation text is neutral, so even the lowest threshold raises the share of real-text sentences with a gesture only from 22% to 27%.
- **Don't go below about 0.05.** There the model's pick is close to random. Forced to gesture on neutral sentences, it picks a negative gesture, such as fear, for about 30% of them. The app's "every sentence" level uses 0.05 and plays a calm nod or thinking look on the robot's other sentences instead.
## Speed on Reachy Mini
Measured in an hour-long live conversation on a wireless Reachy Mini (Raspberry Pi CM4), with ONNX Runtime on one CPU thread:
| | |
|---|---|
| Heard turns | 62 ms median |
| Said sentences | 97 ms median |
| Cost per sentence | about 18 ms + 3.6 ms per token |
| Loading | 3.8 s, done after the greeting so it can't interrupt it |
| Time to first audio | unchanged, 141 ms median |
## Files
| File | What it is |
|---|---|
| `model_qint8.onnx` | The int8 encoder the robot runs (118 MB) |
| `model.onnx` | The same encoder in float32 |
| `model.safetensors`, `config.json` | The encoder in float16, for fine-tuning with ๐ค Transformers |
| `gesture_heads.npz` | The two output layers: `say_weight`, `say_bias`, `react_weight`, `react_bias` |
| `gesture_labels.json` | The gesture name for each output, per layer |
| `tokenizer.json` and friends | The base model's tokenizer |
| `training.json` | Training settings and per-epoch scores |
## Limitations
- **Text only:** it reads what was said, not how. Tone, sarcasm and teasing that only show in the voice are often missed. It sometimes reads irritation into friendly teasing.
- **Transcription errors:** a garbled transcript can still get a confident gesture.
- **Sentence by sentence:** it doesn't see the rest of the conversation.
- **Fixed moves:** it only knows the 22 moves above. New moves in the emotions library need retraining.
- **Model-written labels:** labels come from two LLMs. Their 78% agreement is a fair guide to how subjective some of these choices are.
## License
Apache 2.0, the same as the base model.
|