Describe the best-gesture threshold and the app's expressiveness levels
Browse files
README.md
CHANGED
|
@@ -83,7 +83,7 @@ Eight of the 22 gestures, played the way the conversation app plays them: cut to
|
|
| 83 |
3. One of two linear output layers scores the gestures:
|
| 84 |
- `say` for what the robot says;
|
| 85 |
- `react` for what it hears.
|
| 86 |
-
4. The
|
| 87 |
|
| 88 |
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.
|
| 89 |
|
|
@@ -106,8 +106,11 @@ heads = np.load(hf_hub_download(REPO, "gesture_heads.npz"))
|
|
| 106 |
labels = json.load(open(hf_hub_download(REPO, "gesture_labels.json")))
|
| 107 |
|
| 108 |
|
| 109 |
-
def pick_gesture(text: str, kind: str = "say", threshold: float = 0.
|
| 110 |
-
"""kind is "say" for what the robot says, "react" for what it hears.
|
|
|
|
|
|
|
|
|
|
| 111 |
ids = tokenizer.encode(text).ids
|
| 112 |
ids = [ids[0], *ids[1:-1][-62:], ids[-1]] # long turns keep their last 64 tokens
|
| 113 |
input_ids = np.array([ids], dtype=np.int64)
|
|
@@ -121,13 +124,14 @@ def pick_gesture(text: str, kind: str = "say", threshold: float = 0.3) -> tuple[
|
|
| 121 |
logits = heads[f"{kind}_weight"] @ (embedding * 10.0) + heads[f"{kind}_bias"]
|
| 122 |
probs = np.exp(logits - logits.max())
|
| 123 |
probs /= probs.sum()
|
| 124 |
-
|
|
|
|
| 125 |
return (labels[kind][best] if probs[best] >= threshold else "none"), float(probs[best])
|
| 126 |
|
| 127 |
|
| 128 |
print(pick_gesture("We did it, the demo worked!", "say")) # ('success1', 0.99)
|
| 129 |
print(pick_gesture("Mi perro muri贸 ayer.", "react")) # ('downcast1', 0.99)
|
| 130 |
-
print(pick_gesture("Le train part 脿 18 h 40.", "say")) # ('none', 0.
|
| 131 |
```
|
| 132 |
|
| 133 |
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.
|
|
@@ -193,6 +197,20 @@ All test sets are held out from training. Each sentence lists its acceptable ans
|
|
| 193 |
- **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.
|
| 194 |
- **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.
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
## Speed on Reachy Mini
|
| 197 |
|
| 198 |
Measured in an hour-long live conversation on a wireless Reachy Mini (Raspberry Pi CM4), with ONNX Runtime on one CPU thread:
|
|
|
|
| 83 |
3. One of two linear output layers scores the gestures:
|
| 84 |
- `say` for what the robot says;
|
| 85 |
- `react` for what it hears.
|
| 86 |
+
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).
|
| 87 |
|
| 88 |
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.
|
| 89 |
|
|
|
|
| 106 |
labels = json.load(open(hf_hub_download(REPO, "gesture_labels.json")))
|
| 107 |
|
| 108 |
|
| 109 |
+
def pick_gesture(text: str, kind: str = "say", threshold: float = 0.4) -> tuple[str, float]:
|
| 110 |
+
"""kind is "say" for what the robot says, "react" for what it hears.
|
| 111 |
+
|
| 112 |
+
Returns the most likely gesture and its probability, or "none" when that probability is under the threshold.
|
| 113 |
+
"""
|
| 114 |
ids = tokenizer.encode(text).ids
|
| 115 |
ids = [ids[0], *ids[1:-1][-62:], ids[-1]] # long turns keep their last 64 tokens
|
| 116 |
input_ids = np.array([ids], dtype=np.int64)
|
|
|
|
| 124 |
logits = heads[f"{kind}_weight"] @ (embedding * 10.0) + heads[f"{kind}_bias"]
|
| 125 |
probs = np.exp(logits - logits.max())
|
| 126 |
probs /= probs.sum()
|
| 127 |
+
none = labels[kind].index("none")
|
| 128 |
+
best = max((i for i in range(len(probs)) if i != none), key=lambda i: probs[i])
|
| 129 |
return (labels[kind][best] if probs[best] >= threshold else "none"), float(probs[best])
|
| 130 |
|
| 131 |
|
| 132 |
print(pick_gesture("We did it, the demo worked!", "say")) # ('success1', 0.99)
|
| 133 |
print(pick_gesture("Mi perro muri贸 ayer.", "react")) # ('downcast1', 0.99)
|
| 134 |
+
print(pick_gesture("Le train part 脿 18 h 40.", "say")) # ('none', 0.0007)
|
| 135 |
```
|
| 136 |
|
| 137 |
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.
|
|
|
|
| 197 |
- **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.
|
| 198 |
- **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.
|
| 199 |
|
| 200 |
+
### Choosing a threshold
|
| 201 |
+
|
| 202 |
+
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:
|
| 203 |
+
|
| 204 |
+
| Threshold (app level) | Real text: gestured | Real text: correct | GLM-written: gestured | GLM-written: correct | Opposite-feeling gestures (GLM-written) |
|
| 205 |
+
|---|---|---|---|---|---|
|
| 206 |
+
| 0.8 (when necessary) | 21% | 93.7% | 51% | 74.2% | 0 |
|
| 207 |
+
| **0.4 (when sure, the default)** | **22%** | **93.9%** | **68%** | **83.5%** | **5** |
|
| 208 |
+
| 0.05 (even when unsure) | 27% | 91.7% | 74% | 82.9% | 7 |
|
| 209 |
+
|
| 210 |
+
- **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.
|
| 211 |
+
- **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%.
|
| 212 |
+
- **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.
|
| 213 |
+
|
| 214 |
## Speed on Reachy Mini
|
| 215 |
|
| 216 |
Measured in an hour-long live conversation on a wireless Reachy Mini (Raspberry Pi CM4), with ONNX Runtime on one CPU thread:
|