1id1.netAbout

The Token Space Framework

Token Space is a category-theoretic framework for AI computation. It provides a common language of records in which we can represent, compose, and transform the internal structure of computational objects, the programs that describe them, their execution states, and their observable behavior.

1. Recording the relations inside an object

Category theory traditionally characterizes an object through its morphisms to and from other objects. Working with programs, databases, and neural networks also requires us to inspect, transport, and rewrite relations inside an object. Examples include grouping and order, the roles of operands, parameter bindings, dependencies, and provenance. Token Space makes three choices:

  • Separate the data that a map can change from the symbols it keeps fixed.
  • Specify the relations of interest explicitly using finite records.
  • Define the admissible computations (morphisms) as the maps that preserve these records.

When the record sets are empty, we recover ordinary sets and functions: any function on the carriers is admissible. By choosing which records to include, we specify exactly which structural constraints a computation must respect. [1], [2]

2. Four mathematical building blocks

Fix a set of symbols EE. Write FE(B)=(B⊔E)*F_E(B) = (B \sqcup E)^* for the set of finite words (tuples) over the disjoint union of BB and EE.

  1. Base. The carrier BB is the set of objects a map acts on. Its elements might be sequences, hidden states, or nodes in a computation.
  2. Core. The set EE contains fixed symbols such as labels, operator or relation names, and protocol roles. A map acts on the disjoint union as f⊔idEf \sqcup \mathrm{id}_E.
  3. Structural Token. A single finite tuple in FE(B)F_E(B) records a particular fact. For example, (+, x, y, z) records x+y=zx + y = z, and (c_k, s, t) records that the sequences s,ts, t agree on their first kk entries.
  4. Heap. The chosen subset Υ⊆FE(B)\Upsilon \subseteq F_E(B) specifies the structure that must be preserved for the purpose at hand.

These ingredients define the category 𝖳𝖲E\mathsf{TS}_E.

  • An object, or Token class, is a triple ⟨B,E,Υ⟩\langle B, E, \Upsilon \rangle.
  • A morphism, or Token map, is a function f:B1→B2f: B_1 \to B_2 whose componentwise extension carries the source heap into the target heap: FE(f)(Υ1)⊆Υ2F_E(f)(\Upsilon_1) \subseteq \Upsilon_2. The morphism retains the entire underlying function ff, including its action on carrier elements that do not appear in Υ1\Upsilon_1. [1]

3. What “token” means in a language model and in Token Space

Section 3 of [1] distinguishes several levels that often share the name “token”:

  • A vocabulary type is an entry identified by an ID in the tokenizer’s vocabulary.
  • A token occurrence is an instance of a type at a particular input position. Two positions with the same ID give two occurrences.
  • An embedding associates a vector with a vocabulary entry. A located hidden state identifies a vector together with its model, layer, input, and position. Two such states can have identical numerical values.
  • A structural Token is a formal record of a relation among these objects. It is an element of the heap.

In a Token class describing a language model, vocabulary items or hidden states typically belong to the base. The structural Tokens record relations among them.

4. Categorical properties and algebraic tokenization

  • Categorical structure. 𝖳𝖲E\mathsf{TS}_E is a complete and cocomplete quasitopos. It is locally cartesian closed, with products and coproducts, exponential objects for higher-order maps, and dependent products for varying interfaces. Adding records while keeping the carrier fixed gives a bijective Token map that can be both monic and epic without having an inverse. This rules out a topos. Strong (equivalently, regular) monomorphisms correspond to induced substructures. [1], [8]
  • Algebraic tokenization. For a fixed finitary signature, structural Tokens with core labels encode constants, relations, and the graphs of operations. This gives fully faithful embeddings of categories of algebraic structures, partially ordered sets, graphs, and vector spaces, and even of small categories and their functors, into 𝖳𝖲E\mathsf{TS}_E. These structures can then be studied in the same framework as datasets, finite maps, and neural network layers. [1]

5. Four directions for research on computation

The papers and research projects develop this language in four connected directions.

  1. Effective representations and computational semantics. This line of work studies algebraic tokenization, regular heaps, causal dependency structures, data types and codata, and interfaces for families of maps. [1], [3]
  2. Composition and structural reuse. Monoidal constructions and Token linkages describe when modules can be composed while respecting provenance. A linkage is a span X←S→YX \leftarrow S \rightarrow Y whose witnesses connect inputs to outputs. A composition diagram can represent these connections without expanding all the witnesses explicitly. [4], [5]
  3. Reconfigurable and elastic execution. Tables, computation graphs, and modular descriptions can implement the same finite map. Treating them within one representation system makes it possible to characterize concurrent schedules and runtime state migration in terms of the frontier of completed work, gluing, and a kernel-inclusion criterion. [1]
  4. Structural observation, distillation, and neural computation. Permutation heaps characterize equivariance in Transformers, and prefix-agreement heaps characterize causality. [1], [9] A future-observation heap identifies the quotient by structural indiscernibility with the minimal reachable behavioral state space. [1], [10] These results delimit what can be preserved by structural distillation, what finite witnesses can distinguish, and where hybrid reasoning can combine structural execution with an LLM.

Papers and references

Papers by Wuming Pan

  1. Token Space: A Category Theory Framework for AI ComputationsWuming Pan · arXiv:2404.11624 · v1 first submitted · cited revision (v4) submitted · Main framework paper
  2. Categorical Studies of Token Structures: A Historical Perspective1id1 · v1 published · Historical background on relational structures and category theory
  3. Counting in Token Space: Finite Witnesses, Linear Tests and Regular Heaps1id1 · v1 and the cited v2 both published · Finite tests, witness bounds, and regular heaps
  4. Token Linkages and Tree Resynchronization: An Effective Characterization1id1 · v1 published · cited v2 published · Resynchronizing tree structures and their witnesses
  5. Monoidal Token Spaces: Initial Sources and Tensor Adjoints1id1 · v1 published · Tensor composition and right adjoints
  6. The Limits of Structural Consistency: A Token-Space Audit of LLM Counting1id1 · v1 published · Further reading on the consistency of counting answers and its limits
  7. Stochastic Token Maps: Monad Liftings, Markov Categories, Convex Algebras, and Coalgebras over Token Space1id1 · v1 published · Further reading on extending deterministic maps to stochastic maps

Related literature

  1. Exponentiability in Categories of Relational StructuresJason Parker · arXiv v1 first submitted · Theory and Applications of Categories, 2023 · Exponentiability of relational structures
  2. Attention Is All You NeedAshish Vaswani et al. · arXiv v1 first submitted · v7 revised · NeurIPS, 2017 · The Transformer and causal masking in the decoder
  3. Universal coalgebra: a theory of systemsJ. J. M. M. Rutten · Theoretical Computer Science · Journal edition published · State systems, bisimulation, and behavior