TensorCode Docs

tensorcode / developer documentation

Trainable tools with sourced evidence and owned weights.

TensorCode composes callable operations (ops.vec, ops.text, ops.graph) into tools that own their encoders, workspace and decoders. Tools create sessions that keep source evidence, generated hypotheses, model assessments and observed outcomes separate, and emit receipts you can audit.

Reviewed targets and action outcomes become data-only experience; a Trainer fits the tool from it; save_pretrained / from_pretrained restore exact configuration and weights, offline or from the Hugging Face Hub. Importing the core package loads no ML framework and makes no network calls.

InstallArchitecture overview

Pick an implementation

Both implement the same public contracts: operations, tools, sessions, tracing, experience and artifacts. The Python package is the reference. The TypeScript port matches it and reads and writes the same files, so a model trained in one language loads in the other. What differs.

Python

tensorcode 0.4.0a4

The reference implementation, on PyTorch. Python 3.11 or newer; install from PyPI with pip.

python -m pip install 'tensorcode[tools]'
import torch
from tensorcode import training
from tensorcode.tools.investigator import Investigator

torch.manual_seed(0)
model = Investigator({"vocabulary": ["database", "network", "connection", "refused", "packet", "loss"],
                      "dimensions": 16, "slots": 2, "steps": 1})
trainer = training.Trainer.from_tool(model, optimizer=torch.optim.AdamW(model.parameters(), lr=0.01))

hypotheses = [{"id": "database", "text": "database connection refused"},
              {"id": "network", "text": "network packet loss"}]

def case(log_line):
    return {"question": "which component failed",
            "evidence": [{"source_id": "log:1", "text": log_line}],
            "hypotheses": hypotheses}

# Reviewed feedback, with explicit provenance, becomes training experience.
experiences = [trainer.capture(case("connection refused"), "database", source="review:1"),
               trainer.capture(case("packet loss"), "network", source="review:2")]
losses = trainer.fit(experiences, epochs=30)

model.save_pretrained("./investigator")
restored = Investigator.from_pretrained("./investigator")
print(restored(case("packet loss"))["selected_id"])  # network
All Python docs →

TypeScript

tensorcode 0.4.0-alpha.5

The port for Node.js 20.16 or newer, with its own autograd core and no runtime dependencies; install from npm.

npm install tensorcode
import { AdamW, manualSeed } from 'tensorcode/nn';
import { Investigator } from 'tensorcode/tools';
import { Trainer } from 'tensorcode/training';

manualSeed(0);
const model = new Investigator({
  vocabulary: ['database', 'network', 'connection', 'refused', 'packet', 'loss'],
  dimensions: 16, slots: 2, steps: 1,
});
const trainer = Trainer.fromTool(model, { optimizer: (params) => new AdamW(params, { lr: 0.01 }) });

const hypotheses = [
  { id: 'database', text: 'database connection refused' },
  { id: 'network', text: 'network packet loss' },
];
const incident = (logLine: string) => ({
  question: 'which component failed',
  evidence: [{ source_id: 'log:1', text: logLine }],
  hypotheses,
});

// Reviewed feedback, with explicit provenance, becomes training experience.
const experiences = [
  trainer.capture(incident('connection refused'), 'database', { source: 'review:1' }),
  trainer.capture(incident('packet loss'), 'network', { source: 'review:2' }),
];
const losses = trainer.fit(experiences, { epochs: 30 });

await model.savePretrained('./investigator');
const restored = await Investigator.fromPretrained('./investigator');
console.log(restored.call(incident('packet loss')).selected_id); // network
All TypeScript docs →

How the pieces fit

Operations are the callable units. Tools compose them and own every parameter. Sessions are runtime state, never saved into model weights. Experience is the only path from runtime back into training.

TensorCode architecture Operations (vec, text, graph) are composed into tools (Chatbot, Investigator, Planner, Decision, Scene). A tool owns its model parameters and creates sessions that hold sourced evidence, revisions and memory. Sessions emit receipts and experience records; the trainer fits the tool's parameters from experience; artifacts are saved with save_pretrained and restored with from_pretrained, locally or from the Hugging Face Hub. OPERATIONS ops.vecencode, decode, classify, retrieve ops.textmessages, classify, decide, retrieve ops.graphsymbolic interfaces (stubs) TOOLS ChatbotInvestigatorPlannerDecisionScene own encoders, workspace, decodersconfigured from JSON RUNTIME Sessionssourced evidenceimmutable revisionsepisodic memory Receiptscandidates + sourcessupport / contradictionabstentions PERSISTENCE Artifactssave_pretrainedfrom_pretrainedlocal or HF Hub Experiencereviewed targetsaction outcomessource provenance from_pretrained restores exact weights and configuration training.Trainer.from_tool(model)capture → save experience → fit → checkpoint updates parameters

Core concepts

The vocabulary the guides use.

Operation
A callable operation(value, *, context=None). Learned operations take JSON configuration and own their weights; weightless ones are pure transforms.
Tool
An owned model (Chatbot, Investigator, Planner, Decision, Scene) with public interaction contracts. Constructing one initializes weights and downloads nothing.
Evidence
Source-identified observations. Generated hypotheses are interpretations, never evidence; revisions keep what a source originally said.
Receipt
Per-candidate support / contradiction / unknown assessments per source, with provenance, truncation and abstention status.
Experience
Data-only training records: inputs, reviewed targets or observed outcomes, and who supplied them.
Artifact
tensorcode_config.json + model.safetensors + model card. Loading rejects incompatible artifacts instead of executing code.

Status and measured scope

Alpha. The APIs are pre-1.0 and change between releases. Published checkpoints are small, fixed-split experiments, and they do not yet establish a consistent benefit from the recurrent workspace or general cognitive competence. Model probabilities are uncalibrated and verifier approval is not truth. Read validation and scope before choosing a model.