Interpretability · Neurons · Torque · Balance · Muay Thai

Torque and neural visualisation of Muay Thai techniques

By Tony Yum ·

The chrome robot fighter in a right high kick, his kicking ankle and both toes glowing yellow at full torque, beside a telemetry panel: a heatmap of joint force over time and a raster of 512 neurons sorted by when they fire

In short. The AI fighter’s brain is a small neural network: 465 numbers in, two layers of 512 neurons, 48 joint commands out, 50 times a second. I recorded everything inside it, and every joint’s torque, while it stood, took a 260 N shove from four directions, was knocked over by a 900 N one, and threw fourteen techniques. Then I drew the two side by side: the joints glow yellow with how hard their motor pushes, and a panel shows the neurons fire. Standing, no neuron is far from its resting level. A shove wakes 98–146 neurons within 0.16 s, and the fighter steps back into balance every time. The knockdown: the network’s own forecast of how things will go halves 40 ms after the push; the body hits the floor 1.94 s later. A press of a technique’s button lights 108–140 neurons on the very next tick, before the body has moved. Fingerprints: a cross and a rear hook share 28 of their 40 most responsive neurons, a jab and a left high kick share 2. Force: in almost every punch the busiest joints are the hips, not the arms; in the knees and kicks the feet take over.

Why look inside

Every other post judges the fighter from the outside: did the punch land, did it fall, does it look like Muay Thai. On 29 October I asked for something different: a film that shows “how these neural networks are interpreted in terms of what techniques being used, which neurons activated”, because “seeing through the brain of the fighter actually helps our understanding of techniques”. I wanted the torques of the joints too, and to watch the brain react as the fighter goes from balance to being knocked over, gets hit from various directions and has to rebalance.

Looking inside a trained network to see what its parts do is called interpretability. This post is a first, simple pass at it: no new training, just one fighter, recorded carefully, and a way to draw what it does.

The brain being looked at

The fighter is the current student, distill9-196.6M: one policy that has every technique on the try page, distilled from the teachers in earlier posts. Fifty times a second it reads its observation, 465 numbers: the angles and speeds of its joints, how its body is moving, where its feet are, the phase of the stance’s rhythm, and which technique button is pressed. Those pass through two hidden layers of 512 neurons each (an MLP with ELU activations) and come out as 48 numbers: a target angle for every joint’s servo. A second network, the critic, reads the same 465 numbers and gives one: its estimate of how much reward the next few seconds will bring. In the pictures that is the forecast.

A diagram of four columns of dots: 465 inputs, layer 1 with 512 neurons, layer 2 with 512 neurons and 48 commands, with some dots lit orange and blue
Figure 1. The fighter's brain: 465 inputs, two layers of 512 neurons, 48 commands, one per joint motor, 50 times a second. The dots light up as a signal passes through; the lines are a sample of the connections (each layer has 512 × 512 of them).

Two ways to look

Joint force. Each joint motor has a maximum torque, set so the fighter is no stronger than a person. Every physics step I recorded how hard each one pushed, as a percentage of its own maximum. A joint with several motors (the hip turns three ways) shows its strongest. On the body, each joint glows yellow with that percentage; in the panel’s heatmap each row is a joint and time runs left to right. A percentage of each motor’s own maximum is how close the joint is to its limit, not how much force it makes: the hip’s strongest motor has a maximum of 220 N·m, the elbow’s 90 and the toes’ 30.

Neurons. For the second layer’s 512 neurons I first recorded three seconds of quiet standing, to learn each neuron’s resting level and how much it wanders. A neuron’s response at any moment is how far it is from rest, in units of its own wandering, a z-score:

zi(t)=∣hi(t)−μi∣σi+0.05z_i(t) = \frac{\left|h_i(t) - \mu_i\right|}{\sigma_i + 0.05}

where hi(t)h_i(t) is the neuron’s output, μi\mu_i and σi\sigma_i its mean and spread while standing (0.05 keeps a neuron that never moves from dividing by nearly zero). Over 3, I call it lit. In the panel each neuron is a row, sorted by when it peaks, so a wave of activity reads as a diagonal sweep. Bright means far from rest.

Every segment below started from the same reset, in the same stance, and was recorded once at 60 frames a second on the MuJoCo simulation. The robot body is drawn in Blender over the simulated one.

Standing: never still

The fighter in his stance, hips glowing faintly, beside a calm joint heatmap and a neuron raster with no lit rows
Figure 2. The stance. The hips hold about a third of their strength (left 34 %, right 26 %) and the right knee 22 %. In the second layer, nothing is lit: the raster is the neurons' quiet wandering.

Standing is never still. The stance has a rhythm, a gentle bounce on the lead foot, and the legs carry the body’s weight through it, so the hips and knees are always working. The neurons hum but never stray: in the quiet seconds not one is lit.

A push from four sides

Then a steel block hits the chest: 260 N for 0.16 s, from in front, from behind, from the left and from the right, each from a fresh start.

The fighter stepping back after a steel block hit his chest, both hips glowing, with the neuron raster lighting up in a diagonal sweep after the push
Figure 3. Shoved from the front, 1 s after the push. The left hip is at 85 % of its maximum, the right hip at 76 %. In the raster, a sweep of neurons lights up after the push line.

Within 0.16 s of the block landing, 98–146 neurons are lit, depending on the direction (front 98, behind 130, left 146, right 144); at their peak 161–174. Over the second after the push, both hips average 60–64 % of their maximum when pushed from the front, and three to five joints touch 95 % or more. The fighter steps and is balanced again every time.

In all four the environment switched on survive mode. It comes on when the body’s capture point, where its momentum is carrying it, heads past the edge of its feet, and goes off once it is calm again. In survive mode the legs may move further from the stance and the only reward is staying up. The network sees the mode as one of its inputs; the recovery itself is learnt.

Do different pushes use different neurons? For each direction I took the 40 neurons that responded most in the second after the push and counted how many each pair of directions share:

behindleftright
front181825
behind3018
left16
Four horizontal bands, one per push direction, each showing the 512 neurons' response; the bands for behind and left are lit in the same places
Figure 4. The 512 second-layer neurons, grouped by the push they answer most; bright = strong. Pushes from the left and the right share only 16 of their 40 strongest neurons; from behind and from the left, 30.

Left and right are told apart most clearly, which makes sense: they need opposite answers. The surprise is that a push from behind and one from the left look almost the same to it. My guess, not something I measured: in its side-on stance, both tip it the same way, over its lead side. Nobody designed this map; it grew out of the millions of shoves in its training.

Knocked over

The same push at 900 N is too big to hold.

The fighter falling backwards with his ankle and toes glowing, the forecast line in the panel already lowThe fighter lying on the floor, toes still glowing, the forecast line at the bottom of its range
Figure 5. The 900 N push. Top: 0.45 s after it, falling, with the left ankle and toes at 100 %; the red forecast line at the bottom of the panel has already dropped. Below: on the floor 2.4 s after the push, still pushing with its toes.

The forecast before the push is 555 (the reward it expects over its horizon). Two ticks after the push, 40 ms, it is already below half. It bottoms out at −92 a second later. The body hits the floor at 1.94 s. The network knew it would fall long before it did, and kept fighting anyway: 187 neurons lit at 0.16 s, nine joints at 95 % or more of their maximum. On the ground, it keeps trying.

Pressing a technique

A technique starts with a button: one of the 465 inputs flips from 0 to 1.

The fighter jabbing, hips glowing, with a burst of activity in the joint heatmap and neuron raster just after the press line
Figure 6. A jab, 0.75 s after the press. The busiest joint is the left hip (44 % at this moment); 161 neurons are lit. The vertical line in both panels is the press.

On the very next tick, 20 ms later, 108–140 neurons are lit, across all fourteen techniques, before the body has moved at all: the press itself is the cause, not anything the body felt. Then the wave spreads, peaking at 179–232 neurons: up to 45 % of the layer for one technique.

Three techniques switched survive mode on for a moment: the rear hook, the switch knee and the pull counter. For a short time each of them put the capture point past the edge of the feet, so close to falling that the balance rules took over.

The fighter coming forward out of a lean back, his right toes and ankle glowing, with a long diagonal sweep in the neuron raster
Figure 7. The pull counter, 0.88 s after the press: lean back, then come forward with the counter. The right toes are at 97 %, the right ankle at 92 %.

Neural fingerprints

Each push and technique leaves a pattern: every neuron’s average response over the second after it. I scaled each pattern to the same size (otherwise the loud techniques all look alike just for being loud), took away the average pattern, and compared each pair with cosine similarity: 1 for the same neurons in the same proportions, 0 for unrelated, negative for opposite.

A 19 by 19 grid coloured red to blue, with a red block for the four pushes and another for jab, cross and the two hooks
Figure 8. How alike each pair of moves' neuron responses are: red = the same neurons, blue = different. The pushes form one block, the straight punches and hooks another; the uppercuts, elbows, knees and kicks each mostly stand alone.
  • The straight punches and hooks share much of their brain. A cross and a rear hook: similarity 0.75, and 28 of their 40 most responsive neurons in common. Jab and cross 0.69 (23 of 40), the two hooks 26 of 40.
  • The pushes are a family of their own. Behind and left are the most alike pair of anything: 0.93.
  • The rest are individuals. A jab and a left high kick share 2 of 40. The two high kicks share 9, the rear and switch knees 11. Each knee and kick has neurons of its own.
  • A shared core. Eleven neurons are in the top 60 of at least 70 % of the techniques: something every technique uses, whatever it is.

The uppercuts don’t join the punches’ block: in the grid they sit with the elbows, knees and kicks, each mostly on its own.

Where the force comes from

The joints tell what each technique asks of the body. For each, the three joints that worked hardest on average in the second after the press:

A table of fourteen techniques, each with its three hardest-working joints as labelled tags; left and right hips appear in most rows, toes and ankles in the knees and kicks
Figure 9. Each technique's three hardest-working joints: mean torque as a percentage of the joint's maximum, in the second after the press. Hips (and in the kicks, ankles and toes) dominate.
  • Punches: the hips are the top two joints in every punch: the jab (left hip 56 %, right 54 %), the cross (61 %, 49 %), both hooks and both uppercuts. In the rear hook, the rear uppercut and the cross to the body the lower back is next (38–43 %). The arm joints never make the top three, apart from the lead hook’s shoulder girdle (29 %).
  • Knees and kicks: the feet take over. The switch knee’s left toes 82 %; the right high kick’s toes 65–66 % on both feet and its right ankle 64 %; the left high kick’s left ankle 69 % and right hip 68 %. The standing foot works as hard as the kicking one: it is the only thing holding the body up.

What this does and doesn’t show

  • It shows what goes together, not what causes what. A neuron that lights up during a hook might drive the hook, or only notice it. The next step is to switch neurons off, or hold them at rest, and see which techniques break.
  • One take each. Every push and technique is one recording from one start. The counts would shift a little with another start, and with the threshold (3) I chose for “lit”.
  • The second layer only. The first layer and the critic’s own neurons aren’t drawn.
  • Percent of each motor’s own maximum. Hips and ankles have far stronger motors than elbows, so the same percentage is not the same force.

No one told these neurons what to mean, or the fighter where a punch’s force should come from. Both were found by trial and error in training, and looking inside is a way to read them back out.