StatAgentWeekly email

Number trace: check AI text against your tables

A free script that runs on your own computer. It reads a piece of text and the source tables behind it, then lists every number in the text that it cannot find in the tables.

What it does

When an AI assistant drafts results text, the most common error to catch is a number that is not in your tables: a transposed digit, a rounded value that was never printed, a percent that was invented. This script checks each number in the draft against the source you give it and reports:

It allows for the usual differences in how a number is written: a leading zero left off (.05 and 0.05), thousands commas, a minus sign typed as a dash, rounding to fewer decimals, and 75.6% against 0.756.

Your data stays with you

The script makes no network calls and needs no extra packages. Use R (base R only) or Python (standard library only). Nothing is uploaded and nothing is sent to this site. You can run it with the network switched off.

Run it in 3 steps

1. Save your source tables as a plain text or CSV file, and the text to check as another plain text file. 2. Download number_trace.R or number_trace.py (links below). 3. Run one of these commands in a terminal, with your own file names:


Rscript number_trace.R  --source tables.txt --text draft.txt
python  number_trace.py --source tables.txt --text draft.txt

The report prints to the screen. Add --out report.txt to save it. A worked example with public CDISC pilot data is included so you can see the output before using your own files.

What a result looks like

On the included example, a copy of a correct results passage had 174 numbers, and 173 were found in the source. The one not found was a threshold the writer had added (0.05). A copy with errors planted by hand had 5 of 9 number errors reported as not found, for example 243 where the table says 234. The 4 it did not report were a swapped arm, a value taken from the wrong row, a wrong rounded value that exists elsewhere in the tables, and a dropped minus sign that matched a different number after rounding.

What it cannot do

The tested counts, including false positives and false negatives, are in the README.

Downloads

Licence

The code is released under the MIT licence: free to use, copy, modify and share, with no warranty. The example tables are a condensed, re-typed excerpt of the public CDISC pilot study clinical study report: the numbers are copied from the CSR tables, but table titles are shortened and footnotes abridged, so it is not the original wording. It is used with attribution to CDISC and not for sale. CDISC's terms for the pilot materials ask for unmodified use, so if you reuse the example, go back to the original report and check those terms.

Get one workflow a week

Unsubscribe anytime. Privacy.