Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

TensorCode

Website: tensorcode.dev · Docs: tensorcode.dev/docs · Source: GitHub · Changelog

TensorCode builds trainable Python programs from callable operations and small tools that own their models. You compose encoders, scorers and decoders (tensorcode.ops), or use a complete tool such as Investigator, Planner or Chatbot (tensorcode.tools). You collect reviewed feedback with explicit provenance, train with PyTorch, and save everything as a data-only artifact that reloads in a fresh process or from the Hugging Face Hub. Tracing records which operation produced which value, so supervised local tensor paths can be replayed and trained. It does not make arbitrary Python or remote model calls differentiable.

Status: 0.4.0 alpha. APIs may change between alphas. The core package has no dependencies and importing it does not import PyTorch or touch the network. Measured behavior and its limits are in validation. Consistent benefits of the learned cognitive workspace are not yet established.

Install

Python 3.11+:

python -m pip install 'tensorcode[tools]'

From a checkout, use python -m pip install -e '.[tools]'. Choose the extras for the interfaces you use:

Extra Adds
tools Owned models, training and Hugging Face loading (PyTorch, Transformers)
vec Vector operations only (PyTorch, NumPy, safetensors)
local Adapter for a local multimodal Transformers model
diffusion tools plus diffusers for image decoders
pretrained Alias of tools
dev pytest, build, Pillow and PyArrow; the full test suite also needs diffusion

30-second example

This trains an Investigator to rank two supplied hypotheses from log evidence. It saves the model and reloads it. It runs offline on CPU in a few seconds.

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

Two authored cases show the lifecycle. They do not show that the model can investigate anything. The result also includes every candidate's score and the source-linked evidence. Probabilities are uncalibrated. The quickstart extends this to persisted experience files, resumable training checkpoints and loading in a fresh process.

What is inside

  • tensorcode.ops.vec, ops.text, ops.graph: operations with one calling convention, op(value, *, context=None). Operations are built from JSON configuration, and learned vector operations own their weights. Text operations wrap an owned seq2seq model or an explicit external provider. Graph operations are reserved symbolic interfaces that raise NotImplementedError.
  • tensorcode.tools: Chatbot, Investigator, Decision, Planner and Scene, complete trainable models with save_pretrained / from_pretrained.
  • tensorcode.trace() and tensorcode.training: dependency capture, explicit supervision, Trainer.from_tool / Trainer.from_ops, portable experience and complete checkpoints.
  • tensorcode.integrations: explicit adapters for OpenAI-compatible endpoints, local Transformers models and Jev.

Generated hypotheses are not evidence, and generated plans are not executable code. Evidence, policies and actions stay explicit in your code.

Guides

  • Quickstart: a runnable offline training lifecycle.
  • Developer documentation: operation and model contracts.
  • Pretrained checkpoints: hosted tools and their measured scope. Saved artifacts must match the current architecture exactly: the hosted Chatbot and cognitive Investigator checkpoints need source commit 6607a8b; only the Hotpot Investigator and Decision have refreshed revisions verified on current source.
  • Evidence and cognition: hypotheses, revisions, memory and outcome feedback.
  • Training: tracing, replay and resumable checkpoints.
  • Examples: learning agents and practical applications.
  • Validation: measured behavior and limitations.
  • Updating development code: import changes since earlier alphas.

Development

python -m pip install -e '.[tools,diffusion,dev]'
python -m pytest -q
python -m build

Library code lives in src/tensorcode. See the test guide for how the suite is organized. This alpha API replaces the former provider-owned tools, and there is no legacy compatibility layer. MIT license.

Release files for tensorcode 0.4.0a4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tensorcode 0.4.0a4
File Size Uploaded
tensorcode-0.4.0a4.tar.gz 1.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for tensorcode 0.4.0a4
File Interpreter ABI Platform
tensorcode-0.4.0a4-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / tensorcode-0.4.0a4.tar.gz

Download URL tensorcode-0.4.0a4.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
c49921d5bd6373d22112af706ec8397995f2958a86c707100a22801c35247367
BLAKE2b-256 checksum
How to use checksums
0125a2cab4d306f0a064a548f76e3845aacba3c8d9334f43ea2336b3f62b4f1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / tensorcode-0.4.0a4-py3-none-any.whl

Download URL tensorcode-0.4.0a4-py3-none-any.whl
Size 190.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4adc54710ed3297a84daad13aba4b0d19083e5f7872aec112ab695e6d061080
BLAKE2b-256 checksum
How to use checksums
cf37132ffdde5e5554f19fe64f37daaa1b5c5abf8e68ad0b894cf893f4d44aea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page