Skip to main content

How Hindsight understands dates in 16 languages: meet hs-date-1

How we trained hs-date-1, the tiny model behind recall's dates in Hindsight 1.3.1: 98.7% right on Hindsight's own tests (dateparser: 91.0%), 16 languages, about 1 ms on a CPU, and fully open source: weights, training data and training code.

By Nicolò Boschi
· 17 min read

Ask your agent "what did I decide last week?" and its memory has to know which week. Since Hindsight 1.3.1, recall reads the dates in a question with hs-date-1, a small model we trained for this job. It gets dates right far more often than dateparser, the library we used before, reads 16 languages, and knows when a question has no date. This post is about the model: what it can do, how we trained it, and why it beats a rule-based parser.

TL;DR​

  • Far more accurate. On Hindsight's own date tests, 98.7% right instead of 91.0%. On everyday English questions, 98.7% instead of 55.9%.
  • It stops inventing dates. "She may have been right" used to search May. Questions with no date now get a date by mistake 1.1% of the time in English, instead of 24.4%.
  • 16 languages, including Chinese, Japanese, Korean, Arabic, Hindi and Thai, each tested on about 3,000 questions.
  • Tiny and fast. 4.8 million weights, a 9.7 MB file, about 1 ms per question on the CPU with numpy. No GPU, no download, no LLM call.
  • Fully open source, not just open weights. The weights, the training data and the training code are public under MIT, so anyone can rebuild hs-date-1 from scratch. The model is hs-date-1, the 940k training questions are hs-date-1-data, and the code is text2date. Run pip install text2date to use it anywhere.

Why dates matter in memory​

When you recall, Hindsight searches four ways at once: by meaning, by keywords, through the graph of people and things, and by time. If the question names a time ("last week", "in March", "上个月"), Hindsight turns it into a date window and searches for memories from that window (how recall works).

So the date step has to be right:

  • A wrong date hides the right memories. If "last quarter" becomes nothing, or "the 90s" becomes today, the memories you wanted never reach the time search.
  • A made-up date adds noise. "Remind me that April is allergic to penicillin" is about a person called April, not the month.
  • No date is safe. When the question has no date, recall searches everything. That's why hs-date-1 says "no date" when it isn't sure.

What hs-date-1 can do​

It reads a question and gives back the date ranges it talks about, for the day the question was asked. Here are questions asked on Wednesday 18 November 2026, next to what dateparser gave:

Questiondateparserhs-date-1
last quarterno dateJul 1 – Sep 30
the 90sNov 18, 20261990 – 1999
in marchMar 18Mar 1 – 31
incidents from the first half of last yearall of 2025Jan 1 – Jun 30, 2025
past two weeksNov 4Nov 4 – 18
先週の会議のメモ (notes from last week's meeting)no dateNov 9 – 15
she may have been rightMay 18no date
remind me that April is allergic to penicillinApr 18no date
the Sunday Times articleNov 15no date

Beyond the everyday cases, it handles:

  • Parts of a period: "early last year" (Jan – Apr 2025), "the first half of last year", quarters, seasons. Seasons follow your hemisphere: "last summer" in Sydney is December to February.
  • Exact days inside a period: "the 3rd of last month" (Oct 3), "the week before last" (Nov 2 – 8).
  • Holidays that move: Easter, US Thanksgiving, Chinese New Year, Mid-Autumn, Dragon Boat, Ramadan and the two Eids, from 1950 to 2076. "What did we eat at Chinese New Year last year" gives Jan 29 – Feb 4, 2025.
  • Several ranges in one question: "compare May 2025 and June 2026" gives both.
  • Open ranges: "before 2020" gives everything up to Dec 31, 2019.
  • Names and products that look like dates: "remind me what June said" and "install Office 2019" give no date.

Why it beats rule-based date parsers​

dateparser, like most date libraries, is built on hand-written rules: patterns per language that turn a date string like "12 March 2024" or "2 days ago" into a date. That works for date strings. A recall question is not a date string, and rules show their limits in three ways.

1. They give a moment, not a range. "In march" is a month, but dateparser answers "March 18", today's day number in March. "Past two weeks" becomes one day, Nov 4. Recall needs the whole window.

2. They match words, not meaning. A rule sees "May", "April", "June" or "Sunday" and finds a date, wherever the word appears. A rule can't tell how sure it is, so it can't hold back when unsure. In English, it found a date in 24.4% of questions that had none.

3. Every fix is another rule. We kept a growing pile of hand-written rules on top of dateparser for the cases it missed, especially in Chinese. Every new phrasing meant another rule, in every language, and every new rule could break an old one.

Here is the full comparison on held-out questions. The dateparser numbers include our hand-written rules.

Questions with every date range exactly right
dateparser hs-date-1
English
55.9%
98.7%
Chinese
66.9%
97.7%
Chinese (traditional)
63.4%
96.9%
Spanish
50.3%
96.4%
German
48.1%
97.9%
Arabic
42.2%
94.6%
Japanese
47.0%
96.2%
Korean
46.4%
97.6%
Italian
49.9%
96.5%
Portuguese
41.4%
96.7%
French
54.2%
95.6%
Vietnamese
40.4%
95.0%
Indonesian
40.0%
95.5%
Thai
43.2%
95.6%
Hindi
46.9%
95.2%
Russian
53.3%
95.4%
Hindsight's own tests
91.0%
98.7%

About 3,000 held-out questions per language, every kind of date. The last row is Hindsight's 834 date tests, written for dateparser.

Questions with no date that got one anyway (lower is better)
dateparser hs-date-1
English
24.4%
1.1%
Chinese
3.1%
0.4%
Chinese (traditional)
1.8%
0.6%
Spanish
19.6%
0.0%
German
18.4%
0.8%
Arabic
4.3%
1.1%
Japanese
8.9%
1.6%
Korean
5.4%
1.6%
Italian
10.4%
1.0%
Portuguese
18.3%
0.7%
French
14.2%
0.9%
Vietnamese
11.3%
1.3%
Indonesian
21.9%
1.6%
Thai
10.0%
1.2%
Hindi
16.9%
1.3%
Russian
16.9%
1.0%
Hindsight's own tests
5.2%
1.5%

"She may have been right" searching May is one of these.

The last row is the strongest test for dateparser: those tests were written for it, rule by rule, over many releases. hs-date-1 was never tuned on them, and it still gets more right.

It's also faster and steadier.

Time per question, slowest 5% (p95)
dateparser
up to 57 ms
hs-date-1
1.5 ms

Bars show the slowest 5% of questions; dateparser's 57 ms is on its slowest test set. Median times: dateparser 0.1 to 16 ms depending on the test set, hs-date-1 about 1 ms on every set.

Why not just ask an LLM?​

An LLM can read dates too, but it doesn't fit inside recall:

  • Time. Recall aims to stay under 100 ms at p99, for the whole search. One LLM call takes seconds. hs-date-1 takes about 1 ms.
  • Cost. Every recall would pay for an LLM call just to find a date. For a step this small, that's a waste of money.

A small model trained for one job does it in a millisecond, on the CPU, for free.

How we trained it​

The model writes meaning, not dates​

The hard part of dates is the calendar, not the language: how many days February has, which day of the week it is, when Chinese New Year falls. So we split the job in two.

hs-date-1 writes a short meaning code. "Last week" becomes week -1. "The past 6 months" becomes last 6 month. "三天前" (three days ago) becomes day -3. "The 3rd of last month" becomes month -1 day 3. "What is my wifi password" becomes none.

Questionhs-date-1 writesPlain code turns it into
what did I decide last weekweek -1Nov 9 – 15
三天前 (three days ago)day -3Nov 15
the 3rd of last monthmonth -1 day 3Oct 3
what is my wifi passwordnoneno date

Questions asked on Wednesday 18 November 2026.

Plain Python code then turns that code into dates, for the day and time zone the question was asked in. The model never does calendar math, so the calendar math is always right, and the model only has to learn language.

The code is a small language of its own. Its whole grammar fits in a few lines:

line    := none | range (; range)*
range := period | [period] .. [period] | before period | after period
| last N unit | next N unit | fuzzy
period := [early|mid|late|h1|h2|around] base
base := now | unit N | YYYY | YYYY-MM | YYYY-MM-DD | YYYYs
| month N day D | week N weekday | sel [N] | holiday ...
unit := day | week | month | quarter | year (N = signed, 0 = this one)

Every word is one token, from a fixed list of 1,271: the grammar words, months and weekdays, numbers from -365 to 365, the years 1800 to 2199 and their decades, and the holidays. A date like 2025-05-12 is written as three tokens (year, month, day), so the model never has to spell out digits one by one.

The data: 940,000 checked questions​

We didn't collect questions and label them. We went the other way: meaning first, words second. Code picks the meaning, so every label is right by construction, and an LLM only has to write a question for it.

  1. Pick a meaning. Code draws a random meaning code and writes it out in plain English: "the week before last".
  2. An LLM writes the question. Gemma 4 writes it in one of 16 languages.
  3. Read it back. A second call reads the question cold. It's kept only if its dates match the meaning we asked for.
  4. Second opinion on "no date". When the model finds a date in a question labelled "no date", the LLM reads it again: real traps stay, wrong labels are fixed, disagreements are dropped.
  5. Clean. Anything that's in a test set is dropped, and the label conventions are applied.

Then we repeat one loop: run the model on a fresh pool of questions, keep the ones it gets wrong, and train on them.

A few details that mattered:

  • Variety on purpose. Each request mixes a language, one of 31 topics ("the dog", "bugs and incidents", "rent and the landlord"), one of 12 writing styles ("texting style with abbreviations", "the time phrase in the middle") and one of 12 personas ("a nurse working shifts", "a marathon runner"). Test sets use different prompts, personas and seeds from training, so the test is not a copy of the training style.
  • Traps get their own requests. For no-date questions, the LLM is asked to use a word that looks like a date but isn't: the verb "may", a person called April, "Office 2019", "winter tires", "the Sunday Times", a price like "$2019".
  • Templates for search-box queries. Short queries like "上个月 会议" came from templates, because LLMs write too politely.
  • Rare cases get extra weight. Days 29 to 31 of a month, "N days ago" up to 365, and years far from today each get a fixed share of the meanings. Early on, every sampler stopped at day 28, and the model got the end of the month wrong.
  • Label conventions are written down. "Last Monday" is the latest Monday before today. "Last summer" is the latest summer already started. Early, mid and late are thirds. Where Hindsight's old tests and the model disagreed, the model's convention won.

Augmentation: a new version of every question, every pass​

An LLM writes clean text. People don't. So on every pass over the data, each training question changes a little at random, and its label changes with it when needed:

How often each trick changes a training question
New numbers in question and code50% of dated"3 weeks ago" → "11 weeks ago", week -3 → week -11
At least one typo50%"yesterady"
Typo inside a month name35% of dated"febuary", "janary"
all lowercase30%"what did i do last tuesday"
Short forms30% of dated"last 3 wks", "yday"
Accents removed10%"días" → "dias"
Unrelated text around it8%a no-date sentence before or after
ALL CAPS5%"WHAT DID I DO LAST WEEK"
Two questions joined5% of datedtwo ranges in one code

Every pass over the data sees a different version of every question, at no extra LLM cost. Digits never get typos: that would change the answer.

The first one matters most. Copying numbers is the model's weakest skill, so half of the dated questions get new random numbers, in the question and in the code together: "3 weeks ago" with week -3 becomes "11 weeks ago" with week -11. That gives endless fresh practice from the same 940k rows without a single extra LLM call.

The architecture​

The model: tiny on purpose

A byte-level encoder-decoder transformer. It reads raw UTF-8 bytes, so any script works with no vocabulary per language.

e4b88ae4b8aae69c8820e4bc9ae8aeae
上个月 会议16 bytes, read as they are
2 convolutions4× shorter: 16 → 4 positions
6 encoder layers256 wide · 4 attention heads
1 decoder layerwrites the code, word by word
month -1
the meaning codethen calendar code → Oct 1 – 31
4.8M weights9.7 MB in FP16~1 ms per question1 CPU thread · numpy onlyno GPU · no LLM call

Each choice has a reason:

  • Bytes, not words. Reading raw UTF-8 bytes means one model for 16 scripts, with no word list per language and no unknown words. Thai, Hindi and Arabic need nothing extra.
  • Convolutions first. A Chinese character is 3 bytes, so the first convolution (width 5) sees whole characters and short words. The second one has a stride of 4: the sequence gets 4 times shorter, so attention has 16 times fewer scores to compute.
  • A narrow byte embedding. Bytes are embedded 64 wide, not 256: the first convolution runs on every byte, so it's the costliest step at run time.
  • Deep reader, shallow writer. 6 encoder layers read the question; 1 decoder layer writes the answer. The output is at most 24 words from a fixed list, so writing it is the easy part.
  • One word table for input and output. The decoder's word table is also its output layer, which saves about 325,000 weights.
Where the 4.83 million weights live
Encoder layers 62.1% Decoder layer 21.8% Convolutions 8.5% Word table (in and out) 6.7% Embeddings, positions, norms 0.8%

Most of the model reads the question; very little of it writes the answer. The output is at most 24 words from a fixed list, so one decoder layer is enough.

The recipe​

StepWhat happensSettings
Train from scratch20 passes over the 940k questions, about 6 hours on a laptop (an M-series Mac)AdamW (β 0.9 / 0.98, weight decay 0.01), learning rate 1e-3 with warm-up then cosine decay, batch 128, label smoothing 0.05, gradient clip 1.0
Keep the best runRuns that differ only in data order land 1 to 3 points apart, so we train 2 to 3Same settings, different data seed
Fine-tune on gaps3 rounds to fix Chinese gaps, on everything plus the new rows3 passes at 3e-4, about 1 hour each; 2 to 3 runs, keep the best or their average
PruneDrop the feed-forward units that never switch on6.4M → 4.8M weights
Pick the cut-offBelow it, the model says "no date"0.5, chosen on a tuning set
ExportFP16 weights for the numpy runtime9.7 MB

Questions are batched with others of a similar length, so little time goes into padding. The data mix gives the rare cases more weight: the LLM-written base counts once, newer rows and templates twice, and month-ends, large counts and hard examples 3 times.

A new version ships only if it is no worse on every test set, in every language, and still passes all of Hindsight's date tests.

Averaging weights only works one way. Averaging 2 to 3 fine-tunes of the same model works: they stay close together, so the average is often better than each one. Averaging runs trained from scratch does not, even when they start from the same weights: they end up far apart, and averaging three of them broke 387 of the 451 date unit tests in Hindsight's code. (Those are code tests; the 834 in the charts are the questions in Hindsight's scored test set.)

Pruning: dropping what never switches on​

Each encoder layer has 1,024 feed-forward units, which switch on (go above zero) only for some inputs. We ran 80,000 training questions through the model and recorded which units ever switched on. A unit that stayed at zero for all of them adds nothing to any answer, so we removed it.

Feed-forward units kept per encoder layer, of 1,024
Layer 1
1016
Layer 2
364
Layer 3
296
Layer 4
330
Layer 5
334
Layer 6
419

A unit that stays at zero for all 80,000 sample questions adds nothing, so we remove it. The first layer uses almost all of its units; the rest use about a third. 6.4M weights became 4.8M. An answer can only change if a question would switch a dropped unit on, so every set is scored again after pruning.

Confidence: when to say "no date"​

The model writes the code one word at a time and knows how sure it is of each word. Its confidence for a whole answer is the probability of its least sure word: one shaky word is enough to doubt the whole date.

To pick the cut-off, we tried values from 0.0 to 0.8 on a separate tuning set (never the test sets) and scored each one as:

score = exact − 3 × made-up date rate

Made-up dates count 3 times because a wrong window hides the right memories, while a missing one just searches everything. 0.5 scored best.

One rule: no hand-written rules​

Whenever the model got something wrong, the fix was more training data, never an if in the code. That's how 16 languages stay manageable: adding a language is a data job, not a code job.

We checked it isn't memorizing our tests​

After many rounds of fixes, we trained it again from scratch on the same data. It scored within 1 to 2 points of the fixed model in every language, not just on Hindsight's tests. The fixes taught it language, not our test answers.

Running it in 1 ms, with numpy alone​

Training uses PyTorch. Running it doesn't: the runtime is the same network rewritten op for op in numpy (a test checks the two give the same answers), so pip install text2date brings no torch and no GPU. A few tricks keep it fast:

  • Exact rewrites at load time. Each LayerNorm's scale and shift are folded into the matrix after it, and attention's 1/√(head size) into the query weights. Same math, fewer numpy calls: at this size, each call costs more than the arithmetic inside it.
  • Cached keys and values. The decoder adds one word per step. The question's keys and values are computed once and laid out per head, and the decoder's own are written into a preallocated buffer.
  • One math thread. numpy's math library splits every matrix product across all cores. Ours are tiny, so the split only costs time: with 6 busy processes on 6 cores, a question took about 350 ms instead of 5 ms. text2date runs its math on one thread.
  • Long text in pieces. The model reads 256 bytes at a time. Longer text is cut at sentence ends, and the dates found in each piece are combined.

How Hindsight uses it​

Nothing changes in how you call recall. On every recall, Hindsight:

  1. Reads the question with hs-date-1, on the day it was asked: your question_date if you pass one, in your own time zone, or today.
  2. Takes the first time window the question names. "Compare May 2025 and June 2026" uses May 2025.
  3. Hands that window to the time search, next to the other three.

A few rules keep it safe:

  • If the question has no date, or only one end of a range ("before 2020", "from tomorrow on"), recall searches all of time, as before.
  • If you already know the period (a date picker in your app), pass temporal_window and Hindsight skips the date step.
  • The model runs in a small helper process, so a busy server never waits on it: with 64 questions at once, the server stays responsive (under about 8 ms of delay, instead of 30 to 60 ms).

It has been on by default since 1.3.1. To switch back to dateparser:

HINDSIGHT_API_QUERY_ANALYZER=dateparser

Limits​

  • Whole days only. "Yesterday at 3pm" gives yesterday.
  • No Hindu-calendar days yet, such as Diwali or Holi.
  • Personal events ("my birthday") give no date.
  • Other languages don't crash, but they aren't trained or tested yet. Want yours? Open an issue on GitHub and we'll be happy to add it: a new language is a data job, not a code change.

Try it​

Use it on its own, in any Python project:

pip install text2date
from datetime import date
import text2date

text2date.parse("what did I decide last week", anchor=date(2026, 11, 20))
# [DateRange(start=date(2026, 11, 9), end=date(2026, 11, 15))]

text2date.parse("上个月的会议", anchor=date(2026, 11, 20), tz="Asia/Shanghai")
# [DateRange(start=date(2026, 10, 1), end=date(2026, 10, 31))]

text2date.parse("what is my wifi password")
# []

From an asyncio app, text2date.ProcessParser gives the same answers from a helper process, with aparse().

The code is on GitHub, the model on Hugging Face, and the training data on Hugging Face, all under MIT. It's open source end to end, not just open weights: the repo has the scripts that generate the data, train, prune and score the model, and TRAINING.md walks through the full recipe, so you can train your own or fix a gap. If it gets a question wrong, open an issue with the question: that becomes training data for the next version.