// Development set: 25 synthetic document pairs (5 types x 5) with planted changes. // Used to build and tune the engine. Fixed seed. All people, companies and places are fictional // (city names are real places but nothing else is). E-mail domains use the reserved .example TLD. // Run: node eval/gen_dev.mjs -> eval/dev.json // Built by Suman Mukherjee. Apache-2.0. import { writeFileSync } from "node:fs"; import { makeRng, inr, intl, words, rupeeWords, wordsDigits, fmtDate, date, addDays, addMonths, render, hardWrap, clone, ordinal } from "./genlib.mjs"; const SEED = 20261114; const FIRST = ["Meera", "Rohan", "Ishaan", "Kavya", "Arjun", "Tanvi", "Nikhil", "Aditi", "Varun", "Sana", "Kabir", "Ritika", "Dhruv", "Anaya", "Yash", "Pooja"]; const LAST = ["Valtekar", "Isharwal", "Korambe", "Dhanvari", "Mirchandel", "Pathrikar", "Sohanpal", "Venkatraju", "Ambrekar", "Tuliyani", "Chandrakar", "Bhosalkar"]; const CITIES = ["Pune", "Nagpur", "Indore", "Kochi", "Mysuru", "Nashik", "Jaipur", "Bhopal", "Coimbatore", "Vadodara"]; const BUILDINGS = ["Tamarind Court", "Juniper Heights", "Silver Oak Residency", "Lotus Enclave", "Banyan Towers", "Neem Vihar"]; const person = (r) => `${r.pick(FIRST)} ${r.pick(LAST)}`; const honor = (r) => r.pick(["Mr.", "Ms.", "Mrs."]); function rupees(n, f) { if (f === "rs") return `Rs. ${inr(n)}`; if (f === "inr") return `INR ${inr(n)}`; return `₹${inr(n)}`; } /* ---------------- D1: rent agreement ---------------- */ function rent(r, id) { const cf = r.pick(["sym", "rs"]); const ds = r.pick(["dmy/", "dmy-"]); const city = r.pick(CITIES); const v0 = { land: `${r.pick(["Mrs.", "Mr."])} ${person(r)}`, ten: `${honor(r)} ${person(r)}`, flat: r.int(101, 904), bldg: r.pick(BUILDINGS), city, rent: r.int(30, 120) * 500, depMonths: r.int(2, 6), due: r.int(3, 10), esc: r.int(3, 9), start: date(r.int(2025, 2026), r.int(1, 12), 1), months: 11, notice: r.int(1, 2), refund: r.pick([15, 30, 45]), park: r.int(1, 3), maint: "Landlord", repairs: r.int(2, 8) * 500, sublet: "may", lockin: r.chance(0.7) ? r.int(3, 6) : 0, pets: false, late: 0, paint: r.chance(0.6), wsh: "will", govCap: "agreement", refundFmt: "words", electricityFirst: true, typo: true, }; v0.dep = v0.rent * v0.depMonths; const v1 = clone(v0); v1.start = new Date(v0.start); v1.start2 = null; const labels = [], noise = []; const money = (n) => rupees(n, cf); const dueTxt = (d) => `${ordinal(d)} day of each month`; const nt = (n) => `${words(n)} (${n}) month${n > 1 ? "s" : ""}`; const endOf = (s, m) => addDays(addMonths(s, m), -1); const opts = [ () => { v1.rent = v0.rent + r.int(1, 6) * 500; labels.push({ cat: "Money", before: money(v0.rent), after: money(v1.rent), what: "monthly rent" }); }, () => { v1.dep = v0.dep + r.int(1, 4) * 10000; labels.push({ cat: "Money", before: money(v0.dep), after: money(v1.dep), what: "deposit" }); }, () => { v1.due = r.other([1, 2, 3, 5, 7, 10], v0.due); labels.push({ cat: "Date", before: dueTxt(v0.due), after: dueTxt(v1.due), what: "rent due day" }); }, () => { v1.esc = v0.esc + r.int(1, 4); labels.push({ cat: "Percent", before: `${v0.esc}%`, after: `${v1.esc}%`, what: "escalation" }); }, () => { v1.notice = v0.notice + 1; labels.push({ cat: "Duration", before: nt(v0.notice), after: nt(v1.notice), what: "notice" }); }, () => { v1.refund = r.other([15, 30, 45, 60], v0.refund); labels.push({ cat: "Duration", before: wordsDigits(v0.refund) + " days", after: wordsDigits(v1.refund) + " days", what: "deposit refund days" }); }, () => { v1.park = v0.park === 1 ? 2 : v0.park - 1; labels.push({ cat: "Number", before: wordsDigits(v0.park), after: wordsDigits(v1.park), what: "parking slots" }); }, () => { v1.maint = "Tenant"; labels.push({ cat: "Party", before: "Landlord", after: "Tenant", what: "who pays maintenance" }); }, () => { v1.repairs = v0.repairs + r.int(2, 6) * 500; labels.push({ cat: "Money", before: money(v0.repairs), after: money(v1.repairs), what: "repairs limit" }); }, () => { v1.sublet = "shall not"; labels.push({ cat: "Obligation", before: "may sublet", after: "shall not sublet", what: "sublet" }); }, () => { if (!v0.lockin) return false; v1.lockin = 0; labels.push({ cat: "Clause removed", before: "lock-in period", after: "", what: "lock-in" }); }, () => { if (v0.lockin) return false; v1.lockin = 6; labels.push({ cat: "Clause added", before: "", after: "lock-in period", what: "lock-in" }); }, () => { v1.late = r.pick([100, 200, 250, 500]); labels.push({ cat: "Money", before: "", after: money(v1.late), what: "late fee sentence" }); }, () => { v1.pets = true; labels.push({ cat: "Clause added", before: "", after: "shall not keep pets", what: "pets clause" }); }, () => { if (!v0.paint) return false; v1.paint = false; labels.push({ cat: "Clause removed", before: "cost of painting", after: "", what: "painting clause" }); }, () => { v1.start = addMonths(v0.start, 11); labels.push({ cat: "Date", before: fmtDate(v0.start, ds), after: fmtDate(v1.start, ds), what: "start date" }); labels.push({ cat: "Date", before: fmtDate(endOf(v0.start, 11), ds), after: fmtDate(endOf(v1.start, 11), ds), what: "end date" }); }, () => { v1.land = `Mr. ${person(r)}`; if (v1.land === v0.land) return false; labels.push({ cat: "Party", before: v0.land.replace(/^\S+ /, ""), after: v1.land.replace(/^\S+ /, ""), what: "landlord" }); }, ]; const noiseOpts = [ () => { v1.wsh = "shall"; noise.push("will -> shall in payment clause"); }, () => { v1.govCap = "Agreement"; noise.push("capitalisation"); }, () => { if (labels.some((l) => l.what === "deposit refund days")) return false; v1.refundFmt = "digits"; noise.push("thirty (30) days -> 30 days"); }, () => { v1.electricityFirst = false; noise.push("electricity paragraph moved"); }, () => { v1.typo = false; noise.push("typo fixed"); }, () => { v1.wrap = true; noise.push("re-flowed lines"); }, ]; pickAndApply(r, opts, r.int(4, 7)); pickAndApply(r, noiseOpts, r.int(2, 3)); const doc = (v) => { const end = endOf(v.start, v.months); const maintP = `Society maintenance charges shall be borne by the ${v.maint}.`; const elecP = `Electricity and water bills for the Premises shall be paid by the Tenant as per actual meter readings.`; const repP = `Minor repairs costing up to ${money(v.repairs)} each shall be done by the Tenant at the Tenant's cost.`; const secs = [ { head: "premises", paras: [`The Landlord agrees to let out Flat ${v.flat}, ${v.bldg}, ${v.city} (the "Premises") to the Tenant for residential ${v.typo ? "accomodation" : "accommodation"} only.`] }, { head: "term", paras: [`This agreement is for a period of ${words(v.months)} (${v.months}) months, from ${fmtDate(v.start, ds)} to ${fmtDate(end, ds)}.`] }, { head: "rent", paras: [ `The Tenant shall pay a monthly rent of ${money(v.rent)} (Rupees ${rupeeWords(v.rent)} only) on or before the ${dueTxt(v.due)}.${v.late ? ` A late fee of ${money(v.late)} per day applies after the due date.` : ""}`, `The rent ${v.wsh} be paid by bank transfer to the account named by the Landlord.`, `The rent shall go up by an annual escalation of ${v.esc}% on each renewal.`, ] }, { head: "security deposit", paras: [ `The Tenant has paid a security deposit of ${money(v.dep)} (Rupees ${rupeeWords(v.dep)} only), which carries no interest.`, `The deposit shall be refunded within ${v.refundFmt === "words" ? wordsDigits(v.refund) : v.refund} days of the Tenant handing over the Premises, after deducting unpaid dues.`, ] }, { head: "maintenance and charges", paras: v.electricityFirst ? [maintP, elecP, repP] : [maintP, repP, elecP] }, { head: "use of the premises", paras: [ v.sublet === "may" ? `The Tenant may sublet a part of the Premises with the prior written consent of the Landlord.` : `The Tenant shall not sublet any part of the Premises.`, `The Tenant shall not make structural changes to the Premises.`, v.pets ? `The Tenant shall not keep pets in the Premises without the written consent of the Landlord.` : null, v.paint ? `The Tenant shall bear the cost of painting the Premises when vacating.` : null, ] }, v.lockin ? { head: "lock-in", paras: [`Neither party may end this agreement during the first ${words(v.lockin)} (${v.lockin}) months (the lock-in period), except for a serious breach.`] } : null, { head: "notice", paras: [`Either party may end this agreement by giving ${nt(v.notice)}' notice in writing.`.replace("month' notice", "month's notice")] }, { head: "parking", paras: [`The Tenant may use ${wordsDigits(v.park)} covered parking slot${v.park > 1 ? "s" : ""} in the building.`] }, { head: "governing law", paras: [`This ${v.govCap} is governed by the laws of India, and the courts at ${v.city} shall have jurisdiction.`] }, ].filter(Boolean); return { title: "Residential rent agreement", preamble: [`This Rent Agreement is made at ${v.city} on ${fmtDate(v.start, ds)} between ${v.land}, (the "Landlord"), and ${v.ten} (the "Tenant").`], sections: secs, closing: [`Signed by the Landlord: ${v.land.replace(/^\S+ /, "")}\nSigned by the Tenant: ${v.ten.replace(/^\S+ /, "")}`], }; }; const style = { num: "dot", sub: true, head: "caps", blank: true }; let after = render(doc(v1), style); if (v1.wrap) after = hardWrap(after, 70); return { id, type: "Rent agreement", before: render(doc(v0), style), after, labels, noise }; } /* ---------------- D2: offer letter ---------------- */ const COMPANIES = ["Lumen Ridge Analytics Pvt Ltd", "Quillmere Software Pvt Ltd", "Saltmarsh Consulting LLP", "Orchid Lane Technologies Pvt Ltd", "Brightwater Insights Pvt Ltd"]; function offer(r, id) { const cf = r.pick(["sym", "inr"]); const co = r.pick(COMPANIES); const letter = date(2026, r.int(8, 11), r.int(1, 20)); const v0 = { co, cand: person(r), role: r.pick(["Senior Data Analyst", "Data Engineer", "Product Manager", "Actuarial Analyst", "Cloud Architect"]), letter, join: addDays(letter, r.int(30, 60)), ctc: r.int(8, 40) * 50000, variable: r.pick([5, 8, 10, 12, 15]), bonus: r.int(1, 4) * 25000, clawback: 0, city: r.pick(CITIES), mgr: person(r), probation: r.pick([3, 6]), notice: r.pick([30, 60, 90]), leave: r.pick([18, 21, 24, 27]), wfh: r.int(1, 3), wfhCond: "with", reloc: r.chance(0.6) ? r.int(2, 6) * 10000 : 0, noncompete: 0, acceptBy: null, bgv: false, cover: r.pick([300000, 500000]), pleased: "pleased", subjCap: false, yours: "sincerely", }; v0.acceptBy = addDays(letter, 7); const v1 = clone(v0); ["letter", "join", "acceptBy"].forEach((k) => { v1[k] = new Date(v0[k]); }); const labels = [], noise = []; const money = (n) => rupees(n, cf); const ds = "long"; const opts = [ () => { v1.ctc = v0.ctc + r.pick([-2, -1, 1, 2, 3]) * 50000; labels.push({ cat: "Money", before: money(v0.ctc), after: money(v1.ctc), what: "CTC" }); }, () => { v1.variable = r.other([5, 8, 10, 12, 15, 20], v0.variable); labels.push({ cat: "Percent", before: `${v0.variable}%`, after: `${v1.variable}%`, what: "variable pay" }); }, () => { v1.bonus = v0.bonus + r.pick([-1, 1, 2]) * 25000; if (v1.bonus <= 0) v1.bonus = 15000; labels.push({ cat: "Money", before: money(v0.bonus), after: money(v1.bonus), what: "joining bonus" }); }, () => { v1.clawback = 12; labels.push({ cat: "Duration", before: "", after: "twelve (12) months", what: "bonus clawback" }); }, () => { v1.join = addDays(v0.join, r.int(7, 35)); labels.push({ cat: "Date", before: fmtDate(v0.join, ds), after: fmtDate(v1.join, ds), what: "joining date" }); }, () => { v1.city = r.other(CITIES, v0.city); labels.push({ cat: "Party", before: v0.city, after: v1.city, what: "location" }); }, () => { v1.mgr = person(r); if (v1.mgr === v0.mgr) return false; labels.push({ cat: "Party", before: v0.mgr, after: v1.mgr, what: "manager" }); }, () => { v1.probation = v0.probation === 3 ? 6 : 3; labels.push({ cat: "Duration", before: wordsDigits(v0.probation) + " months", after: wordsDigits(v1.probation) + " months", what: "probation" }); }, () => { v1.notice = r.other([30, 60, 90], v0.notice); labels.push({ cat: "Duration", before: wordsDigits(v0.notice) + " days", after: wordsDigits(v1.notice) + " days", what: "notice" }); }, () => { v1.leave = r.other([12, 15, 18, 21, 24, 27, 30], v0.leave); labels.push({ cat: "Duration", before: `${v0.leave} days`, after: `${v1.leave} days`, what: "leave" }); }, () => { v1.wfh = v0.wfh === 1 ? 2 : v0.wfh - 1; labels.push({ cat: "Duration", before: `${words(v0.wfh)} day${v0.wfh > 1 ? "s" : ""}`, after: `${words(v1.wfh)} day${v1.wfh > 1 ? "s" : ""}`, what: "wfh days" }); }, () => { v1.wfhCond = "only with"; labels.push({ cat: "Obligation", before: "with your manager", after: "only with your manager", what: "wfh condition" }); }, () => { if (!v0.reloc) return false; v1.reloc = 0; labels.push({ cat: "Clause removed", before: "relocation costs", after: "", what: "relocation" }); }, () => { v1.noncompete = r.pick([6, 12]); labels.push({ cat: "Clause added", before: "", after: "direct competitor", what: "non-compete" }); }, () => { v1.acceptBy = addDays(v0.acceptBy, r.int(5, 14)); labels.push({ cat: "Date", before: fmtDate(v0.acceptBy, ds), after: fmtDate(v1.acceptBy, ds), what: "accept by" }); }, () => { v1.bgv = true; labels.push({ cat: "Obligation", before: "", after: "subject to", what: "background check sentence" }); }, () => { v1.cover = v0.cover === 300000 ? 500000 : 300000; labels.push({ cat: "Money", before: money(v0.cover), after: money(v1.cover), what: "insurance cover" }); }, ]; const noiseOpts = [ () => { v1.pleased = "happy"; noise.push("pleased -> happy"); }, () => { v1.subjCap = true; noise.push("subject line capitalised"); }, () => { v1.yours = "faithfully"; noise.push("sign-off"); }, () => { v1.wrap = true; noise.push("re-flowed lines"); }, () => { if (labels.some((l) => l.what === "CTC")) return false; v1.ctcAlt = true; noise.push("CTC currency written differently, same amount"); }, ]; pickAndApply(r, opts, r.int(5, 8)); pickAndApply(r, noiseOpts, r.int(2, 3)); const doc = (v) => ({ title: "", preamble: [`${v.co}\nPlot ${7}, Sector 9, Cyber Park, Gurugram 122002\ncareers@${v.co.split(" ")[0].toLowerCase()}.example`, `Date: ${fmtDate(v.letter, ds)}`, `Dear ${v.cand},`, `Subject: ${v.subjCap ? "Offer of Employment" : "Offer of employment"}`, `We are ${v.pleased} to offer you the position of ${v.role} at ${v.co} (the "Company"), on the terms below.`], sections: [ { head: "Joining date", paras: [`Your date of joining will be ${fmtDate(v.join, ds)}.`] }, { head: "Compensation", paras: [`Your annual cost to company (CTC) will be ${v.ctcAlt ? rupees(v.ctc, cf === "inr" ? "sym" : "inr") : money(v.ctc)}. This includes variable pay of ${v.variable}% of CTC, paid on the basis of your performance rating.`] }, { head: "Joining bonus", paras: [`You will receive a one-time joining bonus of ${money(v.bonus)} with your first salary.${v.clawback ? ` The joining bonus must be repaid in full if you leave the Company within ${wordsDigits(v.clawback)} months of joining.` : ""}`] }, v.reloc ? { head: "Relocation support", paras: [`The Company will pay up to ${money(v.reloc)} towards your relocation costs, against receipts.`] } : null, { head: "Location", paras: [`Your place of work will be ${v.city}. You may be asked to travel for client work.`] }, { head: "Reporting", paras: [`You will report to ${v.mgr}, Head of the team.`] }, { head: "Probation", paras: [`You will be on probation for ${wordsDigits(v.probation)} months from your date of joining.`] }, { head: "Notice period", paras: [`After confirmation, either party may end your employment by giving ${wordsDigits(v.notice)} days' notice in writing.`] }, { head: "Leave and insurance", paras: [`You are entitled to ${v.leave} days of paid leave in each calendar year. You and your family are covered by a health insurance policy of ${money(v.cover)}.`] }, { head: "Work from home", paras: [`You may work from home up to ${words(v.wfh)} day${v.wfh > 1 ? "s" : ""} a week, ${v.wfhCond} your manager's approval.`] }, v.noncompete ? { head: "Non-compete", paras: [`For ${wordsDigits(v.noncompete)} months after you leave, you shall not join a direct competitor of the Company in India.`] } : null, ].filter(Boolean), closing: [`${v.bgv ? "This offer is subject to a satisfactory background check of your education and past employment. " : ""}Please sign and return a copy of this letter by ${fmtDate(v.acceptBy, ds)} to accept the offer.`, `Yours ${v.yours},\nAnika Sorenstam\nHead of People, ${v.co}`], }); const style = { num: "none", head: "sentence", blank: true }; let after = render(doc(v1), style); if (v1.wrap) after = hardWrap(after, 66); return { id, type: "Offer letter", before: render(doc(v0), style), after, labels, noise }; } /* ---------------- D3: loan sanction letter ---------------- */ const LENDERS = ["Tarnwell Housing Finance Ltd", "Brightmoor Home Loans Ltd", "Kestrelgate Finance Ltd"]; function loan(r, id) { const lender = r.pick(LENDERS); const amt = r.int(20, 150) * 100000; const ds = "dmy-"; const sanction = date(2026, r.int(6, 11), r.int(1, 28)); const v0 = { lender, b1: `${honor(r)} ${person(r)}`, b2: `${honor(r)} ${person(r)}`, amt, rate: r.pick([7.9, 8.25, 8.5, 8.75, 9.1, 9.4]), tenure: r.pick([180, 240, 300]), fee: r.pick([0.25, 0.5, 0.75, 1]), prepay: r.pick([0, 2]), valid: r.pick([30, 60, 90]), reset: 3, late: 2, sanction, minBal: false, noPrepayClause: true, partPrepay: "may", insure: true, ref: r.int(100000, 999999), rateWord: "per annum", sym: "sym", }; v0.emi = Math.round((amt * (v0.rate / 1200)) / (1 - Math.pow(1 + v0.rate / 1200, -v0.tenure)) / 10) * 10; const v1 = clone(v0); v1.sanction = new Date(v0.sanction); const labels = [], noise = []; const money = (n, f = v0.sym) => rupees(n, f); const opts = [ () => { v1.amt = v0.amt + r.pick([-5, 5, 10]) * 100000; labels.push({ cat: "Money", before: money(v0.amt), after: money(v1.amt), what: "loan amount" }); }, () => { v1.rate = Math.round((v0.rate + r.pick([0.25, 0.5, 0.35, -0.25])) * 100) / 100; labels.push({ cat: "Percent", before: `${v0.rate}%`, after: `${v1.rate}%`, what: "interest" }); }, () => { v1.tenure = r.other([120, 180, 240, 300], v0.tenure); labels.push({ cat: "Duration", before: `${v0.tenure} months`, after: `${v1.tenure} months`, what: "tenure" }); }, () => { v1.emi = v0.emi + r.int(3, 40) * 100; labels.push({ cat: "Money", before: money(v0.emi), after: money(v1.emi), what: "EMI" }); }, () => { v1.fee = r.other([0.25, 0.5, 0.75, 1, 1.25], v0.fee); labels.push({ cat: "Percent", before: `${v0.fee}%`, after: `${v1.fee}%`, what: "processing fee" }); }, () => { v1.valid = r.other([30, 45, 60, 90], v0.valid); labels.push({ cat: "Duration", before: `${v0.valid} days`, after: `${v1.valid} days`, what: "validity" }); }, () => { v1.reset = 6; labels.push({ cat: "Duration", before: "3 months", after: "6 months", what: "reset" }); }, () => { v1.late = 3; labels.push({ cat: "Percent", before: "2%", after: "3%", what: "late charge" }); }, () => { v1.b2 = `${honor(r)} ${person(r)}`; if (v1.b2 === v0.b2) return false; labels.push({ cat: "Party", before: v0.b2.replace(/^\S+ /, ""), after: v1.b2.replace(/^\S+ /, ""), what: "co-borrower" }); }, () => { v1.minBal = true; labels.push({ cat: "Clause added", before: "", after: "minimum balance", what: "min balance clause" }); }, () => { v1.noPrepayClause = false; labels.push({ cat: "Clause removed", before: "no prepayment charges", after: "", what: "no prepay charges clause" }); }, () => { v1.partPrepay = "shall not"; labels.push({ cat: "Obligation", before: "may make part", after: "shall not make part", what: "part prepay" }); }, () => { v1.sanction = addDays(v0.sanction, r.int(3, 20)); labels.push({ cat: "Date", before: fmtDate(v0.sanction, ds), after: fmtDate(v1.sanction, ds), what: "sanction date" }); }, () => { v1.insure = false; labels.push({ cat: "Clause removed", before: "insured against fire", after: "", what: "insurance clause" }); }, ]; const noiseOpts = [ () => { v1.rateWord = "p.a."; noise.push("per annum -> p.a."); }, () => { if (labels.some((l) => l.cat === "Money")) return false; v1.sym = "rs"; noise.push("rupee sign -> Rs."); }, () => { v1.swap = true; noise.push("two conditions swapped"); }, () => { v1.wrap = true; noise.push("re-flowed"); }, ]; pickAndApply(r, opts, r.int(5, 7)); pickAndApply(r, noiseOpts, r.int(2, 3)); const doc = (v) => { const m = (n) => money(n, v.sym); const conds = [ `The property shall be ${"insured against fire, flood and earthquake for its full value"} with the Lender named as the first beneficiary.`, `The Borrowers shall give post-dated cheques or an e-mandate for the EMI before the first disbursement.`, ]; if (v.swap) conds.reverse(); if (!v.insure) conds.splice(conds.findIndex((c) => c.includes("insured")), 1); return { title: "Sanction letter for home loan", preamble: [`Ref: HL/${v.ref}\nDate: ${fmtDate(v.sanction, ds)}`, `To: ${v.b1} and ${v.b2}`, `We are pleased to inform you that ${v.lender} (the "Lender") has sanctioned a home loan on the terms set out below.`], sections: [ { head: "Loan amount", paras: [`The loan amount sanctioned is ${m(v.amt)} (Rupees ${rupeeWords(v.amt)} only).`] }, { head: "Interest", paras: [`Interest shall be charged at a floating rate of ${v.rate}% ${v.rateWord}, linked to the Lender's benchmark rate. The rate is reset every ${v.reset} months.`] }, { head: "Tenure and EMI", paras: [`The loan tenure is ${v.tenure} months. The equated monthly instalment (EMI) is ${m(v.emi)}, payable on the 5th day of each month.`] }, { head: "Fees and charges", paras: [`A processing fee of ${v.fee}% of the loan amount is payable before disbursement.`, `A late payment charge of ${v.late}% per month applies to any overdue EMI.`] }, { head: "Prepayment", paras: [`The Borrowers ${v.partPrepay} make part prepayments of at least one EMI at any time.`, v.noPrepayClause ? `There are no prepayment charges on floating rate loans taken by individuals.` : null] }, { head: "Conditions", paras: [...conds, v.minBal ? `The Borrowers shall keep a minimum balance equal to one EMI in the repayment account at all times.` : null] }, { head: "Validity", paras: [`This sanction is valid for ${v.valid} days from the date of this letter.`] }, ], closing: [`For ${v.lender}\nAuthorised Signatory`], }; }; const style = { num: "dot", sub: true, head: "title", blank: true }; let after = render(doc(v1), style); if (v1.wrap) after = hardWrap(after, 68); return { id, type: "Loan sanction letter", before: render(doc(v0), style), after, labels, noise }; } /* ---------------- D4: vendor services agreement ---------------- */ const CLIENTS = ["Harbourline Logistics Inc.", "Cobaltfield Retail Inc.", "Northvane Freight Corp."]; const VENDORS = ["Quillfeather Data Services LLC", "Ironbark Cloud Services LLC", "Pebblestone Analytics LLC"]; function vendor(r, id) { const cur = r.pick(["$", "USD "]); const usd = (n) => `${cur}${intl(n)}`; const eff = date(2027, r.int(1, 6), r.int(1, 28)); const v0 = { client: r.pick(CLIENTS), vendor: r.pick(VENDORS), fee: r.int(8, 40) * 1000, hourly: r.int(9, 18) * 10, pay: r.pick([30, 45]), lateInt: r.pick([1, 1.5]), cap: r.pick([250000, 500000, 1000000]), uptime: r.pick([99.5, 99.9]), credit: r.pick([5, 10]), term: r.pick([12, 24, 36]), termNotice: r.pick([30, 60, 90]), eff, conf: r.pick([2, 3, 5]), email: "notices@" + "client.example", lead: person(r), conv: "may", nonsolicit: false, audit: true, breach: 0, wsh: "will", defsSwap: false, }; const v1 = clone(v0); v1.eff = new Date(v0.eff); const labels = [], noise = []; const opts = [ () => { v1.fee = v0.fee + r.pick([-2, 1, 2, 4]) * 1000; labels.push({ cat: "Money", before: usd(v0.fee), after: usd(v1.fee), what: "monthly fee" }); }, () => { v1.hourly = v0.hourly + r.pick([10, 15, 20]); labels.push({ cat: "Money", before: usd(v0.hourly), after: usd(v1.hourly), what: "hourly rate" }); }, () => { v1.pay = v0.pay === 30 ? 45 : 60; labels.push({ cat: "Duration", before: `${wordsDigits(v0.pay)} days`, after: `${wordsDigits(v1.pay)} days`, what: "payment terms" }); }, () => { v1.lateInt = v0.lateInt === 1 ? 1.5 : 2; labels.push({ cat: "Percent", before: `${v0.lateInt}%`, after: `${v1.lateInt}%`, what: "late interest" }); }, () => { v1.cap = r.other([250000, 500000, 1000000, 2000000], v0.cap); labels.push({ cat: "Money", before: usd(v0.cap), after: usd(v1.cap), what: "liability cap" }); }, () => { v1.uptime = v0.uptime === 99.5 ? 99.9 : 99.5; labels.push({ cat: "Percent", before: `${v0.uptime}%`, after: `${v1.uptime}%`, what: "uptime" }); }, () => { v1.credit = v0.credit === 5 ? 10 : 5; labels.push({ cat: "Percent", before: `${v0.credit}%`, after: `${v1.credit}%`, what: "service credit" }); }, () => { v1.term = r.other([12, 24, 36], v0.term); labels.push({ cat: "Duration", before: `${v0.term} months`, after: `${v1.term} months`, what: "term" }); }, () => { v1.termNotice = r.other([30, 60, 90], v0.termNotice); labels.push({ cat: "Duration", before: `${v0.termNotice} days`, after: `${v1.termNotice} days`, what: "termination notice" }); }, () => { v1.eff = addDays(v0.eff, r.int(10, 40)); labels.push({ cat: "Date", before: fmtDate(v0.eff, "mdy"), after: fmtDate(v1.eff, "mdy"), what: "effective date" }); }, () => { v1.conf = r.other([2, 3, 5], v0.conf); labels.push({ cat: "Duration", before: `${words(v0.conf)} years`, after: `${words(v1.conf)} years`, what: "confidentiality" }); }, () => { v1.email = "legal@client.example"; labels.push({ cat: "Party", before: "notices@client.example", after: "legal@client.example", what: "notice email" }); }, () => { v1.lead = person(r); if (v1.lead === v0.lead) return false; labels.push({ cat: "Party", before: v0.lead, after: v1.lead, what: "key person" }); }, () => { v1.conv = "may not"; labels.push({ cat: "Obligation", before: "may terminate", after: "may not terminate", what: "termination for convenience" }); }, () => { v1.nonsolicit = true; labels.push({ cat: "Clause added", before: "", after: "solicit", what: "non-solicitation" }); }, () => { v1.audit = false; labels.push({ cat: "Clause removed", before: "audit", after: "", what: "audit rights" }); }, () => { v1.breach = 72; labels.push({ cat: "Duration", before: "", after: "72 hours", what: "breach notification sentence" }); }, ]; const noiseOpts = [ () => { v1.wsh = "shall"; noise.push("will -> shall"); }, () => { v1.defsSwap = true; noise.push("definitions swapped (moved)"); }, () => { v1.wrap = true; noise.push("re-flowed"); }, () => { if (labels.some((l) => l.what === "termination for convenience")) return false; v1.endWord = true; noise.push("terminate -> end in one sentence"); }, ]; pickAndApply(r, opts, r.int(5, 8)); pickAndApply(r, noiseOpts, r.int(2, 3)); const doc = (v) => { const defs = [`"Services" means the data processing and reporting services described in Schedule A.`, `"Business Day" means a day other than a Saturday, Sunday or public holiday in New York.`]; if (v.defsSwap) defs.reverse(); return { title: "Master services agreement", preamble: [`This Master Services Agreement is entered into as of ${fmtDate(v.eff, "mdy")} (the "Effective Date") by and between ${v.client} ("Client") and ${v.vendor} ("Vendor").`], sections: [ { head: "definitions", paras: defs }, { head: "fees and payment", paras: [`Client shall pay Vendor a monthly fee of ${usd(v.fee)} for the Services.`, `Additional work requested in writing is charged at ${usd(v.hourly)} per hour.`, `Invoices are payable within ${wordsDigits(v.pay)} days of receipt. Overdue amounts carry interest at ${v.lateInt}% per month.`] }, { head: "service levels", paras: [`Vendor ${v.wsh} make the Services available ${v.uptime}% of the time in each calendar month.`, `If availability falls below this level, Client is entitled to a service credit of ${v.credit}% of the monthly fee.`] }, { head: "term and termination", paras: [`This Agreement starts on the Effective Date and continues for ${v.term} months.`, `Either party ${v.conv} ${v.endWord ? "end" : "terminate"} this Agreement for convenience by giving ${v.termNotice} days' written notice.`] }, { head: "liability", paras: [`Each party's total liability under this Agreement is limited to ${usd(v.cap)}.`] }, { head: "confidentiality", paras: [`Each party shall keep the other party's confidential information secret for ${words(v.conf)} years after this Agreement ends.${v.breach ? ` Vendor shall notify Client of any data breach within ${v.breach} hours of becoming aware of it.` : ""}`] }, v.audit ? { head: "audit", paras: [`Client may audit Vendor's records relating to the Services once a year, on reasonable notice.`] } : null, v.nonsolicit ? { head: "non-solicitation", paras: [`Neither party shall solicit or hire the other party's employees during the term of this Agreement.`] } : null, { head: "key personnel", paras: [`Vendor's account lead for the Services is ${v.lead}.`] }, { head: "notices", paras: [`Notices to Client shall be sent by e-mail to ${v.email}.`] }, ].filter(Boolean), closing: [`Signed for Client: ____________\nSigned for Vendor: ____________`], }; }; const style = { num: "section", sub: true, head: "title", blank: true }; let after = render(doc(v1), style); if (v1.wrap) after = hardWrap(after, 74); return { id, type: "Vendor services agreement", before: render(doc(v0), style), after, labels, noise }; } /* ---------------- D5: life insurance renewal (Corvane Life, fictional insurer) ---------------- */ function renewal(r, id) { const ds = r.pick(["long", "dmy/"]); const due = date(2027, r.int(1, 12), r.int(1, 28)); const v0 = { holder: `${honor(r)} ${person(r)}`, pol: r.int(100000, 999999), sa: r.pick([2500000, 5000000, 7500000, 10000000]), prem: r.int(80, 400) * 100, grace: r.pick([15, 30]), nominee: person(r), rel: r.pick(["spouse", "daughter", "son", "mother"]), adb: r.pick([500000, 1000000]), wait: 90, due, loading: r.pick([0, 10, 15]), claimDays: r.pick([30, 60, 90]), hazard: false, rider: true, disclose: false, mode: "annual", capSA: false, }; const v1 = clone(v0); v1.due = new Date(v0.due); const labels = [], noise = []; const money = (n) => `₹${inr(n)}`; const opts = [ () => { v1.sa = r.other([2500000, 5000000, 7500000, 10000000], v0.sa); labels.push({ cat: "Money", before: money(v0.sa), after: money(v1.sa), what: "sum assured" }); }, () => { v1.prem = v0.prem + r.int(5, 40) * 100; labels.push({ cat: "Money", before: money(v0.prem), after: money(v1.prem), what: "premium" }); }, () => { v1.grace = v0.grace === 15 ? 30 : 15; labels.push({ cat: "Duration", before: `${v0.grace} days`, after: `${v1.grace} days`, what: "grace" }); }, () => { v1.nominee = person(r); if (v1.nominee === v0.nominee) return false; labels.push({ cat: "Party", before: v0.nominee, after: v1.nominee, what: "nominee" }); }, () => { if (!v1.rider) return false; v1.adb = v0.adb === 500000 ? 1000000 : 500000; labels.push({ cat: "Money", before: money(v0.adb), after: money(v1.adb), what: "rider sum" }); }, () => { v1.wait = r.pick([60, 120, 180]); labels.push({ cat: "Duration", before: `${v0.wait} days`, after: `${v1.wait} days`, what: "waiting period" }); }, () => { v1.due = addDays(v0.due, r.int(5, 30)); labels.push({ cat: "Date", before: fmtDate(v0.due, ds), after: fmtDate(v1.due, ds), what: "due date" }); }, () => { v1.loading = r.other([0, 5, 10, 15, 25], v0.loading); labels.push({ cat: "Percent", before: `${v0.loading}%`, after: `${v1.loading}%`, what: "loading" }); }, () => { v1.claimDays = r.other([30, 60, 90], v0.claimDays); labels.push({ cat: "Duration", before: `${v0.claimDays} days`, after: `${v1.claimDays} days`, what: "claim intimation" }); }, () => { v1.hazard = true; labels.push({ cat: "Clause added", before: "", after: "hazardous sports", what: "exclusion" }); }, () => { if (labels.some((l) => l.what === "rider sum")) return false; v1.rider = false; labels.push({ cat: "Money", before: money(v0.adb), after: "", what: "rider sentence removed" }); }, () => { v1.disclose = true; labels.push({ cat: "Clause added", before: "", after: "must tell us", what: "disclosure section" }); }, () => { v1.pol = v0.pol + r.int(1, 9); labels.push({ cat: "Number", before: String(v0.pol), after: String(v1.pol), what: "policy number" }); }, ]; const noiseOpts = [ () => { v1.capSA = true; noise.push("Sum Assured capitalised"); }, () => { v1.swap = true; noise.push("two conditions swapped"); }, () => { v1.wrap = true; noise.push("re-flowed"); }, () => { v1.modeWord = true; noise.push("wording: annual -> yearly"); }, ]; pickAndApply(r, opts, r.int(4, 7)); pickAndApply(r, noiseOpts, r.int(2, 3)); const doc = (v) => { const SA = v.capSA ? "Sum Assured" : "sum assured"; const conds = [ `If a premium is not paid by the due date, a grace period of ${v.grace} days applies, during which the cover continues.`, `Claims must be reported to Corvane Life within ${v.claimDays} days of the date of death, with the documents listed in the claim form.`, ]; if (v.swap) conds.reverse(); return { title: "Corvane Life: renewal notice for your term insurance policy", preamble: [`Policyholder: ${v.holder}\nPolicy number: CVL-TL-${v.pol}\nPlan: Corvane Term Shield`, `Your policy is due for renewal. The terms for the next policy year are set out below. Please read them carefully.`], sections: [ { head: "Cover", paras: [`The ${SA} is ${money(v.sa)}.${v.rider ? ` An accidental death benefit rider adds ${money(v.adb)} if death is caused by an accident.` : ""}`] }, { head: "Premium", paras: [`The ${v.modeWord ? "yearly" : "annual"} premium is ${money(v.prem)}, including a health loading of ${v.loading}%. It is due on ${fmtDate(v.due, ds)}.`] }, { head: "Conditions", paras: [...conds, `Critical illness cover starts after a waiting period of ${v.wait} days from the renewal date.`, v.hazard ? `Death caused by taking part in hazardous sports, such as motor racing or mountaineering, is not covered.` : null] }, { head: "Nominee", paras: [`The nominee under this policy is ${v.nominee} (${v.rel}).`] }, v.disclose ? { head: "Your duty to disclose", paras: [`You must tell us about any new illness or change of occupation before the renewal date, or a claim may be refused.`] } : null, ].filter(Boolean), closing: [`Corvane Life is a fictional insurer used in this demonstration.`], }; }; const style = { num: "dot", sub: true, head: "caps", blank: true }; let after = render(doc(v1), style); if (v1.wrap) after = hardWrap(after, 72); return { id, type: "Insurance renewal", before: render(doc(v0), style), after, labels, noise }; } function pickAndApply(r, opts, k) { let applied = 0; for (const fn of r.shuffle(opts)) { if (applied >= k) break; if (fn() !== false) applied++; } } const r = makeRng(SEED); const builders = [rent, offer, loan, vendor, renewal]; const pairs = []; for (let i = 0; i < 25; i++) pairs.push(builders[i % 5](r, `dev-${String(i + 1).padStart(2, "0")}`)); writeFileSync(new URL("./dev.json", import.meta.url), JSON.stringify({ split: "dev", seed: SEED, note: "Synthetic, fictional documents. Used for building and tuning.", pairs }, null, 1)); console.log(`dev: ${pairs.length} pairs, ${pairs.reduce((s, p) => s + p.labels.length, 0)} planted changes, ${pairs.reduce((s, p) => s + p.noise.length, 0)} cosmetic changes`);