Vanilla JS CBT Detector Outperforms NLP Libraries in Accuracy, Speed, and Privacy
A developer built a 200-line vanilla JavaScript tool to detect cognitive distortions — patterns identified in CBT therapy — and benchmarked it against five NLP and AI solutions. The rule-based JS detector achieved 94% accuracy on 100 test samples, outperforming OpenAI's API (89%), Hugging Face (83%), and TensorFlow.js (72%), while running at 0.2ms median latency with zero cost. Unlike API-based tools, the vanilla JS approach processes all data entirely in the browser, making it suitable for sensitive mental health use cases where privacy is critical. The benchmark covered ten clinically defined cognitive distortions originally described by Aaron Beck in 1976, representing a closed and well-documented classification set. The developer concluded that rule-based pattern matching is preferable when the output space is fixed, privacy is essential, and deterministic results are required.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in