We Tested TF-IDF Against Two Transformers for Contract Risk Screening. Bag-of-Words Won Twice.

· Source: NLP on Medium · Field: Legal & Regulatory — Legal Technology (LegalTech), Artificial Intelligence & Machine Learning, Compliance & Risk Management · Depth: Advanced, medium

Summary

A contract risk screening system, developed using the CUAD legal dataset, demonstrated that a bag-of-words approach (TF-IDF + logistic regression) significantly outperformed transformer-based models in precision at matched recall. In a five-way bake-off, TF-IDF achieved 0.248 precision at 0.904 recall, more than double the precision of frozen MiniLM embeddings (0.107 at 0.907 recall) and fine-tuned DeBERTa-v3-base (0.107 at 0.874 recall). An LLM (gpt-oss-120b) showed high precision (0.812) but low recall (0.613). The final production system, a hybrid architecture combining TF-IDF screening with LLM triage for weak flags, achieved the best F1 score of 0.852, processing 95.6% of decisions without LLM cost and running entirely on free-tier cloud resources. This system screens 8 business-facing risk categories from 408 commercial contracts.

Key takeaway

For AI Engineers developing contract risk screening systems, prioritize simple, high-precision models like TF-IDF before investing in complex transformers. If you are building a system where missed risks are costly, implement recall-first thresholding. Consider a hybrid architecture that uses a cheap baseline for initial screening and routes only uncertain cases to an LLM, significantly reducing operational costs while maintaining high performance.

Key insights

For contract risk screening, simple bag-of-words models can significantly outperform transformers in precision at matched recall, especially when combined with LLM triage.

Principles

Method

A hybrid system screens contracts with TF-IDF, routing weak flags to an LLM for confirmation or clearance. Strong flags are kept, and low-score items are cleared, minimizing LLM usage.

In practice

Topics

Code references

Best for: AI Engineer, Machine Learning Engineer, Director of AI/ML

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by NLP on Medium.