reachy-gestures / README.md
andito's picture
andito HF Staff
Describe the best-gesture threshold and the app's expressiveness levels
7f8fe9d verified
|
Raw History Blame Contribute Delete
14.6 kB
metadata
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

Reachy Mini playing success1
success1
A task went well
Reachy Mini playing laughing2
laughing2
Something is funny
Reachy Mini playing grateful1
grateful1
Thanks
Reachy Mini playing welcoming2
welcoming2
Hello, welcome
Reachy Mini playing amazed1
amazed1
Something extraordinary
Reachy Mini playing downcast1
downcast1
Sadness
Reachy Mini playing fear1
fear1
Fright, shock
Reachy Mini playing irritated1
irritated1
Annoyance

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.

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

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. On the robot, the 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: the sentences, the labels, the training code and the exact commands (how to reproduce it). The teacher is 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), GoEmotions and BRIGHTER.
  • 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 with the same two output layers, published as 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, 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.