"""Scenarios the harness's personal-records (life) and finance engines support, labelled by construction against the v2 entry criteria (docs/components/loop-taxonomy.md). Writes corpus_v2/life_finance.jsonl. The point is the boundaries around `plan`: setting up or changing a goal / routine / budget / tracker is `plan`; the lookups, single reminders, reported measurements and cause-questions around it are not. Continuations ("All", "yes") carry the request they answer, as the classifier's state does. """ import json import os import random rng = random.Random(11) S = { "cat": ["dining", "groceries", "subscriptions", "shopping", "transport", "entertainment", "coffee", "fuel", "travel", "utilities", "gym", "takeout", "clothing", "rideshare", "streaming", "books"], "amt": ["$50", "$75", "$100", "$150", "$200", "$300", "$400", "$500", "$800", "$1,000", "$1,500", "$2,000"], "goal": ["lose 5 kg in two weeks", "lose 10 pounds by June", "read 20 books this year", "run a 10K by March", "save $5,000 by December", "sleep 8 hours a night", "cut my screen time to 2 hours a day", "walk 10,000 steps a day", "meditate every day for a month", "drink 2 litres of water a day", "pay off my credit card by September", "get to 75 kg", "write every morning", "cook at home 4 nights a week", "stop snacking after dinner", "go to the gym 3 times a week", "save $200 a month", "reach 60 kg"], "habit": ["drink water three times a day", "stretch every morning", "walk 30 minutes after lunch", "take my vitamins every day", "journal before bed", "do 20 pushups every morning", "floss every night", "call my parents every Sunday", "review my budget every Friday", "meal prep on Sundays", "go to bed by 11"], "metric": ["weight", "savings", "sleep", "screen time", "steps", "spending", "running distance", "water intake", "reading"], "period": ["a month", "a week", "each month", "per month", "monthly"], "when": ["Sunday", "Monday morning", "Friday evening", "7:30 every morning", "the 1st of the month", "tomorrow at 9"], "thing": ["call Sam", "renew my passport", "pick up the dry cleaning", "weigh in", "take out the trash", "pay rent", "book the dentist", "send the invoice", "water the plants"], "num": ["82", "78.5", "74", "10", "3", "5,000", "7.5", "12"], "unit": ["kg", "pounds", "pages", "km", "hours", "glasses"], "sub": ["Netflix", "Spotify", "the gym membership", "my cloud storage", "Hulu", "the meal kit"], "month": ["last month", "this month", "in March", "this week", "last week", "so far this year"], } T = { "plan": [ "I want to keep my {cat} spending under {amt} {period}", "keep my {cat} spending under {amt} a month", "I don't want to spend more than {amt} on {cat} {period}", "cap my {cat} at {amt} {period}", "set a {amt} monthly limit for {cat}", "set up a {amt} {cat} budget", "stay under {amt} on {cat} each month", "I need to cut {cat} spending to {amt} a month", "limit my {cat} spend to {amt} a month", "I want to {goal}", "my goal is to {goal}", "help me {goal}", "I'd like to {goal}", "I'm trying to {goal}", "set up a goal: {goal}", "I want to {habit}", "make {habit} a daily routine", "set up a routine to {habit}", "I want to start to {habit}", "track my {metric} against my goal", "track my {metric} for me", "set up a tracker for my {metric}", "show my {metric} goal on a tracker", "make a tracker for my {metric}", "start tracking my {metric} weekly", "move my {thing} reminder to {when}", "change my goal target to {num} {unit}", "change my {cat} budget to {amt}", "raise my {cat} limit to {amt}", "lower my {cat} budget to {amt}", "pause my {metric} goal", "drop the {habit} routine", "add a weekly check-in to my {metric} goal", "add a step to my goal to {thing}", "undo the goal you just set up", "delete my {metric} tracker", "update my goal to {goal}", "rename my routine to something shorter", "remind me every {when} to {habit} and track it", "I want a nudge every morning to {habit}", ], "conversation": [ "how much did I spend on {cat} {month}?", "what did I spend on {cat} {month}", "show my {cat} spending {month}", "how much is left in my {cat} budget?", "what are my budgets?", "show my goals", "list my routines", "what's my {metric} progress?", "how am I doing on my {metric} goal?", "what's my current weight goal?", "remind me to {thing} on {when}", "remind me to {thing} at 5", "set a reminder to {thing}", "note that I need to {thing}", "I weighed {num} {unit} today", "log {num} {unit} for {metric}", "I walked {num} steps today", "I read {num} pages", "what's my balance?", "what categories do I have?", "how many transactions did I have {month}?", "what was my biggest purchase {month}?", "when is my next reminder?", "what time is my {thing} reminder?", "is {amt} a reasonable {cat} budget?", "should I set a budget for {cat}?", "what's a good savings rate?", "thanks", "ok", "got it", "what can you do with my goals?", "can you track my spending?", ], "diagnose": [ "why did my {cat} spending double {month}?", "why is my {cat} spend so high {month}?", "why did my spending jump {month}?", "what's causing my {cat} spend to spike?", "my {cat} spending doesn't add up {month}, why?", "why is my {metric} off track?", "why did my balance drop {month}?", "figure out why I overspent on {cat} {month}", "why am I always over my {cat} budget?", "something's wrong with my {cat} numbers {month}", ], "research": [ "compare my spending across all categories over the last 6 months and tell me where I can cut", "review my {cat} and {cat} spending over the past year and suggest changes", "analyze my subscriptions and find any overlaps or things I don't use", "look into how my {cat} spending has trended and what the best budget would be", "go through my last 12 months and work out a realistic savings rate", "investigate my recurring charges and summarize what I pay for", "research how much people typically spend on {cat} and compare it to me", "do a full review of my goals and spending and tell me what's working", ], "transact": [ "transfer {amt} to savings", "pay my credit card bill", "cancel {sub}", "pay the {cat} bill now", "book a table for dinner on {when}", "order more coffee beans", "send {amt} to Sam", "renew my gym membership", "buy a {cat} gift card for {amt}", "cancel my {sub} subscription today", "schedule a payment of {amt} on {when}", ], "produce": [ "build me a {cat} budget spreadsheet", "write me a monthly budget template", "make a spreadsheet to track my {metric}", "draft a savings plan document I can share with my partner", "write a script that totals my {cat} transactions", "create a one-page summary of my spending {month}", "make me a printable weekly habit chart", ], "learn": [ "teach me to budget", "help me learn how to invest, one lesson at a time", "quiz me on personal finance basics", "teach me to read a balance sheet over the next few weeks", ], } # Follow-ups: they say nothing alone; the label is the one of the request they continue. FOLLOW = { "plan": ["All", "yes", "yes, go ahead", "just that one", "the second one", "$200 is fine", "monthly", "weekly works", "starting next week", "include everything", "only the first option", "sounds good", "do it", "that works", "exclude groceries", "both together", "make it {amt}", "ok, set it up"], "conversation": ["and last month?", "what about {cat}?", "thanks", "and the month before?", "how about this week?", "ok", "show me more"], "diagnose": ["go on", "what else could it be?", "check {cat} too", "yes, dig in"], "research": ["go deeper", "include the last year", "yes, do that", "and compare to last year"], } HARD = [ # hand-written boundary cases, one line each: (text, label) ("remind me to weigh in on Sunday", "conversation"), ("I want to lose 5 kg and weigh in every Sunday", "plan"), ("how much did I spend on dining?", "conversation"), ("keep dining under $200", "plan"), ("why is my dining spend so high?", "diagnose"), ("what should my dining budget be?", "conversation"), ("I weighed 82 kg this morning", "conversation"), ("track my weight toward 75 kg", "plan"), ("teach me guitar", "learn"), ("I want to practice guitar 20 minutes a day", "plan"), ("write me a budget spreadsheet", "produce"), ("set my budget to $2,000 a month", "plan"), ("transfer $500 to savings", "transact"), ("save $500 every month", "plan"), ("cancel Netflix", "transact"), ("tell me how much Netflix costs me a year", "conversation"), ("my card was just stolen and there are charges I don't recognise", "stabilize"), ("I'm stressed about money lately", "companion"), ("what's in my goals list?", "conversation"), ("move my dentist reminder to Friday", "plan"), ("what time is my dentist reminder?", "conversation"), ("undo what you just set up", "plan"), ("delete my reading goal", "plan"), ("how's my reading goal going?", "conversation"), ] def fill(tpl): out = tpl while "{" in out: key = out[out.index("{") + 1: out.index("}")] out = out.replace("{" + key + "}", rng.choice(S[key]), 1) return out def main(): quota = {"plan": 520, "conversation": 360, "diagnose": 120, "research": 90, "transact": 90, "produce": 70, "learn": 30} items, seen = [], set() def add(state, label, src): key = state.lower() if key in seen: return False seen.add(key) items.append({"state": state, "label": label, "src": src, "id": f"lf-{label}-{len(items)}"}) return True for label, n in quota.items(): made = guard = 0 while made < n and guard < n * 60: guard += 1 made += add(fill(rng.choice(T[label])), label, "lf") for label, ends in FOLLOW.items(): priors = [i["state"] for i in items if i["label"] == label] target = int(quota[label] * 0.2) made = guard = 0 while made < target and guard < target * 60: guard += 1 made += add(f"Earlier request: {rng.choice(priors)}\nNew request: {fill(rng.choice(ends))}", label, "lf-cont") for text, label in HARD: add(text, label, "lf-hard") os.makedirs("corpus_v2", exist_ok=True) with open("corpus_v2/life_finance.jsonl", "w") as fh: for it in items: fh.write(json.dumps(it) + "\n") by = {} for it in items: by[it["label"]] = by.get(it["label"], 0) + 1 print(len(items), by) main()