·project

TensorCode

A framework for encoding and decoding arbitrary Python objects, differentiable programming, and runtime code generation — Programming 2.0 with the abstractions software engineers already know.

presentation slides
TensorCode title slide with the github.com/limboid/tensorcode link
Capabilities: encode and decode arbitrary objects, develop and evolve multi-modal models, runtime code generation, differentiable programming, develop cognitive architectures
Reinforcement-learning loop diagram: an agent and a world exchanging action and observation
Hand-written step() function manually encoding inputs, deciding, and decoding the action tensor back to Python objects
Arbitrary object encoding and decoding with tc.encode and tc.decode
The fully hand-written step() function shown in full
The same step() function rewritten compactly with tc.encode and tc.decode
TensorCode step() alongside the Observation and Action class definitions it is inferred from
The same step() unchanged while Observation and Action grow extra typed fields
Observation and Action using a Union of Literals to type the direction field
Action using a tuple of direction literals, still decoded by the unchanged step()
How tc.encode turns an Observation object into query and key-value tensor pairs
Tensor-shape walkthrough showing how encoded objects batch across vision, text, and energy inputs
Runtime Code Generation: tc.exec, tc.select, tc.create, and tc.patterns.Factory examples
Differentiable Programming: @tc.If / .Elif / .Else decorators making control flow differentiable
Cognitive Architecture Development diagram: multi-modal fusion, memory, prediction, action, and training loss terms
Cognitive-architecture step() function, full listing
Cognitive-architecture step() highlighting the recurrent input and memory reads
Cognitive-architecture step() highlighting the global-workspace perception state
Cognitive-architecture step() highlighting the prediction stage
Cognitive-architecture step() highlighting the output and memory writes
Cognitive-architecture step() highlighting the training feedback and loss terms
Cognitive-architecture step() with the return statement highlighted
Closing capabilities slide with the github.com/limboid/tensorcode link

Problem

Building a multi-modal model means writing the same plumbing over and over: pick an encoder per input type, concatenate latents, run a decision network, then hand-decode the output tensor back into the Python objects the rest of your program expects. Every time the Observation or Action shape changes, that glue code changes with it. You end up thinking in tensors when you'd rather be thinking in objects, patterns, and architecture.

Solution

TensorCode introduces simple abstractions and functions for encoding and decoding arbitrary Python objects, differentiable programming (including differentiable control flow), and intelligent object creation, selection, and other runtime code-generation features.

Rather than just think about the underlying mathematical objects, TensorCode's Programming 2.0 paradigm gives your brain the abstractions it needs to apply ordinary software-engineering patterns — encapsulation, abstraction, composition, design patterns, and the concepts derived from them — to your underlying problem. If you're developing a multi-modal agent, building the next generation of end-to-end differentiable cognitive architectures, or just adding magic to an existing program, TensorCode may fit right into your stack.

import tensorcode as tc

def step(self, obs: Observation) -> Action:
    latent = tc.encode(obs)
    action = self.mlp(latent)
    return tc.decode(action, Action)

tc.encode turns any annotated object into a latent tensor; tc.decode turns a tensor back into a typed object. When the Observation or Action definition grows a new field, the encode and decode calls don't change — TensorCode infers the wiring from the type annotations.

How

The framework centers on a few primitives:

  • tc.encode / tc.decode — bidirectional conversion between arbitrary Python objects and tensors, driven by type annotations (Image, str, float, Union, Literal, tuples, nested classes).
  • Runtime code generationtc.exec, tc.select, tc.create, and tc.patterns.Factory let a program describe what it wants in natural language and have TensorCode produce, choose, or run the object at runtime.
  • Differentiable programmingtc.If / .Elif / .Else decorators make control flow differentiable, so gradients flow through branches the same way they flow through arithmetic.
  • Cognitive-architecture building blocks — multi-modal fusion, short- and long-term memory, a global-workspace prediction loop, and composable loss terms for training the whole thing end to end.

Presentation

The deck below walks from a hand-wired RL agent to the same agent expressed with TensorCode primitives, then through runtime code generation, differentiable control flow, and a full differentiable cognitive architecture. The full deck is also available as a downloadable PDF.

Status

TensorCode is an active, exploratory framework. The GitHub repository holds the current implementation. The project notebook tracks design notes. Encoding/decoding and runtime code generation are the furthest along; differentiable control flow and reinforcement programming are still in progress.

Lessons

The recurring lesson is that the bottleneck in multi-modal ML isn't the math — it's the abstractions. Giving the encode/decode boundary a name, and letting type annotations carry the wiring, is what makes the software-engineering toolkit (composition, design patterns, encapsulation) usable on a learning system at all.

Neighborhood

Related

notion-vibestartupnotion-vibestartupRecursive Omnimodal Video Action ModelRecursive Omnimodal Vid...ComputatrumComputatrumyt2ctxyt2ctxThe Multi-Agent Network (MAN)The Multi-Agent Network...MPNetsMPNetsFull-Stack Artificial IntelligenceFull-Stack Artificial I...jnumpyjnumpyFull Stack Artificial IntelligenceFull Stack Artificial Intel...The Tensor ComputerThe Tensor ComputerDifferentiable Tensor Computers for End-to-End Program SynthesisDifferentiable Tensor Compu...TensorCode