Week 5: Imitation as Program Induction and Modular Decomposition of Demonstrations
• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning
By Scott Reed & Nando de Freitas
Neural Programmer-Interpreters (NPI) is an attempt to use neural methods to train machines to carry out simple tasks based on a small amount of training data.
• RNN is a neural network with feedback
• Hidden state is to capture history information and current state of the network

• LSTM is a special kind of RNN
• Gates are used to control information flow. Just like a valve
The NPI core is a LSTM network that learns to represent and execute programs given their execution traces

Line 3: \(𝑀^{𝑝𝑟𝑜𝑔}\) and \(𝑀^{𝑘𝑒𝑦}\) are memory banks to store program embeddings and program keys
Line 7: \((𝑀_{𝑗,}^{𝑘𝑒𝑦})^{𝑇}𝑘\) is directly measurement for cosine similarity
(1): \(𝑀^{𝑝𝑟𝑜𝑔}\) and \(𝑀^{𝑘𝑒𝑦}\) are memory storing program embeddings and program keys
(2): \(𝑓_{𝑒𝑛𝑐}\) is a domain-specific encoder (for different tasks, have different encoders)
(3): \(𝑓_{𝑒𝑛𝑑}\) is to calculate the probability of finishing the program
(4): \(𝑓_{𝑝𝑟𝑜𝑔}\) is to retrieve the next program key from memory
(5): \(𝑓_{𝑎𝑟𝑔}\) is to return the next program’s arguments
(6): \((𝑀_{𝑗,}^{𝑘𝑒𝑦})^{𝑇}𝑘\) is to measure cosine similarity
(7): \(𝑓_{env}\) is a domain-specific transition mapping
Directly maximize the probability of the correct execution trace output \(𝞷^{𝑜𝑢𝑡}\) conditioned on \(𝞷^{𝑖𝑛𝑝}\):
\[ 𝜃^∗ = 𝑎𝑟𝑔 \underset{𝜃}{max} \sum_{(𝞷^{𝑖𝑛𝑝}, 𝞷^{𝑜𝑢𝑡})} 𝑙𝑜𝑔𝑃(𝞷^{𝑜𝑢𝑡}|𝞷^{𝑖𝑛𝑝}, 𝜃) \]
Then we can just run gradient ascent to optimize it
• Addition: Teach the model the standard grade school algorithm of adding 2 base-10 numbers
• Sorting: Teach the model bubble sorting to sort an array of numbers in ascending order
• Canonicalizing 3D models: Teach the model to generate a trajectory of actions that delivers the camera to the target view, e.g, frontal pose at a 15° elevation
• Data Efficiency
• Generalization
• Learning new programs with a fixed NPI cores
• Seq2Seq LSTM and NPI used the same number of layers and hidden units.
• Trained on length up to 20 arrays of single-digit numbers.
• NPI benefits from mining multiple subprogram examples per sorting instance, and additional parameters of the program memory.
• For each length up to 20, they provided 64 example bubble sort traces, for a total of 1216 examples.
• Then, they evaluated whether the network can learn to sort arrays beyond length 20

• NPI trained on 32 examples for sequence length up to 20
• s2s-easy trained on twice as many examples as NPI (purple curve)
• s2s-stack trained on 16 times more examples than NPI (orange curve)

• NPI trained on 32 examples for sequence length up to 20
• s2s-easy trained on twice as many examples as NPI (purple curve)
• s2s-stack trained on 16 times more examples than NPI (orange curve)
• Toy example: maximum-finding in an array
• Simple (not optimal) way: call BUBBLESORT and then take the right-most element of the array. Two new programs:
• RJMP: Move all pointers to the rightmost position in the array by repeatedly calling RSHIFT program
• MAX: Call BUBBLESORT and then RJMP
• Expand program memory by adding 2 slots. Then learn by backpropagation with the NPI core and all other parameters fixed.

Only the memory slots of
the new program are updated!
All other weights are
fixed!
Protocol:
• Randomly initialize new program vectors in memory
• Freeze core and other program vectors
• Backpropagate gradients to new program vectors

• Numbers are per-sequence % accuracy
• + Max: indicates performance after addition of MAX program to memory
• “unseen” uses a test set with disjoint car models from the training set

NPI needs full execution traces. AlphaNPI only needs a specification: a hierarchy of programs, each with pre- and post-conditions
Sparse reward: 1 if the post-conditions hold when the program calls STOP, 0 otherwise
NPI becomes an actor-critic (policy \(\pi\), value \(V\)), trained as in AlphaZero: MCTS gives an improved policy \(\pi^{mcts}\), and the loss is \(-\pi^{mcts\top} \log \pi + (V - r)^2\)
Recursive MCTS: calling a learned program builds a new search tree for it
Recursive bubble sort trained on lists of length ≤ 4: 100% on length 100 with MCTS, 10% with the network alone. Tower of Hanoi trained on 2 disks: 100% on 12 disks
Learning Compositional Neural Programs with Recursive Tree Search and Planning, Pierrot et al, NeurIPS 2019. https://arxiv.org/abs/1905.12941
• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning
Danfei Xu, Suraj Nair, Yuke Zhu, Julian Gao, Animesh Garg, Li Fei-Fei, Silvio Savarese
Top-level program block_stacking is recursively decomposed to bottom-level API move_to and grip.
Learning to Generalize Across Hierarchical Tasks
Neural Task Programming combines the idea of Few-Shot Learning from Demonstration and Neural Programmer-Interpreters.
The model is trained using rich supervision from program execution traces \(\{\xi_t| \xi_t = (\Psi_t, p_t, s_t), t = 1 \ldots T\}\).
The training objective is to maximize the probability of the correct executions over all the tasks in the dataset \(D = \{(\xi_t, \xi_{t+1})\}\).
For each task specification, the ground-truth hierarchical decomposition is provided by the expert policy, which is an agent with hard-coded rules.
→ Three tasks: Object Sorting, Block Stacking, and Table Clean-up
Flat: non-hierarchical model, directly predicts the primitive APls instead of calling hierarchical programs.
GRU: Gated Recurrent Unit.
Sort plastic bowls and forks into a stack, so they can be steadily carried away.
Task variations:
• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning
Kyriacos Shiarlis, Markus Wulfmeier, Sasha Salter, Shimon Whiteson, Ingmar Posner

Complex tasks can often be broken down into simpler sub-tasks
Most Learning from Demonstration (LfD) algorithms can only learn a single policy for the whole task
Resulting in more complex policies, and also less reusable
Modelling the task as a composition of sub-tasks
Reusable sub-policies (modules) are learned for each sub-task.
Sub-policies are easier to learn and can be composed in different ways to execute new tasks.
Key approach: provide the learner with additional information about the demonstration
\[ \tau = (b_1, b_2, . . . , b_L), \]
How do we align task-sketches with the demonstration?
Main idea: Borrow temporal sequence alignment techniques from speech recognition
Input trajectory \(\rho=((s_1,a_1),...,(s_T,a_T))\)
Task sketch \(\tau = (b_1, b_2, . . . , b_L)\) indicating which sub-tasks are active in \(\rho\). Assume \(L \ll T\)
A path \(\zeta = (\zeta_1, \zeta_2, ..., \zeta_T )\) is a sequence of sub-tasks of the same length as the input sequence \(\rho\), describing the active sub-task \(\zeta_t\) at every time-step
\(Z_{T,\tau}\) is the set of all possible paths \(\zeta\) of length T, given a task sketch \(\tau\)
Eg. T = 6, \(\tau = (b_1, b_2, b_3), \zeta = (b_1, b_1, b_2, b_3, b_3, b_3)\)

Objective: Maximise the joint log likelihood of the task sketch sequence \(\tau\) and the action sequence \(\mathbf{a}_\rho\) of a training trajectory \(\rho\), conditioned on the state sequence \(\mathbf{s}_{\rho}\) of \(\rho\)
\[ p(\tau, \mathbf{a}_\rho \mid \mathbf{s}_\rho) = \sum_{\zeta \in Z_{T, \tau}} p(\zeta \mid \mathbf{s}_\rho) \prod_{t=1}^{T} \pi_{\theta_{\zeta_t}} (a_t \mid s_t) \]
\(p(ζ |\mathbf{s}_ρ)\) is the product of the stop, \(a_{STOP}\) , and nonstop, \(ā_{STOP}\), probabilities associated with any given path.
Eg. T = 4, \(\mathbf{s}_{\rho} = (s_1, s_2, s_3, s_4)\), \(\tau = (b_1, b_2), \zeta = (b_1, b_1, b_2, b_2)\)
\(p(\zeta |\mathbf{s}_{\rho}) = \pi_{\theta_{b_1}}(\bar{a}_{STOP}|s_2)\,\pi_{\theta_{b_1}}(a_{STOP}|s_3)\,\pi_{\theta_{b_2}}(\bar{a}_{STOP}|s_4)\)
No stop factor at \(s_1\), since \(\zeta_1 = \tau_1\) is fixed (Eq. 10 in the TACO paper).
Problem: Impossible to compute all paths \(\zeta\) in \(Z_{T,\tau}\) for long sequence
Solution: Dynamic Programming
The (joint) likelihood of being at sub-task \(l\) at time \(t\) can be formulated in terms of forward variables:
\[ \alpha_t(l) := \sum_{\zeta_{1:t} \in Z_{t, \tau_{1:l}}} p(\zeta \mid \mathbf{s}_\rho) \prod_{t' = 1}^{t} \pi_{\theta_{\zeta_{t'}}}(a_{t'} \mid s_{t'}) \]
\(\alpha_1(l) = \begin{cases} \pi_{\theta_{b_1}}(a_1|s_1), & \text{if } l = 1, \\ 0, & \text{otherwise}. \end{cases}\)
\(\alpha_t(l) = \pi_{\theta_{b_l}}(a_t|s_t) \left[ \alpha_{t-1}(l-1) \pi_{\theta_{b_{l-1}}}(a_{STOP}|s_t) \right.\)
\(\left. + \alpha_{t-1}(l)(1 - \pi_{\theta_{b_l}}(a_{STOP}|s_t)) \right].\)
\(\alpha_T(L) = p(\tau, \mathbf{a}_\rho|\mathbf{s}_\rho).\)

Training: Maximize \(\sum_{\rho} \log \alpha_T(L)\) over all demonstrations, w.r.t. the sub-policy parameters \(\theta=(\theta_1, ..., \theta_K)\), which define both the action policies \(\pi_{\theta_k}(a|s)\) and the stop policies \(\pi_{\theta_k}(a_{STOP}|s)\)
Setup:
Training:

Test:




Modular LfD
Weak supervision - task sketch
Optimising the sub-policies over a distribution of possible alignments
Limitation:
Future work:
Task sketches are dissimilar to natural human communication. Combination of TACO with architectures that can handle natural language.
Hierarchical task decomposition.
• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning

Goal: move green box and blue box on the goal surface
Problem: grey box is obstructing
Task plan:

Discrete action space: 3 objects x 4 operations
Continuous action space: 5 joint angles on the robot arm x T timesteps
find-grasp(b, hand)
place(b, hand, sur face)
find-traj(hand, goal)
collides(arm, b, objects)
\(b \in \{b_0, b_1, b_2 \}\)

Discrete action space: M objects x N operations
Continuous action space: 5 joint angles on the robot arm x T timesteps
find-grasp(b, hand)
place(b, hand, sur face)
find-traj(hand, goal)
collides(arm, b, objects)
pour(b, b’)
stir(b)
shake(b)
.
.
.

Discrete action space: M objects x N operations
Continuous action space: 5 joint angles on the robot arm x T timesteps
Discrete + Continuous Optimization

Expanding 1 and 2 requires solving continuous optimization problems with constraints
These plans are useful, but unfortunately discrete + continuous optimization is slow
Q: How can we learn to plan from past experience of having solved similar problems?
*Learning to Search in Task and Motion Planning with Streams, Khodeir et al, Robotics and Automation Letters. 2022
Jinbang Huang, Allen Tao, Rozilyn Marco, Miroslav Bogdanovic, Jonathan Kelly, Florian Shkurti
ICRA 2025

Given: candidate predicates \(\mathbf{P}\), e.g. (is_on ?o1 ?o2), and actions \(\mathbf{A}\), e.g. stack, cook, each with its motion planner
Find: a planning domain \(\mathbf{D}\), i.e. a subset of \(\mathbf{P}\) and \(\mathbf{A}\), plus each action’s preconditions and effects
Training: from TAMP problems of 9 basic tasks (30 demonstrations each, 2-4 objects), learn estimators that score the relevance \(u \in [0, 1]\) of every predicate and action
Testing: predict the relevance scores from the demonstration, convert the most likely domain to PDDL, then refine it by search using \(\mathbf{Q}_v\). If no domain solves \(\mathbf{Q}_v\), ask for more demonstrations

Initial and goal states as scene graphs: objects are nodes, predicates are node features and edges
Graph attention network → relevance score \(u_p, u_a \in [0, 1]\) for every predicate and action
Score of a candidate domain with predicates and actions \(\omega_\mathbf{D}\):
\[ u_\mathbf{D} = \prod_{p \in \omega_\mathbf{D}} u_p \prod_{p \notin \omega_\mathbf{D}} (1 - u_p) \prod_{a \in \omega_\mathbf{D}} u_a \prod_{a \notin \omega_\mathbf{D}} (1 - u_a) \]
The best-scoring \(\omega_\mathbf{D}^{top}\) is the initial guess. The rest are ranked by score in a priority list \(L\)

\(\omega_\mathbf{D}^{top}\) → PDDL domain \(\mathbf{D}_{top}\), using the demonstration:
Expansion: add the highest-scored element of \(L\) until the domain solves all of \(\mathbf{Q}_v\)
Contraction: try removing each element. Keep the removal if \(\mathbf{Q}_v\) is still solved
Assumes that a subdomain of an incomplete domain is incomplete, and that the optimal domain is contained in any complete domain
Each plan call queries the motion planners, which dominates the cost. A good initial guess means few calls
Unseen composed tasks, one demonstration each (success rate % vs. number of objects):
| Task | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|
| Cook and plate | 100 | 100 | 100 | 100 | 100 | 40 | 50 |
| Unpack and cook | 100 | 100 | 100 | 100 | 100 | 80 | 50 |
| Label | 100 | 100 | 100 | 100 | 100 | 100 | 100 |


• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning
• Learning programs based on execution traces (NPI - Neural Programmer Interpreters)
• Extending NPI for video-based robot imitation (NTP - Neural Task Programming)
• Inferring sub-task boundaries (TACO - Temporal Alignment for Control)
• Learning to search in Task and Motion Planning (TAMP)
• Generalization through imitation – using hierarchical policies
• Compositional generalization in diffusion planning
What Do You Need for Compositional Generalization in Diffusion Planning? Quentin Clark and Florian Shkurti. CoRL 2026. https://arxiv.org/abs/2505.18083


A ResNet CNN with:
✅ Local receptive fields
✅ Shift-equivariance

Eq-Net generates many more novel trajectories than U-Net and DiT backbones

Lower receptive field integral = more local. Models trained on more data are more local, and Eq-Net is local even with little data

Gradient of the center state w.r.t. the trajectory
Low-data regime: large receptive fields
High-data regime: small receptive fields

Eq-Net composes with much less data. U-Net and DiT only start composing once the dataset is large enough to make them local
Positional encodings remove shift-equivariance from Eq-Net, and data augmentation adds it to U-Net. Locality alone helps more than shift-equivariance alone, and both together work best

Eq-Net: through architectural inductive biases (locality and shift-equivariance)
Diffusion Policy and CompDiffuser: through action chunking and replanning