HomeAI & Machine LearningContract Clause Classifier

⚖️ Contract Clause Classifier — NLP Risk Flagging Live

Feed clauses from a synthetic contract through an NLP classifier that flags indemnity, termination and liability risk in real time, highlighting exactly which tokens drove each flag.

AI & Machine Learning3DAdvanced60 FPS
ai-legal-contract-analysis ↗ Open standalone

About the Contract Clause Classifier

Legal teams reviewing a long commercial contract need to find the handful of clauses that actually carry outsized risk — an uncapped indemnity, a one-sided termination-for-convenience right, a liability waiver buried in boilerplate — without reading every definitions section and notice clause with the same scrutiny. NLP-based contract review tools automate this first pass: they read every clause, score it for risk, and surface the ones that cross a threshold for a human lawyer to check. This simulation builds a real, working version of that first pass rather than a stylised animation of one.

Under the hood is a genuine bag-of-words logistic regression: a fixed vocabulary of roughly 45 legal terms, each carrying a hand-set signed coefficient tagged to an indemnity, termination or liability category, combined with a bias term and passed through the sigmoid function to produce a 0–1 risk probability per clause. Because the model is linear, every token's contribution to the score is exact and visible — the highlighted-text panel colours each word by its literal coefficient, warm for risk-raising terms like "indemnify" or "uncapped" and cool for risk-reducing terms like "cap" or "cure". Step through a synthetic 24-clause contract clause by clause, or let it auto-play, and watch the running document-level risk chart and category flag counts build up live.

Frequently Asked Questions

How does this simulation actually decide a clause is risky?

Each clause is tokenised into lowercase words, and every token is looked up in a fixed legal vocabulary of about 45 terms, each carrying a real signed coefficient — for example "indemnify" carries +2.2, "uncapped" carries +2.3, while risk-reducing terms like "cap" or "cure" carry negative coefficients such as −1.2 and −0.6. The clause's raw score is the bias term plus the sum of the coefficients for every matched token, and that raw score is passed through the logistic sigmoid function 1/(1+e⁻ᶻ) to produce a probability-like risk score between 0 and 1. This is a genuine bag-of-words logistic regression, just with hand-set weights instead of weights learned from labelled training data.

What is the difference between bag-of-words scoring and a real production NLP pipeline?

Bag-of-words logistic regression, exactly as shown here, was the dominant approach to text classification for roughly two decades before deep learning, and lightweight legal-tech tools still use TF-IDF plus logistic regression or linear SVMs today because they are fast, auditable and cheap to run on thousands of documents. Production contract-review systems increasingly layer a transformer encoder (like a fine-tuned BERT or a legal-domain LLM) on top, which captures word order, negation and context that a bag-of-words model misses entirely — for instance it cannot tell "the Vendor shall not be liable" from "the Vendor shall be liable" because "not" is rarely weighted heavily on its own. This simulation deliberately keeps the model simple so every contributing term stays visible.

Why do some words like "cap" or "notice" lower the risk score instead of raising it?

Contract risk is not just about the presence of dangerous concepts — it is about whether those concepts are constrained. A liability clause that mentions "liability" and "damages" is inherently about risk allocation, but if it also contains "cap", "capped" or "maximum", that signals the parties negotiated a ceiling, which meaningfully reduces downside exposure. Similarly "cure" and adequate "notice" periods on a termination clause give the counterparty a chance to fix a problem before the contract ends, which is materially less risky than immediate termination. This simulation encodes that nuance directly as negative coefficients on those specific tokens.

What do the indemnity, termination and liability categories actually track?

Every vocabulary token is tagged with one of four categories: indemnity (indemnify, hold harmless, defend, indemnitee), termination (terminate, convenience, without cause, perpetual), liability (unlimited, uncapped, consequential damages, waive, disclaim) or general (breach, penalty, forfeit, arbitration). For each clause the simulation sums the coefficients of matched tokens separately within each category, and the category with the highest positive subscore becomes that clause's "primary risk driver" tag shown in the highlighted panel. A clause can score high overall while still having a clearly dominant category, which mirrors how real contract-review tools bucket flagged clauses for a lawyer's queue.

How is the token heatmap generated and is it a real attribution, not just decoration?

Because the model is a linear sum of per-token coefficients, the exact contribution of any single token to the final score is just that token's coefficient (or coefficient × count, for repeated tokens) — there is no approximation or post-hoc explanation step needed, unlike attribution methods such as SHAP or integrated gradients that are required for non-linear models. The heatmap renders each token's background opacity and hue directly proportional to its signed coefficient: warm colours for positive (risk-raising) weights, cool colours for negative (risk-reducing) weights, and neutral grey for unweighted tokens. What you see is the literal arithmetic term in the sigmoid's input sum, not a simulated visual effect.

What does the risk threshold slider control, and how does moving it change the flag counts?

The classifier always outputs a continuous risk probability between 0 and 1 for every clause; the threshold slider sets the cutoff above which a clause is labelled "flagged" rather than "clear". Lowering the threshold flags more clauses (higher recall, more false positives on borderline clauses) while raising it flags fewer, more confidently risky clauses (higher precision, but some real risk may slip through unflagged). This is the same precision/recall trade-off every binary classifier faces in production, and legal-tech teams typically tune this threshold against a labelled sample of previously reviewed contracts rather than picking it arbitrarily.

Why does the document-level risk chart keep changing shape as clauses are processed?

The running chart plots the per-clause risk score in the order clauses are fed through the classifier, plus a cumulative running-average line. Because the synthetic contract deliberately interleaves low-risk boilerplate (definitions, notices, governing law) with high-risk clauses (uncapped indemnification, unilateral termination for convenience), the per-clause line oscillates sharply while the running-average line smooths those swings out and converges toward the document's overall risk profile as more clauses accumulate — exactly the pattern a real batch contract-review job produces when scanning clause by clause.

Could a lawyer rely on a model like this in practice, or is it only for illustration?

A hand-weighted bag-of-words model like this one is not something a firm would deploy as-is — the coefficients here were chosen for pedagogical clarity, not fitted to a labelled dataset of real contracts, and the vocabulary is far too small to catch the enormous variety of phrasing real contracts use. In practice this kind of linear model is used as a fast first-pass triage filter, trained on thousands of clauses labelled by paralegals, sitting in front of a slower, more accurate transformer-based re-ranker that a human reviewer checks before anything is relied upon legally. The core value of the simple linear version is that every flag is fully explainable — exactly what this simulation visualises.

⚙ Under the hood

Every clause is tokenised and scored against a ~45-term weighted legal vocabulary; the weighted sum plus bias runs through a real sigmoid to produce a risk probability, with per-token coefficients rendered directly as a colour-coded attribution heatmap.

NLPLogistic RegressionBag-of-WordsToken AttributionLegal Tech

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)