Classification over 255 classes

Other decision APIs take at most 255 options in one choice. With TypeLLM's latest hosted model, one choice takes up to 512, each with its probability and a confidence.

Time zones need more than 255. An email says "3pm my time, I'm in Saskatoon." To book the meeting you need the sender's IANA time zone, and there are 418 of them. Saskatoon is America/Regina: Saskatchewan skips daylight saving, so a coarse "Mountain" or "Central" puts the meeting an hour off for half the year.

All 418 time zones go in one choice, answered in one API call with a probability for each and a confidence.

Set up

Install the library, and tzdata for the list of time zones:

pip install "typellm>=0.6.9" tzdata

Get an API key from your dashboard:

from typellm import TypeLLMClient

client = TypeLLMClient(api_key="YOUR_API_KEY")

EMAILS is a list of 5 one-line replies; see the notebook for details.

Load the time zones

zone.tab from tzdata lists the 418 time zones in use, one per region:

from importlib.resources import files

lines = files("tzdata.zoneinfo").joinpath("zone.tab").read_text().splitlines()
ZONES = sorted(line.split("\t")[2] for line in lines if line and not line.startswith("#"))

Find each sender's time zone in one call

All 418 time zones go in one enum:

QUESTIONS = {"time_zone": {
    "type": "string", "enum": ZONES, "return_probabilities": True,
    "instructions": "Which IANA time zone is the sender in?",
}}

for email in EMAILS:
    answer = client.generate(context=f"Email: {email}", questions=QUESTIONS).result["time_zone"]
    print(f"{answer['value']:30s} {answer['confidence']:.2f}  <- {email}")
America/Sao_Paulo              1.00  <- Thursday 9am works for me. I'm in Porto Alegre this month.
America/Regina                 1.00  <- Can we do 3pm my time? I'm in Saskatoon.
Asia/Kolkata                   1.00  <- Morning works best. Our office is in Bangalore.
America/Phoenix                1.00  <- Can we do 3pm my time? I'm based in Scottsdale.
America/Indiana/Indianapolis   1.00  <- Let's talk at 10. I'm in Indiana.

Every sender lands in the time zone that sets their clock, not just the nearest big city. The notebook runs all of it with your key: open it in Colab.

← all recipes