Python
tensorcode 0.4.0a4The 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- QuickstartStart here
- Architecture and contractsStart here
- Pretrained toolsStart here
- Tools and pretrained modelsGuides
- Evidence, interpretations and actionGuides
- Operations and providersGuides
- Pretrained vector encoders and decodersGuides