Skip to main content
#self-improvement#reinforcement-learning#memory#ntu

Self-Improving AI 25 — What survives a session, and what makes an agent explore?

NTU Part II, pages 56–60. Seven worked examples connect session memory, delegated research and goal choice to curiosity, empowerment and the rewards that drive exploration.

An inspection robot starts a new session. Asked where it found a defect yesterday, it reads the shift log and answers “shelf three.” Now leave the same log available but give no instruction. What would make the robot go back to that shelf? Keeping information and using it to choose what to do next are different capabilities.

Chapter 24 followed the hidden state as a model read a sentence. Here we pick up at the session boundary. Page 56 asks what carries over. Pages 57–59 trace who chooses a research task or a mathematical goal. Page 60 shows how to compute a reward that can change the next action. The worked examples distinguish illustrative numbers from results reported by researchers.

Worked examples Retrieving a memory · Delegating research · Weighting math goals · Curiosity on a repeat visit · Bits of empowerment · Predicting the action · Choosing the next shelf

Video guide by slide
Part II pageLecture videoQuestion to listen for
5652:22What survives in a file when a new session resets the hidden state?
5755:23Which parts of research, from choosing a question to editing a report, were delegated?
5859:07Where did “be good at math” come from?
5959:17What signal could let an agent choose where to explore next?
601:01:49How does curiosity become a reward in the earlier lecture Lee recommends?

These are spoken topic anchors. The 9:07 printed on page 60 belongs to a separate lecture recorded in 2018. NTU course schedule, May 22, 2026

#Part II, page 56 — Which memories have to be read again in a new session?

The hidden state starts again at H₀ across the session boundary. Files carry over, and the two sessions share the network weights.
Part II, page 56. Follow the hidden state and the file across the dotted line separately.Hung-yi Lee / NTU ML 2026 · Original source

Follow H₀ → H₁ → H₂ across the top row and stop at the dotted line. The first box on the other side is H₀ again. A new session resets the runtime state in this diagram. The file in the middle row crosses that boundary. If the first session writes a record, and the next session retrieves it and places it in the input, the new H₁ can depend on what happened earlier. Both sessions share the network weights at the bottom. Lee compares the weights to genes because they change most slowly in this example. Lecture at 52:22, three timescales · 53:47, bringing a file back into context

Layer on page 56What changes it?What to check in a fresh session
Hidden stateThe current input and the preceding stateWas any part of the previous conversation or state restored?
File-backed memoryA record written or edited by the agent or systemWhich record was retrieved, and did it reach the input?
Network weightsTraining or replacing a model checkpointDid both runs start from the same model version and weights?

Storage and retrieval are separate events. A sorting agent can save yesterday’s shift instructions and still miss them today if its query retrieves other documents. Conversely, the original conversation can be closed and a fresh run of the same model can still use yesterday’s record when it is supplied again. To test the effect of retrieval, use the same model and question in fresh sessions and vary access to the record.

#Worked example 1. Which of three stored memories enters the new input?

Supplementary material
A question retrieves a subset of the memory stream. The enlarged inset compares three candidates on recency, importance and relevance.
Park et al., Figure 6. Only a subset of memories reaches the language model when the agent is asked what it looks forward to. The lower panel enlarges the original score comparison.Joon Sung Park et al. / UIST 2023 · Original source

Figure 6 of Park et al.’s Generative Agents asks a simulated character, Isabella, what she is looking forward to most. The candidate memories include planning a Valentine’s Day party, ordering decorations and researching party ideas. Recency depends on time since a record was last accessed. Relevance comes from the cosine similarity between the query and record embeddings. Importance is assigned when a record is created. The implementation normalizes each component to the 0–1 range and adds the three scores with equal weights of one. Park et al., 2023, §4.1 and Figure 6

Let r, i and q denote normalized recency, importance and relevance. Substituting the numbers printed in the original figure gives the following scores.

S(m)=rm+im+qm.S(m)=r_m+i_m+q_m.
Splan=0.91+0.63+0.80=2.34,Sorder=0.87+0.63+0.71=2.21.S_{\rm plan}=0.91+0.63+0.80=2.34,\qquad S_{\rm order}=0.87+0.63+0.71=2.21.
Sideas=0.85+0.73+0.62=2.20.S_{\rm ideas}=0.85+0.73+0.62=2.20.

Suppose there is room for one record in this example. The party plan ranks first, 2.34−2.21=0.13 ahead of ordering decorations. The actual implementation takes as many of the highest-ranked records as fit in the available context. The 2.34 is a ranking score, not a probability of answering about the party. Turning off retrieval or access to this record in a fresh session leaves the file intact while cutting off that route for supplying the party information. Memory architecture, Figure 5 · Memory retrieval, Figure 6

#Part II, page 57 — Which part of the research did the agent choose?

Three robots take successive roles in choosing a question, planning and running experiments, and organizing results and editing the manuscript.
Part II, page 57. Trace the chain of delegated work back to the initial request.Hung-yi Lee / NTU ML 2026 · Original source

Start with the robot on the right. The results already exist. Its job is to organize the material and polish the manuscript. The middle robot also plans and runs the experiment. The robot on the left can find a research question within a field. Look one step farther left, at the speech bubble. It still specifies the field in which to look for questions. Lee uses this slide to separate the ability to propose a question from the motive for starting the search. Lecture at 55:23, intrinsic motivation · 55:55, three stages of research

Lecture recording
A person specifies the research field; three agents pass a question and results along. AI co-scientist and AlphaEvolve are labeled below.
Lecture recording at 57:15. The field, research question and results pass between stages. Chinese labels are translated into English.Hung-yi Lee / NTU ML 2026 · Original source

The lecturer introduces AlphaEvolve at the experiment-planning stage (56:09), then AI co-scientist at the question-finding stage (56:53). The person at the left supplies the research field. The first robot selects a specific question within it and passes that question to the next stage.

The input to the AI co-scientist project, which Lee mentions, makes that distinction concrete. A scientist supplies a research goal in natural language. The system generates hypotheses and proposals within that goal and compares candidates. Consider the assignment “Study why reflections make this inspection camera reject good parts.” An agent could decide whether to test lighting angle or exposure time first. The assignment already chose the field, camera inspection, and the objective, reducing false rejects. Lecture at 56:59 · Original AI co-scientist paper, 2025

#Worked example 2. If three of six experiments yield an accepted report, what fraction of assignments succeeded?

Consider ten independent, hypothetical runs of the camera assignment. Eight produce a testable question. Six of those complete an experiment. Of the six completed experiments, three pass a prespecified report review that checks the conclusions against the experimental record. A run that drops out does not proceed to the next stage.

StageRuns passing this stageRuns entering this stage
Propose a testable question Q810 starts
Complete an experiment E68 with accepted questions
Pass final report review R36 with completed experiments
P(Q)=810,P(E∣Q)=68,P(R∣E,Q)=36.P(Q)=\tfrac{8}{10},\qquad P(E\mid Q)=\tfrac68,\qquad P(R\mid E,Q)=\tfrac36.
P(Q∩E∩R)=810×68×36=310=0.30.P(Q\cap E\cap R)=\tfrac{8}{10}\times\tfrac68\times\tfrac36=\tfrac3{10}=0.30.

The pass rate at the last stage is 50%. The end-to-end completion rate is 30%. Multiplying the conditional fractions uses the progressively smaller denominators and requires no independence assumption between stages. These counts measure the ability to finish a sequence of tasks under a given research objective. The origin of that objective is a separate observation. A person supplied it in all ten runs.

#Part II, page 58 — How does “be good at math” become a score?

A goal H, labeled “be good at math,” sits before the evaluated agent. The empty position at left leaves the origin of that goal open.
Part II, page 58. Changing the middle goal can change the loss assigned to the same agent.Hung-yi Lee / NTU ML 2026 · Original source

The goal in the middle of the slide is labeled H. The model on the right is labeled L(Aθ,H). Here Aθ is the agent with parameters θ, H represents human-provided goals or information, and L is a loss under those conditions. A proposer can pick hard questions on its own while someone has already chosen which kinds of questions earn credit. Changing that choice can change the score for the same agent. Lecture at 59:07, the external source of the goal · 58:06, being asked to propose math problems · Definition of H in chapter 14

Lecture recording
A person supplies the goal H, “be good at math,” which leads to an agent evaluated against that goal.
Lecture recording at 59:06. The person who supplied H stands at the start of the first arrow.Hung-yi Lee / NTU ML 2026 · Original source

The preceding prompt slide at 57:39 gives examples of a person specifying a question-generating task and its output format. Both prompts appear on page 6 in Chapter 15.

#Worked example 3. Can the better math model change when the answers stay the same?

Give two models the same ten arithmetic problems and ten geometry problems. In this hypothetical scorecard, model A solves eight arithmetic and four geometry problems. Model B solves six arithmetic and eight geometry problems. Let λ be the proportion of arithmetic problems in the intended evaluation and 1−λ the proportion of geometry problems. Weighted accuracy averages the two subject scores under those proportions. Awarding a loss of one for an error and zero for a correct answer makes expected loss equal to one minus accuracy.

aA(λ)=0.8λ+0.4(1−λ)=0.4+0.4λ.a_A(\lambda)=0.8\lambda+0.4(1-\lambda)=0.4+0.4\lambda.
aB(λ)=0.6λ+0.8(1−λ)=0.8−0.2λ,Lj=1−aj.a_B(\lambda)=0.6\lambda+0.8(1-\lambda)=0.8-0.2\lambda,\qquad L_j=1-a_j.
Arithmetic proportion specified by HModel A accuracy / lossModel B accuracy / lossLower-loss model
80%0.72 / 0.280.64 / 0.36A
25%0.50 / 0.500.75 / 0.25B

We can also find the proportion at which the two scores tie. Subtract 0.4 from both sides and add 0.2λ to both sides. This leaves 0.6λ=0.4.

aA=aB ⟺ 0.4+0.4λ=0.8−0.2λ ⟺ λ=23.a_A=a_B\ \Longleftrightarrow\ 0.4+0.4\lambda=0.8-0.2\lambda\ \Longleftrightarrow\ \lambda=\tfrac23.

A ranks first when the arithmetic share exceeds two thirds. B ranks first below that point. The answers and model weights stayed fixed throughout. What changed was the evaluator’s translation of the goal into a number. This sets up the question on page 59. When nobody specifies the next arithmetic problem, what signal could guide an agent in choosing its next experience?

#Part II, page 59 — What should earn a reward when the agent chooses its next action?

A robot and speech bubble appear before the goal. Curiosity and empowerment are listed below as two criteria for exploration.
Part II, page 59. The agent now appears where the source of the goal had been left open. Its two candidate criteria can favor different actions.Hung-yi Lee / NTU ML 2026 · Original source

This time the speech bubble belongs to the robot. It chooses mathematics as its goal H and is evaluated against that goal on the right. How might it decide what to explore next? The two bullets at the bottom of the slide ask different questions. Curiosity asks how well the agent can predict what it observes. Empowerment asks how much its choice now can influence what it observes later. We can build a score for each question. Lecture at 59:17 · NTU Part II, page 59

#Worked example 4. How much curiosity reward remains the next time a robot opens a door?

Supplementary material
The inverse model infers the action from two feature vectors. The forward model uses the first vector and the action to predict the second.
Pathak et al., ICML 2017, right panel of Figure 2. The discrepancy between predicted and observed next features supplies the curiosity reward.Deepak Pathak et al. / ICML 2017 · Original source

A robot pushes a door. In Pathak et al.’s Intrinsic Curiosity Module (ICM), the frames at the bottom, sₜ and sₜ₊₁, show the scene before and after the action. The inverse model on the right uses the features of both frames to infer which action occurred. This training signal teaches the feature encoder which parts of the scene help identify the action. The forward model on the left takes the initial features and the actual action to predict the features of the next frame. The curiosity reward is proportional to the squared distance between predicted and observed next features. Pathak et al., Curiosity-driven Exploration by Self-supervised Prediction, Equations 4–6

For a hand calculation, set the observed next features to (2, 1), the first prediction to (1, 1), and the reward scale η to 0.2. Only the first feature is off, by one unit. Suppose that after more training on this situation, the model predicts (1.8, 1). The same door and action produce the same observed features on the return visit in this example.

rtICM=η2∥ϕ^t+1−ϕt+1∥22,rfirst=0.1(12+02)=0.1.r^{\rm ICM}_t=\frac{\eta}{2}\left\|\widehat{\phi}_{t+1}-\phi_{t+1}\right\|_2^2,\qquad r_{\rm first}=0.1(1^2+0^2)=0.1.
rlater=0.1(0.22+02)=0.004,rlaterrfirst=125.r_{\rm later}=0.1(0.2^2+0^2)=0.004,\qquad \frac{r_{\rm later}}{r_{\rm first}}=\frac{1}{25}.

What about a screen of random pixels? A pixel on a display next to the door takes values zero or one with equal probability, independently of the action. A predictor of the raw pixel still incurs expected squared error 0.25 when it always outputs the best prediction, 0.5. If this irreducible error earns a reward, staying near the screen can be attractive. This is the “noisy TV” problem. Features trained by ICM’s inverse task can focus on cues that the door moved. How much unrelated noise they suppress needs to be tested in the actual environment. ICM, §2.1

Random Network Distillation (RND) gives the same observed frame to two networks. One is a randomly initialized target f whose weights stay fixed. The other is a predictor trained to match its output. If the target on one image is 2 and the prediction improves from 1.5 to 1.9, the raw bonus decreases as follows. An identical image always has the same target. Noise can still supply a stream of previously unseen images. Burda et al., 2018, Exploration by Random Network Distillation, §2.2

bRND(x)=∥f^(x)−f(x)∥22,(1.5−2)2=0.25,(1.9−2)2=0.01.b_{\rm RND}(x)=\left\|\hat f(x)-f(x)\right\|_2^2,\qquad (1.5-2)^2=0.25,\qquad (1.9-2)^2=0.01.

These feature values and bonuses are illustrative. In Table 1 of the RND paper, the reported final mean score for the Atari game Montezuma’s Revenge was 8,152 points for RND and 2,497 for the PPO baseline, a difference of 5,655 game points. The table measures extrinsic game performance. The values 0.25 and 0.01 above are units of an internal exploration bonus. RND, Table 1

#Worked example 5. How many bits of control do two possible destinations provide?

Supplementary material
In a symmetric two-room system, routing error rates of 0%, 25% and 50% yield capacities of 1, approximately 0.189 and 0 bits.
Applying Mohamed and Rezende’s Equation 2 to the two-room example. The points show the worked calculation for this hypothetical channel.JJo illustration · based on Shakir Mohamed and Danilo Jimenez Rezende · Original source

At a junction s, a robot presses a left or right button A and observes its destination S′ one step later. Knowing that two rooms are possible tells us little about whether the robot can choose its destination. Mohamed and Rezende fix the starting state and action horizon, then find the distribution over actions that maximizes the information shared by the action and the destination. The maximum is empowerment. The paper also considers sequences of actions. Here we allow one press and use base-two logarithms to report bits. Mohamed and Rezende, 2015, Variational Information Maximisation for Intrinsically Motivated Reinforcement Learning, Equation 2

E(s)=max⁡p(A∣s)I(A;S′∣s),I(A;S′∣s)=H(S′∣s)−H(S′∣A,s).\mathcal E(s)=\max_{p(A\mid s)} I(A;S'\mid s),\qquad I(A;S'\mid s)=H(S'\mid s)-H(S'\mid A,s).

Here H denotes entropy, the uncertainty of a probability distribution. The first term measures how uncertain the destination is before we see the action. The second measures the uncertainty that remains once we know which button was pressed. At a symmetric junction, each button routes the robot to the opposite room with probability ε. Pressing the two buttons equally often makes the rooms equally likely and gives the first term its maximum of one bit. The second term is the same for either button, so that choice maximizes their difference.

H2(ε)=−εlog⁡2ε−(1−ε)log⁡2(1−ε),E(s)=1−H2(ε).H_2(\varepsilon)=-\varepsilon\log_2\varepsilon-(1-\varepsilon)\log_2(1-\varepsilon),\qquad \mathcal E(s)=1-H_2(\varepsilon).
What happens after a button pressUncertainty given the actionEmpowerment
The robot always reaches the indicated room0 bits1 bit
On average, one trip in four reaches the opposite roomAbout 0.811 bitsAbout 0.189 bits
A fair coin selects the room independently of the button1 bit0 bits
H2(0.25)=−0.25(−2)−0.75log⁡2(0.75)≈0.8113,1−0.8113≈0.1887.H_2(0.25)=-0.25(-2)-0.75\log_2(0.75)\approx0.8113,\qquad 1-0.8113\approx0.1887.

In the middle row, knowing that the left button was pressed helps predict the destination but leaves some doubt. In the final row the destination can vary on every trip, yet seeing it gives no clue about the button. Random outcomes can thus keep a prediction error high in a system with zero empowerment. The three points in the figure are calculated for this hypothetical junction.

What can a language model explore? Two studies first posted in 2025 appear among the slide’s references. In Navigate the Unknown, IMAGINE treats a math problem and a complete generated solution as one trajectory. It allocates the exploration bonus to solutions judged incorrect. WorldLLM instead proposes natural-language hypotheses about an environment, takes actions and uses the observed transitions as evidence to revise those hypotheses. One system explores which lines of reasoning to generate. The other explores which observations could help refine an explanation of the world. Navigate the Unknown: Enhancing LLM Reasoning with Intrinsic Motivation Guided Exploration, Equations 5–6 · WorldLLM: Improving LLMs’ world modeling using curiosity-driven theory-making, §3

#Part II, page 60 — When does a curiosity bonus change the next action?

In the ICM diagram from the 2018 lecture, features from two observations feed both a forward prediction and an inverse action prediction.
Part II, page 60. The left network predicts the next features. The right one predicts the action that was taken.Hung-yi Lee / NTU ML 2026 · Original source

Page 60 revisits the Intrinsic Curiosity Module (ICM) from Lee’s 2018 reinforcement learning lecture. The two boxes at the bottom take observations before and after an action, sₜ and sₜ₊₁. The same encoder φ produces features from both. The network on the left uses the action to predict the next features. The one on the right infers which action took place from the two sets of features. At the top, diff compares the left network’s prediction with the observed next features. Main lecture at 1:01:49 · 2018 recording at 14:20, both networks · 2018 lecture, page 7 · Pathak et al., ICML 2017

#Worked example 6. Why predict an action that has already happened?

An inspection camera can move left or right. Suppose it moved right. Its own action log supplies the label. Let p be the probability that the inverse dynamics model assigns to “right” after seeing features from both frames. Cross-entropy loss falls as the model places more probability on the correct action. Here ln denotes the natural logarithm. Pathak et al., §2.2, inverse and forward models

Linv=−ln⁡p(at=right∣ϕ(st),ϕ(st+1)).L_{\rm inv}=-\ln p(a_t=\mathrm{right}\mid\phi(s_t),\phi(s_{t+1})).

If the frames reveal which way the part shifted in the image, suppose the model assigns p=0.8. If all it can see is a flashing background that carries no action information, it can give 0.5 to each of two equally frequent actions. Compute the two illustrative losses.

−ln⁡0.8≈0.223,−ln⁡0.5≈0.693,0.693−0.223≈0.470.-\ln 0.8\approx0.223,\qquad -\ln 0.5\approx0.693,\qquad 0.693-0.223\approx0.470.

The inverse model’s training objective favors features that distinguish the actions. The 0.470 above is the difference between two inverse-model losses. The quantity supplied to the agent as an exploration bonus is the forward feature-prediction error from page 59. If a background change is consistently correlated with the action, the encoder can learn to use it. The inverse objective therefore does not guarantee that it will eliminate every distraction. Pathak et al., Figure 2 and Equations 2–3

Supplementary material
Environment rewards and intrinsic rewards computed by ICM from the same transitions appear below the time axis.
NTU DRL Lecture 7, page 5. The original slide shows where the two rewards enter the return.Hung-yi Lee / NTU DRL 2018 · Original source

On page 5 of the 2018 deck, the top row follows the agent’s interactions with the environment. The bottom row records two reward signals for the same transition. The time printed on page 60 of the main lecture, 9:07, opens the curiosity example. By 9:50 the animation shows both the environment reward and the bonus produced by the curiosity module. The recording then develops next-state prediction and prediction in feature space. 2018 recording at 9:07, introduction · 9:50, both rewards visible · 10:40, next-state prediction · Supplementary lecture, page 5

#Worked example 7. How large a bonus would favor the unfamiliar shelf?

Return to the inspection robot. It has enough time for one move. Revisiting shelf three has an expected task reward of 1 and a curiosity bonus of 0.1. Visiting a new shelf has an expected task reward of zero and a bonus of 0.6. These numbers are hypothetical. To compare the two scores, introduce an explicit weight β on the bonus. A one-decision horizon leaves no future rewards to discount.

Jknown=1+0.1β,Jnew=0+0.6β.J_{\rm known}=1+0.1\beta,\qquad J_{\rm new}=0+0.6\beta.
Jnew>Jknown  ⟺  0.5β>1  ⟺  β>2.J_{\rm new}>J_{\rm known}\iff0.5\beta>1\iff\beta>2.
Bonus weight βFamiliar shelfNew shelfHigher-scoring action
11.10.6Reinspect the familiar shelf
21.21.2Tie
31.31.8Explore the new shelf

At β=3 the new shelf scores 1.8, of which zero comes from the task reward. Report task reward, shelves visited and defects found alongside the total to see which outcome improved. The threshold of 2 depends on the units chosen for these rewards and on the one-move budget. 2018 lecture, combining environment and intrinsic rewards

The log on page 56 tells the robot where it inspected yesterday. The exploration bonus on pages 59–60 influences where it goes today. Whether the robot can read that log tomorrow and whether its choices produce more of the outcome people want are separately testable questions. Page 61 takes up the case in which the quantity an agent improves drifts away from the outcome people care about. NTU Part II, page 61

Connect