Open Source

coxlm

Typed questions in, calibrated probabilities out. The Python package for running Cox models.

terminal
pip install "git+https://github.com/Vitund-AI/coxlm.git"

coxlm is the package that runs Cox models. You describe your questions in Python, pass in texts, and get back a typed answer for every question: the chosen option, a calibrated confidence, and the full probability distribution.

import coxlm
from coxlm import Questions, choice, score, yesno

# Connect to a running coxlm server (no GPU or PyTorch needed on this machine)
model = coxlm.connect("http://localhost:8000")

# Or run a checkpoint on your own GPU (pip install "coxlm[local]"):
# model = coxlm.load("path/to/model.pt")


# The questions, as a class: one attribute per question
class Ticket(Questions):
    team = choice(["billing", "support", "sales"], instructions="Which team handles this?")
    urgency = score(["low", "medium", "high"], instructions="How urgent is it?")
    refund = yesno("Is the customer asking for a refund?")


# One text in, one Ticket out
ans = model.decide("My card was charged twice!!", Ticket)

# Each answer carries its probabilities, so the code can act on how sure the model is
if ans.refund.p_yes > 0.8:
    print("Refund request")
elif ans.team.confidence < 0.6:
    print("Unsure which team:", ans.team.probabilities)
else:
    print("Route to", ans.team.choice)
print("Urgency (1 = low, 3 = high):", round(ans.urgency.score, 1))

Worked examples with real output: routing tickets, matching records, rating aspects, and putting events in order.

What’s in it

  • A client with no dependencies. coxlm.connect(url) talks to a running server using only the Python standard library, so the machine asking questions needs no GPU and no PyTorch.
  • Local inference. coxlm.load(path) runs a checkpoint in your own process (pip install "coxlm[local]"). The checkpoint records how it was trained, and coxlm reads it the same way.
  • A small server. coxlm-serve answers on a native endpoint, on a System One-compatible endpoint (noul, choice and score questions), and on a demo page where you can type a text and questions and see the probabilities.
  • Putting things in order. order_items orders a set of events or steps, either by asking each item its position or by asking about every pair. The pairwise mode also returns which steps can happen at the same time and how consistent the model’s answers are. See it on an incident timeline.
  • Questions as a class. Define the questions once as a class; the answers come back as an instance of it, so editors complete the question names and type checkers catch a misspelt one. For program flow, pick() returns the top answer only when the model is sure enough, which makes “unsure” its own match case.
  • Every question answered in one pass. Ask ten questions about a text and they are answered together, each one as if it were asked alone.

Status

The package is usable today. Cox weights are not yet public; a release build trained only on data that permits commercial use is planned. Until then coxlm runs checkpoints you already have, or connects to a server that has one.