SandHouse
Pages and contents

Thought Learner 1

Introduction

Motivation

I seek to create an AI agent capable of general and efficient learning. I propose a framework of dynamics inspired by human cognition.

Z

The agent should maintain a rich latent representation of its current perception. This representation should preserve information useful for predicting future states, selecting actions, and producing higher-level thoughts. The perceptual latent space will be denoted as Z.

Rather than imposing an explicit object-centric structure on Z in the initial model, Z will consist simply of dense learned features. We should also form beliefs about future perceptual states, denoted Z−.

C

A "conscious" thought space C where the agent is able to plan and process perceptual encodings, memories, goals, and previous thoughts. This is a recurrent system, possibly a state space model, that takes previous thoughts as well as present experience to produce thoughts capable of triggering actions. I originally intended to include a separate working-memory component, but the recurrent thought space itself should be capable of serving as working memory.

Given the current perceptual context, it can retain information from previous thoughts while selectively reading from Z.

M

An explicit long-term memory that is queried by thoughts. This will be included later. It should likely persist tuples involving (C,Z,A,R) so that previous experiences can be retrieved when useful. M, C, and Z may eventually mutually influence their representation spaces so that memories remain compatible with the agent's changing internal representations.

A

The action set is denoted 𝒜 while an action at time t is At∈𝒜.

Continuity

In order to preserve a sense of continuity between latent transitions, particularly within the thought space C, we can implement a residual-like property among recurrent components of the network state. Let ht represent some internal state at time t. A general structural-continuity equation is

ht=ht−+gt⊙Δt

where ht− represents a prior or recurrent prediction, Δt represents new information, and gt determines how strongly that information modifies the existing state. This structure can be interpreted loosely as a learned belief update.

The Z Space

Encoding

Given an environment state Xt, we encode it into dense features using some efficient attention or vision architecture, likely FMA or a variant thereof.

Zt=Eθ(Xt)

where Eθ is the perceptual encoder. For an image or video frame, Zt may be represented as a collection of dense latent vectors

Zt=[zt,1,zt,2,...,zt,N]∈ℝN×d

These vectors do not initially have any required semantic interpretation. In particular, we do not require zt,i=objecti. A feature may instead represent some local visual pattern, region, texture, motion cue, object part, complete object, or more abstract property learned by the model. The purpose of Z in V1 is therefore to provide a rich perceptual representation that is

1. Useful for predicting future states,
2. Accessible to the thought process C,
3. Useful for action selection.

Explicit object discovery is deferred.

Predictive Prior

Although Zt is obtained directly from perception, the agent should also learn to predict how its latent perceptual state will evolve. Given the current latent state and action,

Zt+1 | t−=DZ(Zt,At)

where DZ is the latent dynamics model. Zt+1|t− represents the agent's prediction of the next latent state before observing Xt+1. This can be recursively propagated to predict multiple steps into the future:

Zt+k|t−=DZ(Zt+k−1|t−,At+k−1)

Thus Zt represents what is currently perceived while Zt+k|t− represents what the agent expects to perceive in the future.

Recurrence of Z

We want to use the priors of Z− and Z itself to for a recurrent relation of dense feature updates. For simpler initial experiments of interest to V1, this section is optional. But for more complex environments such as Minecraft, this is likely to be essential.

Zt=Xt+gtZ⊙ΔZ(Zt−,Xt)

Where g is a gate term that controls how much the priors influence the encodings at timestamp t.

gt,iZ=σ(WZ[zt,i−,xt,i]+bZ)

This equation means that Z0− must be initialized to something. We can sample from a learned Gaussian.

z0,i−∼𝒩(μZ,diag(σZ2))

World Model Prediction Loss

We want Zt to contain information that makes the future predictable. After observing the future environment

Zt+k=Eθ(Xt+k)

we compare the predicted latent state against the posterior representation produced from the actual observation. A simple JEPA-like objective is

ℒpred=∑k=1Kwk1N∑i=1N‖zt+k|t,i−−sg(zt+k,i)‖22

Here ‖zt+k|t,i−−sg(zt+k,i)‖22 measures the prediction error between the predicted future representation and the representation produced after actually observing the future. The stop-gradient sg(⋅) prevents the prediction target from simply moving toward the prediction. The outer sum ∑k=1Kwk(⋅) allows the model to learn predictions across multiple future horizons.

For the initial model, Zt can preserve the spatial organization produced by the encoder so that DZ predicts a future dense feature representation of the same general structure. If direct feature-to-feature prediction proves too restrictive because features move spatially through time, more sophisticated prediction, alignment, or grouping mechanisms can be introduced later.

World Model Regularization

To prevent representation collapse, we must include a loss term that regularizes the latent distribution. The VISReg loss is one that handles center, scale, and full projected distributional shape, beating performance of SIGReg and with greater flexibility.

ℒreg=λscaleD∑j=1D(1−σj(Z^ℬ))2+λshapeK∑k=1K‖sort(Z^ℬwksg(σ)+ϵ)−q𝒩‖22+λcenter∥μ∥22

Where Z^ℬ represents the centered imbedding of a replay buffer

Zℬ={Eθ,T(X1),Eθ,T(X2),...,Eθ,T(XT)},Z^ℬ=Zℬ−μℬ

sort(⋅) sorts the projected values in each dimension, and q𝒩∈ℝNrepresents the fixed quantiles of the standard Gaussian distribution. This has linear time complexity. The VISReg paper mentions that the default λ∗=1 works well for high-quality datasets, but increasing the shape loss weight improves performance on low-quality datasets.

Finally, we have the world model loss

ℒworld=ℒpred+λregℒreg

Role of Z

The initial purpose of Z is intentionally broad. We want

Xt→EθZt

to produce a representation from which both prediction and behavior can emerge. The two primary consumers of Zt are therefore Zt→DZ for world-model prediction and Zt→Ct for thought and planning. The policy may also access Zt directly so that simple behaviors do not necessarily have to pass through the entire thought process.

The C and A Space

Thought

The C space is where planning occurs and where I attempt to approximate a sequence of internal thoughts. C also acts as working memory because the current thought depends recurrently on previous thought states. The thought system should selectively read information from Zt rather than requiring the entire dense representation to be compressed into a single vector beforehand. The general form is

Ct=Think(Cti<t,Zt,Read(qt,M))

For the first simplified version, explicit memory retrieval will be deferred.

Ct=Think(Cti<t,Zt)

There may eventually be multiple internal thought steps per environment timestep, Ct,1,Ct,2,...,Ct,J, but this will also be deferred initially.

Reading From Z

The current thought should selectively query the dense perceptual representation. Given the previous thought Ct−1 and perceptual features zt,i, we calculate

αt,i=softmaxi(q(Ct−1)⊤k(zt,i)d)

The attended perceptual context is

QtC=∑iαt,iv(zt,i)

Importantly, this attention does not assume that each zt,i corresponds to an object. It allows the thought process to retrieve whichever parts of the learned perceptual representation are useful at a given moment.

Thought Transition

A simple form of the thought transition is

Ct=Ct−+gtC⊙ΔC(Ct−,QtC)

where

Ct−=DC(Ct−1)

Ct− represents the recurrent continuation of the previous thought state while QC introduces information from current perception. The gate gtC controls how strongly the new perceptual information modifies the existing thought state.

Mamba-Like Think Function

Rather than using only a simple gated recurrence, the thought space can eventually use a Mamba-like state space model to maintain information across a sequence of thoughts. First, the current thought queries Zt

QtC=Read(Ct−1,Zt)

We then update a recurrent hidden state HtC

HtC=Mamba(Ht−1C,QtC)

The explicit thought is produced from this hidden state

Ct=fC(HtC,QtC)

Thus HtC acts as the recurrent memory of the thought sequence while Ct represents the current explicit thought exposed to the policy. The overall Think function can therefore be written as

Ct=Think(Ht−1C,Ct−1,Zt)

with the transition

Zt→Read(Ct−1,⋅)QCt→MambaHtC→fCCt

For V1, a simpler gated recurrence may be preferable before introducing the full state-space implementation.

Actions

Thoughts can produce deliberate actions while Zt may also directly contribute to action selection.

At=πϕ(Ct,Qtπ)

More precisely, the actor defines a policy

At∼πϕ(At∣Ct,Qtπ)

Where the policy query Qtπqueries the dense features of Zt.

Qtπ=∑isoftmax(q(Ct)⊤k(zt,i)d)v(zt,i)

To appropriately summarize the dense information of Zt, the Qtπ mechanism should have multiple heads. Allowing the policy to observe both Ct and Zt means the architecture does not require every action to be mediated by deliberate thought, instead there can be reflexive actions that are essential for survival in the case of an environment like Minecraft. Ct may learn to contribute primarily when temporal reasoning, planning, memory, or selective attention are useful.

RL Loss

For the initial model, reinforcement learning can use a standard actor-critic setup with GAE for advantage estimation and PPO for the policy update. The critic estimates

Vφ(Ct,QtV)

where QtV is a multi-headed learned query of the dense features of the same form as Qtπ. First define the one-step temporal-difference residual

δt=rt+γVφ(Ct+1,Qt+1V)−Vφ(Ct,QtV)

Instead of a plain n-step return, we estimate the advantage using Generalized Advantage Estimation

A^tGAE=∑l=0T−t−1(γλ)lδt+l

Here, λ∈[0,1] controls the bias-variance tradeoff. We then define the value target as

R^t=A^tGAE+Vφ(Ct,QtV)

Let the policy ratio be

rt(ϕ)=πϕ(At∣Ct,Qtπ)πϕold(At∣Ct,Qtπ)

The actor is trained with the PPO clipped objective

ℒactor=−min⁡(rt(ϕ)A^tGAE,clip(rt(ϕ),1−ϵ,1+ϵ)A^tGAE).

The critic minimizes the squared value error

ℒcritic=12(Vφ(Ct,QtV)−R^t)2

We also include an entropy term ℋ(π) to encourage exploration. The total reinforcement learning loss is

ℒRL=λAℒactor+λCℒcritic−λHℋ(π)

Training

Phase 1

The first phase of training should be focused on building a baseline world model representation. We should take a diverse number of samples with a sample number depending on the complexity of the world environment. Specifically, we should collect a set of n short trajectory segments, where for episodic learning, each 𝒮 is a complete episode or a subset of an episode where Xt+k is the terminating step.

𝒮(i)=(Xt,At,Xt+1,At+1,...,At+k−1,Xt+k)i=[1,...,n]

These trajectory segments are used to train ℒworld . During this phase, each zi∈Zℬis re-encoded with the updated Eθ function at each training step. This prevents large representation divergence in the ℒreg term. If online learning is then to maintain a latent replay buffer only, this pretraining phase could have an objective of training until

ΔZrel=𝔼x|Eθt(x)−Eθt−τ(x)|2𝔼x|Eθt−τ(x)|2+ϵ<δ

Where δ∈ℝ is some some small value indicating that the representation has stabilized on the domain. This is important because for the VISReg, a large drift in sample representation during online learning would cause a poorly constructed latent replay buffer.

Since VISReg consumes some Y∈ℝB×d, and Zt is a dense set a feature vectors, we need to regularize independent Z patches across the batch.

ℒreg=1N∑i=1NVISReg⁡(Z[:,i,:]),Z[:,i,:]∈ℝB×d

When M is introduced in future models, this phase should be more intensive and include a phase 1.5 that stabilizes C before writing memories that no longer make sense in a modest number of time steps.

Phase 2

The training objective combines predictive representation learning with reinforcement learning.

ℒ=λworldℒworld+λRLℒRL

The world-model objective trains Eθ and DZto form useful predictive latent representations. The reinforcement learning objective primarily trains C,πϕ, and Vφ. For the initial model, policy gradients should not necessarily be allowed to freely modify Eθ or DZ. The RL input can instead use sg(Zt) so that the perceptual representation is primarily shaped by the predictive objective rather than potentially unstable policy gradients.

This gives the rough learning structure Xt→EθZt→DZZt+1− for predictive learning and sg(Zt)→ReadCt→πAt for reinforcement learning. This separation can be relaxed later if end-to-end RL gradients prove useful.

For phase 2, since the Z space is stable, we can store the following buffer to evaluate the loss.

𝒮t=(Zt−k,At−k,rt−k,dt−k,...,Zt,rt,dt)

Where dt∈{0,1}represents an episode termination indicator. This replay buffer shouldn’t exceed a size that causes significant drift between Zt−k and Zt. However, given a small enough δ in phase 1 and a low learning rate for ℒworld, large buffers can be achieved without concern. ℒRL should sample a smaller window from the replay buffer to account for policy drift, ideally a single episode or a subset of an episode (for large episodes).

An initial environment could be MiniGrid or another simple environment with visual observations and discrete actions. This could implement a high entropy exploration policy for phase 1 with many episodes.

V2 - Things To Add

Explicit Memory

We would eventually like to store thoughts, their associated perceptual states, actions, and rewards so that previous experiences can be queried at any given moment. We can call this czar-memory because the variables spell out the word Mj=(Cj,Zj,Aj,Rj).

A thought could form a query qt=Q(Ct,Zt) and retrieve relevant memories through Rt=Read(qt,M). The retrieved information could then become another input to the thought process.

Ct=Think(Cti<t,Zt,Rt)

Intrinsic Reward for Thoughts

I have not yet described a mechanism through which intermediate thoughts could receive reinforcement when they make progress toward an objective. Eventually, C may maintain some representation of expected goal achievement. Changes in this belief could potentially provide an intrinsic learning signal for internal thought transitions. External reinforcement learning rewards should initially remain the dominant and grounded learning signal. This mechanism should therefore be deferred until the basic perceptual world model, thought recurrence, and actor-critic loop work reliably.

Multiple Thoughts Per Environment Step

The first version uses approximately one thought update per environment transition. A later model could allow Ct,1→Ct,2→...→Ct,J before choosing an external action. This would allow the model to perform internal computation at a different temporal frequency from its interaction with the environment.

Deferred Object-Centric Structure

Original Motivation

The original architecture treated Zt as an explicitly object-centric latent space consisting of slots

Zt={zt,1,zt,2,...,zt,N}

Each slot was intended to correspond approximately to a persistent object in the environment. The motivation for this structure was that many important aspects of world modeling appear naturally relational. Objects persist through time, interact with one another, move independently, and can be individually relevant to planning. An explicit object representation would make computations of the form

objecti→future objectiorRead(Ct,{object1,...,objectN})

particularly natural. It could also provide an efficient interface between perception, prediction, thought, and explicit memory.

Original Slot Formation

The original proposal used predicted object states as queries into dense visual features. A competitive attention mechanism assigned features to slots

aij=softmaxi(q(zt,i−)⊤k(yt,j)d)

Each slot then aggregated its assigned sensory information

ct,i=∑jaijv(yt,j)∑jaij+ϵ

The prior object representation was corrected using this evidence

zt,i=zt,i−+gt,iZ⊙ΔZ(zt,i−,ct,i)

This provided a clean interpretation: Zt−1→DZZt−→BindZt. The prior maintained object identity through time while incoming visual evidence corrected the predicted state.

Why It Is Deferred

The problem is that this architecture imposes a strong assumption before it has been demonstrated to be necessary, that the world should be partitioned in discrete object slots. There may not be a single correct decomposition. For example, depending on the task, a model may benefit from representing: - an entire person, - a person's hand, - an object being held, - several objects as a group, - a spatial region, - a moving surface, - or some abstract feature spanning multiple physical objects. Requiring every latent vector to correspond to a discrete object may therefore constrain the representation unnecessarily. Fixed or oversupplied slot sets also introduce additional problems involving assignment, slot collapse, unused slots, object appearance and disappearance, occlusion, and temporal identity. These mechanisms substantially increase the complexity of V1 before determining whether explicit objects are actually required.

There is also a convincing paper “Are We Done With Object Centric Learning” by Rubenstein et. al. that explain that segmentation models have outperformed slot mechanisms. It seems that there is a general drift away from trying to force slot attention mechanisms to work and I agree with the sentiment.

Possible Future Latent Segmentation

Following the thoughts and experiments of Rubenstein et. al., explicit structure can later be introduced after learning dense representations. For example, Xt→EθZtdense→GψZtstructured.

Gψ could perform some form of learned grouping or segmentation directly in latent space. The resulting representation might take the form

Ztstructured={et,1,et,2,...,et,K}

where the et,i are persistent entities or regions without requiring that they correspond exactly to semantic objects. Possible implementations include: - latent segmentation, - learned clustering, - latent particles, - region or mask proposals, - dynamically formed entities, - hierarchical groups of dense features. This creates a weaker and potentially more useful inductive bias. The value of this additional structure can then be measured experimentally by comparing it against the dense V1 representation.

Initial Architecture Summary

The simplified V1 architecture is

Xt→EθZt,(Zt,At)→DZZt+1−
(Ct−1,Zt)→ThinkCt,(Ct,Zt)→πϕAt.

The two principal learning mechanisms are ℒworld for predictive representation learning and ℒRL for behavior. Thus the initial model tests a relatively small set of hypotheses.

1. Predictive learning can form useful dense perceptual representations.
2. A recurrent thought state can selectively read from those representations.
3. The thought state can accumulate information across time.
4. The combination of Ct and Zt can support reinforcement learning.
5. Explicit object or entity structure can be added later only if experiments demonstrate that it provides value.

Statements

Right now, Zmodels only immediate transitions abstractly. For planning to take effect, we need to form abstract representations of events of arbitrary timescales. The Z space abstracts direct sensory experience and the sequential nature of the world. There needs to be a way to form abstractions of expectations within the C space in a Bayesian manner. For example the C space should form beliefs such that if it digs a dirt hole when its nighttime, that no mobs will attack it. This is difficult, but there is likely active research other than latent hierarchies, which doesn’t quite seem like what I’m envisioning.