Get started
From install to a table of cases
Eight steps, in R, at a terminal, or in Python, using the rules engine, which needs no AI setup. Each step is a few lines to copy and run. The local AI engine is experimental and is not used here.
- 1 Three free programs
- 2 Install extract-text
- 3 Example document
- 4 Scan a random 50
- 5 Grade and score
- 6 Teach your forms
- 7 Whole folder
- 8 Final table
- Go further
- If something goes wrong
Choose R, Terminal, or Python. The same engine runs all three ways, and every step below has a tab for each. Choose a tab once and the whole page follows it. R is for someone who works in RStudio. Terminal needs no programming. Python hands the scan to your own code, and uses the terminal commands for grading and the final table.
Before step 1. You need R and RStudio on your computer, both free, and your court documents (PDF or TIFF files) in a folder on it. If your computer's system is old, update it first: step 1 needs macOS 15 or later on an Apple chip, or Windows 10 version 1809 or later, and says how to check. R is the program that runs the code on this page, and RStudio is the window you work in.
- Install R. Go to cran.r-project.org and choose your system (Windows, macOS, or Linux). On Windows, choose "base" and then the download link at the top. On a Mac, there are two files: one for Apple chips (its name has "arm64") and one for Intel chips. The Apple menu, About This Mac, says which chip you have. Open the downloaded file and accept what the installer suggests.
- Install RStudio. Go to posit.co/download/rstudio-desktop, download the installer for your system, open it, and accept what it suggests.
- Open RStudio. The pane named Console, at the lower left, is where R code runs.
Before step 1. You need your court documents (PDF or TIFF files) in a folder on your computer, and a terminal window, which every computer has: Terminal on a Mac or Linux, PowerShell on Windows. Step 1 shows how to open it. If your computer's system is old, update it first: step 1 needs macOS 15 or later on an Apple chip, or Windows 10 version 1809 or later, and says how to check. You type no code beyond the lines on this page.
Before step 1. You need your court documents (PDF or TIFF files) in a folder on your computer, a terminal window for the install, and Python 3.10 or newer, which step 1 installs. If your computer's system is old, update it first: step 1 needs macOS 15 or later on an Apple chip, or Windows 10 version 1809 or later, and says how to check. Run the Python lines wherever you run Python: at the python prompt, in a script, or in a notebook that uses the environment step 2 makes.
How to run the code on this page. Each dark box below is code, and the strip above it says where it goes. A box marked R goes in RStudio: press Copy at its top right, click in the Console pane, paste, and press Return. A box marked Terminal or PowerShell goes in that program, which step 1 shows how to open. A box marked Python goes wherever you run Python. A light box shows what you should see afterward and is not for typing. A line that begins with # is a note to you, and the computer ignores it.
Prefer one file to copy from? Every step on this page is in getting_started_example_script.R, under the same eight numbers, as code with one-line notes. Save it, open it in RStudio, and run it a block at a time. This page explains each step.
Prefer one block to copy from? Start here lists the terminal command for every step on this page in one block, under the same eight numbers. This page explains each step.
Prefer one block to copy from? Start here lists the Python lines and terminal commands for every step on this page in one block, under the same eight numbers. This page explains each step.
1 Install three free programs
extract-text needs three programs that it does not install itself.
- poppler opens PDF files.
- tesseract reads scanned pages (OCR).
- Python 3.10 or newer runs the engine, the part of extract-text that reads the documents. The Python that comes with a Mac is older.
You install them once, in a terminal window. Find your computer below. You need the internet only to install. After that, extract-text runs with the network unplugged.
Check your system first, and update it if it is old.
- Mac. Open the Apple menu and choose About This Mac. You need macOS 15 (Sequoia) or later, and a line that reads "Chip: Apple M1" or later. Homebrew, the installer used below, keeps ready-made copies of poppler, tesseract, and Python only for the three newest versions of macOS on Apple chips (in November 2026: macOS 15, 26, and 27). On macOS 14 or older, or on an Intel Mac, it prints a warning and tries to build each program from its source code, which is slow and can fail, as it did for one of our testers on macOS 14. Update macOS first, in System Settings, General, Software Update. For a Mac that cannot be updated, Homebrew's own advice is MacPorts, which we have not tested.
- Windows. Press the Windows key, type
winver, and press Enter. Windows 11 works with everything on this page. On Windows 10, the three programs and R need version 1809 or later, and the current RStudio lists Windows 11 only.
Mac
- Open Terminal. Press Command and Space, type Terminal, and press Return.
- Install Homebrew if you do not have it. Homebrew is a free program that installs other programs. Its page gives one line to paste into Terminal.
- Run this line.
brew install poppler tesseract python
Windows
- Open PowerShell. Press the Windows key, type PowerShell, and press Enter.
- Run these three lines, one at a time.
winget install oschwartz10612.Poppler
winget install UB-Mannheim.TesseractOCR
winget install Python.Python.3.12
- Add tesseract to your PATH, which its installer does not do. Open Start, type "Edit environment variables for your account", and open it. Select Path, choose Edit, choose New, and enter
C:\Program Files\Tesseract-OCR. - Restart RStudio if it is open. If you work at a terminal, close PowerShell and open it again, so that it sees the new PATH.
Linux (Debian or Ubuntu)
Run this line in a terminal.
sudo apt install poppler-utils tesseract-ocr python3 python3-venv
If you already have some of these, check before you install. Run which pdftoppm tesseract python3 in Terminal on a Mac or Linux, or where.exe pdftoppm tesseract python in PowerShell on Windows. A program you have prints a path. On a Mac, brew install on a program you already have upgrades it and everything that depends on it, which can be a large download.
On a work computer of any kind, these installs may need your IT department. Ask for poppler, tesseract, and Python 3.10 or newer, and send them For your IT department, which lists each program, where it comes from, and what the rest of the install does.
2 Install extract-text
In RStudio, run these lines. They install extract-text, check that R can find Python, and then install the engine, the part of extract-text that reads the documents. You do this once per computer.
install.packages(c("remotes", "dplyr"))
remotes::install_github("evictionresearch/extract-text", subdir = "r")
library(extracttext)
# A check before the engine is installed. It should print the path of a
# Python, 3.10 or newer. NULL means R found none: go back to step 1,
# restart RStudio, and run this block again.
reticulate::virtualenv_starter(">=3.10")
extracttext_install()
The install, extracttext_install(), puts the engine in a folder of its own inside your user folder. It asks for no administrator password. It prints many lines as it works, and you can ignore them unless it ends with the word Error. On a fast connection it takes under a minute. It is finished when the Console shows "Done. Restart R, then run extracttext_doctor()." Restart R when it finishes, so the package finds the engine. In RStudio, choose Session, then Restart R. Then check your setup.
library(extracttext)
library(dplyr)
extracttext_doctor()
The last line of the checkup should be this one.
Ready: the deterministic engine can run.
The checkup lists poppler and tesseract with the folder it found each in. It reports Ollama as missing, and that is fine. Ollama belongs to the experimental AI engine, which these steps do not use. If the checkup says the Python engine is not installed, see If something goes wrong.
In the terminal, run these lines. They make a private Python environment for the engine, turn it on, and install extract-text into it. You do this once per computer. Python from Homebrew on a Mac, and from Debian or Ubuntu, refuses a plain pip install outside an environment like this one.
python3 -m venv ~/extract-text-env
source ~/extract-text-env/bin/activate
pip install "extract-text @ https://github.com/evictionresearch/extract-text/archive/main.zip#subdirectory=python"
On Windows, skip the first two lines. The Python that step 1 installs accepts the pip install line as it is. On a Mac or Linux, run the source line again in every new terminal window, before any extract-text command. Then check your setup.
extract-text doctor
The last line of the checkup should be this one.
Ready: the deterministic engine can run.
The checkup lists poppler and tesseract with the folder it found each in. It reports Ollama as missing, and that is fine. Ollama belongs to the experimental AI engine, which these steps do not use. If the terminal answers "command not found", see If something goes wrong.
The engine is a Python package, so the install is the same as at a terminal. Run these lines in a terminal window. They make a private Python environment for the engine, turn it on, and install extract-text into it. You do this once per computer. Python from Homebrew on a Mac, and from Debian or Ubuntu, refuses a plain pip install outside an environment like this one.
python3 -m venv ~/extract-text-env
source ~/extract-text-env/bin/activate
pip install "extract-text @ https://github.com/evictionresearch/extract-text/archive/main.zip#subdirectory=python"
On Windows, skip the first two lines. The Python that step 1 installs accepts the pip install line as it is. On a Mac or Linux, run the source line again in every new terminal window, before any extract-text command. The install also gives you the extract-text command, which steps 5, 6, and 8 use. Check your setup with it.
extract-text doctor
The last line of the checkup should be this one.
Ready: the deterministic engine can run.
The checkup lists poppler and tesseract with the folder it found each in. It reports Ollama as missing, and that is fine. Ollama belongs to the experimental AI engine, which these steps do not use.
Then start Python from that same terminal window, with python, or point your editor or notebook at ~/extract-text-env. If this line raises no error, Python has found the engine.
from extract_text import extract, scan
3 Read one example document
This downloads a made-up summons from the package's test files and reads it.
f <- file.path(tempdir(), "synthetic_summons_scanned.pdf")
download.file(paste0("https://raw.githubusercontent.com/evictionresearch/",
"extract-text/main/python/tests/fixtures/",
"synthetic_summons_scanned.pdf"),
f, mode = "wb")
# Open the summons, to compare with what the engine reads
browseURL(f)
one <- extract_deterministic(f)
# Expect 1234 EXAMPLE AVE S APT 5, Seattle, WA 98100
one$record$defendant_address
# Problems the engine found; empty means none
one$flags
curl -L -o synthetic_summons_scanned.pdf https://raw.githubusercontent.com/evictionresearch/extract-text/main/python/tests/fixtures/synthetic_summons_scanned.pdf
extract-text extract synthetic_summons_scanned.pdf
In PowerShell on Windows, type curl.exe in place of curl. The first line saves the summons in the folder the terminal is in, where you can open it to compare. The second prints everything the engine read. Look for this part, the defendants' address, and for "flags": [] near the end, which means the engine found no problem.
"defendant_address": {
"raw": "1234 EXAMPLE AVE S APT 5 SEATTLE, WA 98100",
"street": "1234 EXAMPLE AVE S APT 5",
"unit": "APT 5",
"city": "Seattle",
"state": "WA",
"zip": "98100"
},
from urllib.request import urlretrieve
from extract_text import extract
# Saves the summons in the folder Python is running in, where you can open
# it to compare with what the engine reads
f, _ = urlretrieve("https://raw.githubusercontent.com/evictionresearch/"
"extract-text/main/python/tests/fixtures/"
"synthetic_summons_scanned.pdf",
"synthetic_summons_scanned.pdf")
one = extract(f)
# Expect 1234 EXAMPLE AVE S APT 5, Seattle, WA 98100
one.record.defendant_address
# Problems the engine found; empty means none
one.flags
4 Scan a random 50 of your own documents
Start with a random sample, not the whole folder. It takes minutes, and you grade every document in it in the next step.
Which documents to put in the folder. The engine reads one document at a time and writes one row for every file, whatever kind of document the file is. Its rules are built for the summons. If your folder holds whole case files (complaints, orders, returns of service), a case gets a row for each of them. When the file names say which documents are summonses, scan those alone, by giving the scan a list of files in place of the folder.
summonses <- list.files(docs_dir, pattern = "summons", ignore.case = TRUE,
recursive = TRUE, full.names = TRUE)
Then give scan_documents() the list, summonses, in place of docs_dir.
extract-text scan DOCS/*summons* --engine deterministic --sample 50 --seed 1 --out RESULTS/sample
On a Mac or Linux, DOCS/*summons* names every file in the folder whose name holds "summons". The pattern minds capital letters and does not look in subfolders. PowerShell on Windows does not fill in such a pattern, so there, put the summonses in a folder of their own.
from pathlib import Path
summonses = sorted(p for p in Path(docs_dir).rglob("*")
if p.is_file() and "summons" in p.name.lower())
Then give scan() the list, summonses, in place of docs_dir.
If your documents are not from Washington. The rules that read the city and the state expect "WA" or "Washington" after the city. On a made-up Oregon summons and a made-up Texas one, the engine read the street, the unit, and the ZIP, left the city and state blank, and raised no flag. Every document you grade carries your city and state in the final table, and the others carry the street and ZIP alone. Documents from another state shows the four-line change that makes the engine read your state.
Practice first, on made-up documents. Steps 4 to 8 run on the package's 15 made-up documents as well as on real ones, so you can learn the grading page before you open a court record. The lines below download the package's code (about 10 MB) into a folder in your home directory. The documents are few and partly repeat one another, so the practice scores mean nothing. Delete the folder when you are done.
practice <- path.expand("~/extract_text_practice")
dir.create(practice, showWarnings = FALSE)
download.file(paste0("https://github.com/evictionresearch/extract-text/",
"archive/refs/heads/main.zip"),
file.path(practice, "extract-text.zip"), mode = "wb")
unzip(file.path(practice, "extract-text.zip"), exdir = practice)
docs_dir <- file.path(practice, "extract-text-main", "python", "tests",
"fixtures")
results <- file.path(practice, "results")
Run it, skip the docs_dir and results lines below, and go on from n_sample.
mkdir -p ~/extract_text_practice
cd ~/extract_text_practice
curl -L -o extract-text.zip https://github.com/evictionresearch/extract-text/archive/refs/heads/main.zip
unzip -q extract-text.zip
These four lines are for a Mac or Linux. On Windows, open that address in your browser, save the zip in a new folder, and unzip it there. Then, in every line from here on, type ~/extract_text_practice/extract-text-main/python/tests/fixtures in place of DOCS and ~/extract_text_practice/results in place of RESULTS.
from pathlib import Path
from urllib.request import urlretrieve
from zipfile import ZipFile
practice = Path.home() / "extract_text_practice"
practice.mkdir(exist_ok=True)
urlretrieve("https://github.com/evictionresearch/extract-text/"
"archive/refs/heads/main.zip",
practice / "extract-text.zip")
ZipFile(practice / "extract-text.zip").extractall(practice)
docs_dir = practice / "extract-text-main" / "python" / "tests" / "fixtures"
results = practice / "results"
Run it, skip the docs_dir and results lines below, and go on from n_sample.
You name two folders. The first holds your court documents (PDF or TIFF, subfolders included). If the documents come to you in a Google Drive folder, download the folder to your own computer first (Drive gives a zip; unzip it). The second is a new folder where everything from here on is written. Expect about 5 seconds a document when OCR is needed.
docs_dir is the documents folder and results the results folder. Type each path with forward slashes, on Windows too.
# Mac: "/Users/yourname/Documents/court_documents"
# Windows: "C:/Users/yourname/Documents/court_documents"
docs_dir <- "path/to/your/documents"
results <- "path/to/your/results"
n_sample <- 50
sample_dir <- file.path(results, "sample")
all_dir <- file.path(results, "all")
res <- scan_documents(docs_dir, engine = "deterministic", sample = n_sample,
seed = 1, out_dir = sample_dir)
When the scan finishes, count what came back.
res %>%
count(text_source,
found = defendant_street != "",
flagged = flags != "")
# A tibble: 3 × 4
text_source found flagged n
<chr> <lgl> <lgl> <int>
1 pdf_ocr FALSE TRUE 1
2 pdf_ocr TRUE FALSE 4
3 pdf_ocr TRUE TRUE 1
This example comes from six made-up documents, so your counts will differ. found says whether the engine read a street, and flagged says whether it raised a flag. pdf_ocr means the pages were scans read by OCR.
In this line and every one after it, type your documents folder in place of DOCS and your results folder in place of RESULTS. Put quotation marks around a path that has a space in it.
# Mac: /Users/yourname/Documents/court_documents
# Windows: C:/Users/yourname/Documents/court_documents
extract-text scan DOCS --engine deterministic --sample 50 --seed 1 --out RESULTS/sample
When the scan finishes, it prints the count of what came back.
scanned 6/6
6 documents scanned, 6 with a defendant street address, 0 flagged for review.
Results in RESULTS/sample/extracted.csv (and extracted.jsonl).
Grade it on the review page with: extract-text review --out RESULTS/sample --serve
This example comes from six of the package's made-up practice documents, so your counts will differ. extracted.csv is the table, one row per document. Step 5 adds --random 50 to the line the scan suggests, so that the page shows a random 50.
docs_dir is the documents folder and results the results folder. Type each path with forward slashes, on Windows too.
from extract_text import scan
# Mac: "/Users/yourname/Documents/court_documents"
# Windows: "C:/Users/yourname/Documents/court_documents"
docs_dir = "path/to/your/documents"
results = "path/to/your/results"
n_sample = 50
sample_dir = f"{results}/sample"
all_dir = f"{results}/all"
rows = scan(docs_dir, engine="deterministic", sample=n_sample, seed=1,
out_dir=sample_dir)
rows is a list with one dictionary per document, and the same table is saved as extracted.csv in the sample folder. When the scan finishes, count what came back.
from collections import Counter
Counter((r["text_source"], r["defendant_street"] != "", r["flags"] != "")
for r in rows)
Counter({('image_ocr', True, False): 4, ('pdf_ocr', True, False): 1, ('pdf_text_layer', True, False): 1})
This example comes from six of the package's made-up practice documents, so your counts will differ. Each entry gives how the text was read, whether the engine read a street, whether it raised a flag, and how many documents that describes. image_ocr and pdf_ocr mean the pages were scans read by OCR.
Keep both folders private. Your documents and every file written from this step on hold tenants' names and addresses. Keep them wherever your organization keeps the court documents themselves, and out of any folder that syncs or is shared (Dropbox, iCloud Drive, OneDrive, or a Google Drive folder that syncs to your computer).
5 Grade the sample, then score the engine
Grading is required. Until you grade a sample, you do not know how often the scan is right on your documents.
The line below opens a page in your browser that shows each document beside what the engine read. Check each field against the page, change only what is wrong, and leave a field blank when the document does not have it. Then look at the colored boxes on the page image, which show where the engine read each value. Drag a box that sits over the wrong place to the right one. Where a field has no box, press the field's button under the image and drag across the value. A box you draw is added to the ones already there, and a box in the wrong place is deleted with its cross. Save every document, even when the engine got everything right. The top of the page has the grading rules in brief, and its foot says what to do when you finish. Fifty documents take about an hour.
review_documents(res, correct = TRUE, n = n_sample, draw = "random")
You can stop at any point by pressing Esc in RStudio, and running the line again picks up where you left off.
extract-text review --out RESULTS/sample --random 50 --serve
The terminal waits while you grade. You can stop at any point by pressing Ctrl-C there, and running the line again picks up where you left off.
Steps 5, 6, and 8 have no Python function of their own. They use the extract-text command, which the install in step 2 put beside the Python package. Run it in a terminal window with the environment from step 2 turned on, and type your results folder in place of RESULTS.
extract-text review --out RESULTS/sample --random 50 --serve
The terminal waits while you grade. You can stop at any point by pressing Ctrl-C there, and running the line again picks up where you left off.
Read the whole script
- This video grades one made-up document on the review page.
- The page is on the left. On the right is what the rules engine read, above a form filled in with its answers.
- The colored boxes show where the engine found each value. Red marks the defendants and blue marks the address.
- Check each field against the page. Here the page prints the city as Sampleton.
- The rules engine misspelled it as Sampieton, so we correct it in the City box of the form.
- The top of the page names the defendants too. We pick Defendants.
- Then we drag a box over those names. Boxes like this teach the engine where the form prints each field.
- Our box is added to the page. The engine's own box, on the line addressed to the defendants, stays where it was.
- A box that sits in the wrong place can be deleted. Point at it and press its cross.
- We press Save. Save every document you check, even when the engine got everything right.
- The page confirms the save and notes that the engine was wrong on the city.
- Your answers stay in a file on your own computer. The full guide is GRADING.md.
Then score the engine against your answers.
score_documents(res)
field checked right near blank wrong
1 plaintiff 1 1 0 0 0
2 defendants 1 1 0 0 0
3 street 1 1 0 0 0
4 unit 1 1 0 0 0
5 city 1 0 0 0 1
6 state 1 1 0 0 0
7 zip 1 1 0 0 0
This example is the one made-up document graded in the video, where the engine misread the city. It is shortened to the main columns. With 50 graded documents, checked reads 50. The score has one row per field and counts how many documents the engine got right, nearly right (the right content written differently, such as Ave for Avenue), left blank, or got wrong. Two more columns, right_random and checked_random, give the accuracy estimate for the whole folder when you divide the first by the second.
extract-text score --out RESULTS/sample
Corrections in sample: 6 documents reviewed, 0 unreadable, 6 random
Scored against the scan as it is now in that folder.
Graded by yourname (6).
deterministic engine, share of fields right, then right or near (random rows alone in brackets)
plaintiff 100.0% 100.0% of 6 [100.0% of 6]
defendants 100.0% 100.0% of 6 [100.0% of 6]
street 83.3% 83.3% of 6 [83.3% of 6] wrong: 1 different
unit 66.7% 66.7% of 6 [66.7% of 6] wrong: 1 different, 1 blank
city 100.0% 100.0% of 6 [100.0% of 6]
state 100.0% 100.0% of 6 [100.0% of 6]
zip 83.3% 83.3% of 6 [83.3% of 6] wrong: 1 different
This example comes from six of the package's made-up practice documents, two of them graded with a correction. The score has one row per field. The first percentage is the share of graded documents the engine got right. The second adds those it got nearly right (the right content written differently, such as Ave for Avenue), and the number after "of" is how many you checked. The brackets hold the share right among the documents drawn at random, which is the accuracy estimate for the whole folder. The end of a row says how the wrong ones went wrong.
The score comes from the same command, in the terminal.
extract-text score --out RESULTS/sample
Corrections in sample: 6 documents reviewed, 0 unreadable, 6 random
Scored against the scan as it is now in that folder.
Graded by yourname (6).
deterministic engine, share of fields right, then right or near (random rows alone in brackets)
plaintiff 100.0% 100.0% of 6 [100.0% of 6]
defendants 100.0% 100.0% of 6 [100.0% of 6]
street 83.3% 83.3% of 6 [83.3% of 6] wrong: 1 different
unit 66.7% 66.7% of 6 [66.7% of 6] wrong: 1 different, 1 blank
city 100.0% 100.0% of 6 [100.0% of 6]
state 100.0% 100.0% of 6 [100.0% of 6]
zip 83.3% 83.3% of 6 [83.3% of 6] wrong: 1 different
This example comes from six of the package's made-up practice documents, two of them graded with a correction. The score has one row per field. The first percentage is the share of graded documents the engine got right. The second adds those it got nearly right (the right content written differently, such as Ave for Avenue), and the number after "of" is how many you checked. The brackets hold the share right among the documents drawn at random, which is the accuracy estimate for the whole folder. The end of a row says how the wrong ones went wrong.
Reading the score. Say the street row shows 43 right of 50 checked. The engine read the street right on 86 percent of your sample. Fifty documents is a small sample, so the share for the whole folder is probably between about 76 and 96 percent. Grade 100 or more before you publish counts or send anything to people.
Decide here whether the fields you need are accurate enough to scan everything. No score is right for everyone, so ask what the table is for. A count of filings by ZIP code can live with a street that is wrong one time in seven, and a mailing to tenants cannot. Look only at the fields you will use, and grade those with care, because a field you leave as the engine filled it is counted as right.
When a field you need is weak, there are three things to do.
- The engine looked in the wrong place. Its box sat over the wrong part of the page, or the field had no box. Step 6 can fix that for your court's forms, with no code.
- The box was in the right place and the value was still wrong. A rule has to change. Improve it shows how to tell us what goes wrong and how to change a rule on your own copy.
- Grade more. Whatever the score, every document you grade is right in the final table. For a small folder, grading all of it is a sound plan.
Your corrections do not change the engine's rules. They tell you which fields to trust, every document you grade carries your answer in the final table, and your boxes teach the engine your court's forms in the next step. How the rules improve says how the rules themselves get better.
6 Teach the engine your court's forms
This step is optional and needs no code. Courts print their own forms, and a form can put the tenant's address where the engine's rules do not look. The boxes you fixed and drew while grading show where your court's forms print each field. From them the package writes a template for each form that has at least five graded documents.
learn_templates(res)
# Opens a page showing each template over a page it was learned from
review_templates(res)
# Approve each template whose regions sit where the form prints that field
approve_template("form-1", res)
extract-text templates learn --out RESULTS/sample
# Writes a page showing each template over a page it was learned from, and
# prints where the page is. Open that file in your browser.
extract-text templates review --templates RESULTS/sample/templates --out RESULTS/sample
# Approve each template whose regions sit where the form prints that field
extract-text templates approve form-1 --templates RESULTS/sample/templates
These are terminal commands too.
extract-text templates learn --out RESULTS/sample
# Writes a page showing each template over a page it was learned from, and
# prints where the page is. Open that file in your browser.
extract-text templates review --templates RESULTS/sample/templates --out RESULTS/sample
# Approve each template whose regions sit where the form prints that field
extract-text templates approve form-1 --templates RESULTS/sample/templates
Nothing learned is used until you approve it. A template holds the form's printed words and a region of the page for each field. It holds no names or addresses.
Expect templates only for the forms your court uses most. A random 50 rarely holds five documents of a rare form, and the engine reads those with its rules alone. A template changes where the engine looks, not how it reads. Form templates says more.
7 Scan the whole folder and grade a second 50
The full run goes to its own folder, so the sample and its corrections stay as they are. It uses the templates you approved in step 6, and the rules alone if you approved none. It needs no attention while it runs. At about 5 seconds a document, 4,000 documents take five or six hours.
templates_dir <- file.path(sample_dir, "templates")
use_templates <- dir.exists(templates_dir) &&
any(list_templates(templates_dir)$approved)
res_all <- scan_documents(docs_dir, engine = "deterministic", out_dir = all_dir,
templates = if (use_templates) templates_dir)
# Leave off --templates and what follows it if you approved none in step 6
extract-text scan DOCS --engine deterministic --out RESULTS/all --templates RESULTS/sample/templates
# If you approved a template in step 6
rows_all = scan(docs_dir, engine="deterministic", out_dir=all_dir,
templates=f"{sample_dir}/templates")
# If you approved none
rows_all = scan(docs_dir, engine="deterministic", out_dir=all_dir)
Run one of the two. The first stops with an error when the folder holds no approved template, so that a run without templates is never mistaken for one with them.
The first sample told you whether to run everything. A second sample measures the run that becomes your table, templates included. A document you already graded may come up again; grade it again, and the later answer is the one kept.
review_documents(res_all, correct = TRUE, n = n_sample, draw = "random", seed = 1)
score_documents(res_all)
extract-text review --out RESULTS/all --random 50 --serve
extract-text score --out RESULTS/all
Grade and score in the terminal, as in step 5.
extract-text review --out RESULTS/all --random 50 --serve
extract-text score --out RESULTS/all
The share right in this score is the accuracy of the full run. Report it with the table.
You can also fix every document the engine flagged, so the table carries a person's answer wherever the engine was unsure.
review_documents(res_all, correct = TRUE, n = sum(res_all$flags != ""),
draw = "flagged")
extract-text review --out RESULTS/all --n 200 --serve
Without --random, the page shows flagged documents first. --n is how many documents it shows, 30 if you leave it off, so give it a number at least as large as the count of flagged documents the scan printed.
extract-text review --out RESULTS/all --n 200 --serve
Without --random, the page shows flagged documents first. --n is how many documents it shows, 30 if you leave it off, so give it a number at least as large as the count of flagged documents the scan printed.
8 Build the final table
cases <- case_table(res_all, graded = sample_dir,
save = file.path(results, "case_table.csv"))
# How many rows carry a graded answer, and how many the engine's reading
count(cases, source)
# A tibble: 2 × 2
source n
<chr> <int>
1 engine 5
2 graded 1
In this example, from six made-up documents, one row carries a graded answer and five carry the engine's reading.
extract-text case-table --out RESULTS/all --graded RESULTS/sample --save RESULTS/case_table.csv
Table saved to RESULTS/case_table.csv
Documents in the table: 15 (9 engine, 6 graded)
In this example, from the package's 15 made-up practice documents, six rows carry a graded answer and nine carry the engine's reading.
The table is built by a terminal command.
extract-text case-table --out RESULTS/all --graded RESULTS/sample --save RESULTS/case_table.csv
Table saved to RESULTS/case_table.csv
Documents in the table: 15 (9 engine, 6 graded)
In this example, from the package's 15 made-up practice documents, six rows carry a graded answer and nine carry the engine's reading.
To go on working with the table in Python, read the file.
import csv
with open(f"{results}/case_table.csv", newline="", encoding="utf-8") as f:
cases = list(csv.DictReader(f))
The table has one row per document, with the case number, the plaintiff, the defendants, and the defendants' address. Your graded answers from both samples replace the engine's wherever you gave one, and the source column says which each row carries. The table is saved as case_table.csv in your results folder.
Go further
- The R script.
getting_started_example_script.Rholds the R code of every step on this page in one file. - When to scan again. Grading does not change the engine, so scan again only after you update the package, change a rule, or approve a template. Start here says more.
- The whole procedure on one page. Start here gives the same steps in plain words, and ends with all eight as terminal commands and as Python.
- Make the engine read your documents better. Improve it shows how to tell us what goes wrong, with no programming, and how to change the rules on your own copy.
- More on form templates. The guide is the last chapter of Changing the rules.
- Try the local AI engine. It is experimental: it runs, but its test against hand-labeled documents is not finished. It needs about 16 GB of memory. Section 6 of the manual has the two steps.
- Read the manual. The manual covers every output column, the flags, and how to use the package outside Washington.
If something goes wrong
Run the checkup first. extracttext_doctor() in R, or extract-text doctor at a terminal, looks at your computer and prints the command for anything missing.
In R, the checkup says "The Python engine is not installed yet." Restart R and run it again. If the message stays, the install in step 2 stopped early, most often because Python was missing or older than 3.10. Run the Python check in step 2 and fix what it shows. Then remove the half-built environment with reticulate::virtualenv_remove("r-extracttext") and run extracttext_install() again.
If the install finished and the message still stays, something has told R to use another Python. In a fresh R session, point R at the engine's own environment before anything else, then run the checkup.
library(extracttext)
reticulate::use_virtualenv("r-extracttext", required = TRUE)
extracttext_doctor()
At a terminal, extract-text gives "command not found". The environment from step 2 is not turned on in this window. On a Mac or Linux, run source ~/extract-text-env/bin/activate and try again.
Something else. Open an issue at github.com/evictionresearch/extract-text/issues, or write to evictions@berkeley.edu.
Never paste a real document, name, address, or case number into an issue or an email. Describe the problem, or reproduce it with the made-up example document from step 3.