SandHouse
Pages and contents

Object Thought Learner

Introduction

This is the original version of Thought Learner 1. I have decided it best to abandon the slot framework.

Motivation

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

Z

A human thinks in terms of objects and their transitions through time. This seems to necessitate some form of object like structure within the latent space rather than representations that are purely distributed through layers of weights. Our object centric latent space will be denoted as Z. We should also form beliefs about the future, Zβˆ’.

C

A β€œconscious” thought space Cwhere the agent is able to plan and process the subconscious beliefs, object encodings, memories, etc. This is a recurrent system (possibly a state space model) that takes previous thoughts as well as present beliefs and experience to produce thoughts capable of triggering actions. I originally was going to include a β€œworking memory” component but the thought space itself should serve as a working memory. Given the current experience and belief context, it could attend to previous thoughts in the series.

M

An explicit long term memory that is queried by the thoughts. This is to be included later. It should likely persist (C,Z). M and Zshould have a mutual influence on the representation space to form a β€œwell structured” latent space. This could perhaps be done in a Hebbian fashion.

A

The action set is to be denoted π’œwhile an action at time t is Atβˆˆπ’œ.

Continuity

In order to preserve a sense of continuity between latent transitions, whether it be the thought space C, or the latent object space Z, we should implement a residual-like property among each component of the network state. Let htrepresent a state at time t. A Bayesian update would take the prior belief and adjust it by some gated value. The structural continuity equation is as follows.

ht=htβˆ’+gtβŠ™Ξ”t

The Z Space

Encoding

Given an environment state X, we encode this into dense features by some sub-quadratic attention mechanism, likely FMA or a variant thereof.

Yt=EΞΈ(Xt)

Where Yt are the dense encoded features and EΞΈis the encoding mechanism. We then form slots from these dense features through binding and priors, which will be detailed below. A slot is simply a vector that represents encoded features, meaning Ztis a set of vectors

Zt={z1,z2,...,zn}t

There are some desirable properties we would like to achieve with this set. For one, it should bind to properties of the environment X. Furthermore, it should obey structural continuity, with smooth transitions between frames rather than complete reconstructions at every step. Now we need to determine how beliefs are to influence the latent representation of Z. We must be careful to not remove all information from Zthat can not predict future states. Factors that are not useful for predicting Zitself will likely still be useful for the thought space.

Priors

Let Ztβˆ’represent the prior belief about the state of Zt.

Ztβˆ’=DZ(Ztβˆ’1,Atβˆ’1)

Where Dcan be a slot-former SlotFormer. Then Z can be written in terms of the prior

Zt=Ztβˆ’+gtZβŠ™Ξ”Z(Ztβˆ’,Yt)

Where g is a gate term detailed in a later section. 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 allows the agent to predict how objects will evolve through time. Given the posterior object state Zt and action At, the dynamics model predicts the prior object state

Zt+1|tβˆ’=DZ(Zt,At)

Which can be recursively propagated to predict multiple steps into the future.

Zt+k|tβˆ’=DZ(Zt+kβˆ’1|tβˆ’,At+kβˆ’1)

We compare these predicted states against the posterior object states obtained after actually observing the future environment.

β„’world=βˆ‘k=1Kβˆ‘i=1Nwkβ€–zt+k | t,iβˆ’βˆ’sg(zt+k,i)β€–22+Ξ»ZSIGReg(Zℬ)

Where Zℬ is a batch of encodings. For each future timestep t+k, the term

β€–zt+k|t,iβˆ’βˆ’sg(zt+k,i)β€–22

measures the prediction error for object slot i. Here zt+k|t,iβˆ’ is the predicted state of object i using information available at time t, while zt+k,i is the posterior state produced after observing the environment at t+k. The stop-gradient sg prevents this loss from directly moving the future posterior representation toward the prediction.

Finally, the outer sum βˆ‘k=1Kwk(β‹…) trains the model to predict across multiple future horizons, where wk controls the relative importance of predictions k steps into the future.

Binding and Formation of Z

We want the posterior object representation Zt to preserve continuity with the prior Ztβˆ’ while incorporating new information from the current observation. We therefore use the prior object vectors as queries into the dense visual features Yt. For each prior object zt,iβˆ’ and dense feature yt,j, we calculate a competitive binding weight

aij=softmaxi(q(zt,iβˆ’)⊀k(yt,j)d)

where the softmax is taken across objects i, causing the object slots to compete for each visual feature. We then aggregate the features assigned to each object

ct,i=βˆ‘jaijv(yt,j)βˆ‘jaij+Ο΅

where ct,i represents the sensory evidence associated with object i. We use this evidence to correct the prior representation according to the structural continuity equation

zt,i=zt,iβˆ’+gt,iZβŠ™ct,i

where gt,iZ=Οƒ(WZ[zt,iβˆ’,ct,i]+bZ) is a learned gate controlling how strongly new sensory evidence modifies the prior. Therefore zt,iβˆ’ provides temporal continuity and object identity, while ct,i introduces information from the current observation. This gives the overall transition

Ztβˆ’1β†’DZ(β‹…,Atβˆ’1)Ztβˆ’β†’Bind(β‹…,Yt)Zt

For the initial model, v(Yt)should project the visual features into the same dimensional latent space as Z. If directly adding ct,i proves too restrictive, the correction can later be generalized to a learned function Ξ”Z(zt,iβˆ’,ct,i).

zt,i=zt,iβˆ’+gZt,iβŠ™Ξ”Z(zt,iβˆ’,ct,i)

Ξ”Zcan be an MLP,

The C and A Space

The C space is where planning occurs and I attempt to try and mimic a human-like sequence of thoughts. Thoughts can produce their own reward as the C space is capable of evaluating its progress towards a goal. It maintains beliefs and refines them according to sensory evidence in a Bayesian manner. It also acts as working memory because Ct depends on previous steps in the time series in a recurrent fashion. This may be done with SSMs. The C space can be written in terms of

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

For the first simplified version, we will defer the Read(β‹…)function and instead focus on Ct=Think(Cti<t,Zt). The current thought Ctshould depend on previous thoughts in the sequence in a Mamba-like fashion. There may also be multiple thoughts per time step Ct,j, but multiple thoughts will be deferred as well.

Ct=Ctβˆ’+gtCβŠ™Ξ”C(Ctβˆ’,Ξ“t)

Where Ξ“is an attention mechanism deciding which objects in Zare relevant to the current thought and Ctβˆ’=DC(Ctβˆ’1).

Ξ±t,i=softmax(q(Ctβˆ’1)⊀k(zt,i)d)

and

Ξ“t=βˆ‘iΞ±i,tv(zt,i)

Thoughts can produce conscious actions while Ztcan produce reflexive actions.

At=πϕ(Ct,Zt)

RL Loss

The reinforcement learning loss terms are more difficult conceptually. We can use an actor-critic model to begin. Let the actor describe the actions as a policy AtβˆΌΟ€Ο•(At | Ct,Zt)with a critic VΟ†(Ct,Zt).We can define total reward as follows.

Gt(n)=βˆ‘k=0nβˆ’1Ξ³krt+k+Ξ³nsg[VΟ†(Ct+n,Zt+n)]

The advantage is

A^t=Gt(n)βˆ’VΟ†(Ct,Zt)

The RL loss is then the sum of the critic loss and the actor loss with an included entropy term to encourage environment exploration

\mathcal{L}_{\text{RL}} = \lambda_{A} \mathcal{L}_\text{actor} + \lambda_C \mathcal{L}_\text{critic} - \lambda_H \mathcal{H}(\pi) \\ \mathcal{L}_{\text{RL}} = -\lambda_A\text{sg}[\hat{A}_t] \log (\pi_\theta(A_t \ | \ C_t, Z_t)) + \frac{1}{2}\lambda_C \hat{A}^2 - \lambda_H \mathcal{H}(\pi)

Which backpropagates through all the layers.

Training

An initial training objective could be to use MiniGrid. We don’t want policy gradients to flow to E or DZ because this may cause destabilization of the slot encodings.

V2 - Things To Add

Existence Probability

We want to oversupply the number of available slots but not enforce the binding of every slot to some feature.
Rather than having a dynamic cardinality (which creates unwanted complexity), we attach each vector zan existence probability e. This changes the definition of Zt

Zt={(z1,e1),...,(zn,en)}t

Each slot zt,i has an existence probability et,i∈[0,1]. Rather than updating the probability directly, we maintain an existence logit β„“t,i such that

et,i=Οƒ(β„“t,i)

The dynamics model predicts the prior existence of each object alongside its latent state

β„“t,iβˆ’=De(ztβˆ’1,i,β„“tβˆ’1,i,Atβˆ’1)

After binding the prior slot to the current sensory features, we can measure the amount of evidence assigned to the slot as mt,i=βˆ‘jaij The posterior existence belief is then updated according to

β„“t,i=β„“t,iβˆ’+gt,ieΞ”e(β„“t,iβˆ’,ct,i,mt,i)

With et,i=Οƒ(β„“t,i) . Thus et,iβˆ’ represents whether the object is expected to exist, while the binding evidence from Yt can increase or decrease its posterior existence probability. Inactive slots should still be allowed to compete for unexplained sensory features so that new objects can activate previously unused slots.

We must also change β„’worldto be weighted by existence probability

β„’world=βˆ‘k=1Kwkβˆ‘iet+k,iβ€–zt+k | t,iβˆ’βˆ’sg(zt+k)β€–2βˆ‘iet+k,i+Ο΅+Ξ»ZSIGReg(Zℬ)

as well as adjust attention mechanisms that query Zto value objects with high existence probability more

Ξ±t,i=softmax(q(Ctβˆ’1)⊀k(zt,i)d+log⁑(et,i+Ο΅))

Mamba Think Function

Rather than using a simple gated recurrence for the thought space, we can use a Mamba-like state space model to maintain information across a sequence of thoughts. First, the current thought queries the object set Zt to extract relevant information

Ξ“t=Read(Ctβˆ’1,Zt)

We then use Ξ“t as the input to a recurrent state space model with hidden state HtC

HtC=Mamba(Htβˆ’1C,Ξ“t)

and produce the current thought from the resulting hidden state

Ct=fC(HtC,Ξ“t)

Thus HtC acts as the recurrent memory of the thought sequence, while Ct represents the current explicit thought exposed to the policy. This allows information from earlier thoughts to persist without explicitly attending over the entire previous thought sequence. The overall Think function can therefore be written as

Ct=Think(Htβˆ’1C,Ctβˆ’1,Zt)

with the transition

Ztβ†’Read(Ctβˆ’1,β‹…)Ξ“tβ†’MambaHtCβ†’fCCt

OCRL Term For Slots

OCRL introduces a loss term that ensures to prohibit overlapping attention for slots within a VAE.

β„’comp:=π”Όβˆ‘l∈[dx]βˆ‘j∈[K]βˆ‘k=j+1KAl,j(z^)Al,k(z^)

Explicit Memory

We would like to store thoughts, their associated actions, and associated rewards to query at any given moment. We can call this czar-memory because the variables spell out the word.

Mj=(Cj,Zj,Aj,Rj)

Intrinsic Reward for Thoughts

I did not describe a mechanism for thoughts to produce a reinforcement learning reward when the agent β€œthinks” it is a step closer to achieving an objective. To do this, the memory query can play a role, as well as somehow representing beliefs of achieving a goal. External reinforcement learning should always be stronger than this.

The belief portion is nice, because once the model understands language, it can interpret negative interactions through beliefs and punish them.