andito HF Staff commited on
Commit
5adba92
ยท
verified ยท
1 Parent(s): 027bfbe

Add a model card

Browse files
Files changed (1) hide show
  1. README.md +207 -0
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - es
6
+ - fr
7
+ - de
8
+ - it
9
+ - pt
10
+ - nl
11
+ - pl
12
+ - ru
13
+ - tr
14
+ - ar
15
+ - hi
16
+ - zh
17
+ - ja
18
+ - ko
19
+ - multilingual
20
+ base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
21
+ pipeline_tag: text-classification
22
+ library_name: onnx
23
+ tags:
24
+ - reachy-mini
25
+ - robotics
26
+ - gestures
27
+ - emotion
28
+ - distillation
29
+ - onnx
30
+ ---
31
+
32
+ # Reachy Mini gesture model
33
+
34
+ **A small multilingual model that picks the gesture Reachy Mini plays as it talks.**
35
+
36
+ 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.
37
+
38
+ | Sentence | Heard or said | Gesture |
39
+ |---|---|---|
40
+ | "We did it, the demo worked!" | said | `success1` |
41
+ | "Mi perro muriรณ ayer." | heard | `downcast1` |
42
+ | "Danke, das ist wirklich lieb von dir!" | heard | `grateful1` |
43
+ | "ๅ“‡๏ผŒ่ฟ™ๅคชไธๅฏๆ€่ฎฎไบ†๏ผ" | heard | `amazed1` |
44
+ | "Hmm, I'm not sure about that." | said | `uncertain1` |
45
+ | "Le train part ร  18 h 40." | said | none |
46
+
47
+ ## At a glance
48
+
49
+ | | |
50
+ |---|---|
51
+ | **Architecture** | Multilingual MiniLM-L12 encoder with two linear output layers |
52
+ | **Parameters** | 118M |
53
+ | **Shipped file** | `model_qint8.onnx`, 118 MB (int8) |
54
+ | **Speed on Reachy Mini (CM4, one thread)** | 62 ms median for heard turns, 97 ms for said sentences |
55
+ | **Languages** | Trained in 15 languages, tested on real text in over 20 |
56
+ | **Outputs** | 22 gestures for what the robot says, 15 for what it hears, plus "none" |
57
+
58
+ ## How it works
59
+
60
+ 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.
61
+ 2. The encoder's token embeddings are mean-pooled and L2-normalized.
62
+ 3. One of two linear output layers scores the gestures:
63
+ - `say` for what the robot says;
64
+ - `react` for what it hears.
65
+ 4. The softmax winner is played if its probability is at least 0.3. Below that, or when the winner is `none`, the sentence gets no gesture.
66
+
67
+ 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.
68
+
69
+ ## Usage
70
+
71
+ ```python
72
+ import json
73
+
74
+ import numpy as np
75
+ import onnxruntime as ort
76
+ from huggingface_hub import hf_hub_download
77
+ from tokenizers import Tokenizer
78
+
79
+ REPO = "HuggingFaceM4/reachy-gesture-student-minilm-e15-t4-full-q8b"
80
+
81
+ tokenizer = Tokenizer.from_file(hf_hub_download(REPO, "tokenizer.json"))
82
+ tokenizer.no_truncation()
83
+ session = ort.InferenceSession(hf_hub_download(REPO, "model_qint8.onnx"), providers=["CPUExecutionProvider"])
84
+ heads = np.load(hf_hub_download(REPO, "gesture_heads.npz"))
85
+ labels = json.load(open(hf_hub_download(REPO, "gesture_labels.json")))
86
+
87
+
88
+ def pick_gesture(text: str, kind: str = "say", threshold: float = 0.3) -> tuple[str, float]:
89
+ """kind is "say" for what the robot says, "react" for what it hears."""
90
+ ids = tokenizer.encode(text).ids
91
+ ids = [ids[0], *ids[1:-1][-62:], ids[-1]] # long turns keep their last 64 tokens
92
+ input_ids = np.array([ids], dtype=np.int64)
93
+ tokens = session.run(None, {
94
+ "input_ids": input_ids,
95
+ "attention_mask": np.ones_like(input_ids),
96
+ "token_type_ids": np.zeros_like(input_ids),
97
+ })[0][0]
98
+ embedding = tokens.mean(axis=0)
99
+ embedding /= np.linalg.norm(embedding)
100
+ logits = heads[f"{kind}_weight"] @ (embedding * 10.0) + heads[f"{kind}_bias"]
101
+ probs = np.exp(logits - logits.max())
102
+ probs /= probs.sum()
103
+ best = int(probs.argmax())
104
+ return (labels[kind][best] if probs[best] >= threshold else "none"), float(probs[best])
105
+
106
+
107
+ print(pick_gesture("We did it, the demo worked!", "say")) # ('success1', 0.99)
108
+ print(pick_gesture("Mi perro muriรณ ayer.", "react")) # ('downcast1', 0.99)
109
+ print(pick_gesture("Le train part ร  18 h 40.", "say")) # ('none', 0.99)
110
+ ```
111
+
112
+ 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.
113
+
114
+ ## Gestures
115
+
116
+ | Gesture | When | Said | Heard |
117
+ |---|---|:-:|:-:|
118
+ | `success1` | A task went well | โœ“ | โœ“ |
119
+ | `success2` | Celebrating good news or an achievement | โœ“ | |
120
+ | `laughing2` | Something is funny | โœ“ | โœ“ |
121
+ | `grateful1` | Thanks for a compliment or help | โœ“ | โœ“ |
122
+ | `loving1` | Warmth, affection, a fond goodbye | โœ“ | โœ“ |
123
+ | `welcoming2` | Hello, welcome, the pleasure is mine | โœ“ | โœ“ |
124
+ | `helpful1` | Happy to help | โœ“ | โœ“ |
125
+ | `surprised1` | Something unexpected | โœ“ | โœ“ |
126
+ | `amazed1` | Something extraordinary or admirable | โœ“ | โœ“ |
127
+ | `relief1` | A stressful situation is over | โœ“ | โœ“ |
128
+ | `calming1` | Soothing someone stressed or upset | โœ“ | โœ“ |
129
+ | `thoughtful2` | Thinking of an idea | โœ“ | โœ“ |
130
+ | `understanding2` | A nod of understanding | โœ“ | |
131
+ | `yes1` | A clear yes | โœ“ | |
132
+ | `no1` | A firm no | โœ“ | |
133
+ | `uncertain1` | No strong opinion, not sure | โœ“ | |
134
+ | `resigned1` | A sad yes, a grumpy OK | โœ“ | |
135
+ | `downcast1` | Sadness, discouragement | โœ“ | โœ“ |
136
+ | `fear1` | Danger, fright, shock | โœ“ | โœ“ |
137
+ | `disgusted1` | Disgust | โœ“ | โœ“ |
138
+ | `irritated1` | Annoyance, a small failure | โœ“ | โœ“ |
139
+ | `rage1` | Anger, injustice | โœ“ | |
140
+
141
+ 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.
142
+
143
+ ## Training
144
+
145
+ - **Sentences:** about 38k labelled sentences.
146
+ - 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.
147
+ - 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).
148
+ - **Labels:** `openai/gpt-oss-120b` and `moonshotai/Kimi-K3` each labelled every sentence. They agreed on 78% of them.
149
+ - The teacher was fine-tuned on the 30k sentences where they agree.
150
+ - Each label is a set of acceptable moves, so a sentence can accept more than one gesture.
151
+ - **Teacher:** [`Qwen/Qwen3-Embedding-8B`](https://huggingface.co/Qwen/Qwen3-Embedding-8B) with the same two output layers.
152
+ - It beat the smaller teachers tried (e5-large, bge-m3, EmbeddingGemma, Qwen3-Embedding 0.6B and 4B).
153
+ - **Distillation:** the teacher scored about 370k multilingual sentences.
154
+ - 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.
155
+ - 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.
156
+ - `training.json` has the full settings and per-epoch scores.
157
+ - **Quantization:** dynamic int8 quantization with ONNX Runtime. It changes each test score by less than a point.
158
+
159
+ ## Evaluation
160
+
161
+ 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.
162
+
163
+ | Model | GLM-written test (462) | Real conversation text (411) | Hard cases (119) | Opposite-feeling gestures |
164
+ |---|---|---|---|---|
165
+ | Phrase lookup (the approach this replaced) | 41.3% | 82.5% | 77.3% | 23 |
166
+ | **This model, int8** | **83.5%** | **94.9%** | **83.2%** | **6** |
167
+
168
+ - **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.
169
+ - **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.
170
+ - **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.
171
+ - **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.
172
+
173
+ ## Speed on Reachy Mini
174
+
175
+ Measured in an hour-long live conversation on a wireless Reachy Mini (Raspberry Pi CM4), with ONNX Runtime on one CPU thread:
176
+
177
+ | | |
178
+ |---|---|
179
+ | Heard turns | 62 ms median |
180
+ | Said sentences | 97 ms median |
181
+ | Cost per sentence | about 18 ms + 3.6 ms per token |
182
+ | Loading | 3.8 s, done after the greeting so it can't interrupt it |
183
+ | Time to first audio | unchanged, 141 ms median |
184
+
185
+ ## Files
186
+
187
+ | File | What it is |
188
+ |---|---|
189
+ | `model_qint8.onnx` | The int8 encoder the robot runs (118 MB) |
190
+ | `model.onnx` | The same encoder in float32 |
191
+ | `model.safetensors`, `config.json` | The encoder in float16, for fine-tuning with ๐Ÿค— Transformers |
192
+ | `gesture_heads.npz` | The two output layers: `say_weight`, `say_bias`, `react_weight`, `react_bias` |
193
+ | `gesture_labels.json` | The gesture name for each output, per layer |
194
+ | `tokenizer.json` and friends | The base model's tokenizer |
195
+ | `training.json` | Training settings and per-epoch scores |
196
+
197
+ ## Limitations
198
+
199
+ - **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.
200
+ - **Transcription errors:** a garbled transcript can still get a confident gesture.
201
+ - **Sentence by sentence:** it doesn't see the rest of the conversation.
202
+ - **Fixed moves:** it only knows the 22 moves above. New moves in the emotions library need retraining.
203
+ - **Model-written labels:** labels come from two LLMs. Their 78% agreement is a fair guide to how subjective some of these choices are.
204
+
205
+ ## License
206
+
207
+ Apache 2.0, the same as the base model.