Pipeline for processing books and other long documents, including:
The main executable class is novels/BooksNLP. runjava is a convenience wrapper for executing java (taking care of the classpath, memory, etc.). To run, execute ./runjava novel/BooksNLP with the relevant flags below.
Download external jars (which are sadly too big for GitHub's 100MB file size limit)
-doc
-tok : file path to save processed tokens to (or read them from, if it already exists)
-p : the path to write all diagnostic files to
-id : a unique book ID for this book
-printHTML : print the text as an HTML file with character aliases, coref and speaker ID annotated
-f : force the processing of the original text file, even if the in the -tok flag exists (if the -tok exists, the process that would generate it is skipped)
./runjava novels/BookNLP -doc originalTexts/dickens.oliver.pg730.txt -printHTML -p output/dickens -id dickens.oliver.twist -tok tokens/dickens.oliver.tokens -f
(On a 2.6 GHz MBP, this takes about 3.5 minutes)
tokens/dickens.oliver.tokens contains the original book, one token per line, with part of speech, syntax and other annotations. The (tab-separated) format is:
The output/dickens folder will now contain:
With apache ant installed, running ant compiles everything.
Coreference only needs to be trained when there's new training data (or new feature ideas: current features are based on syntactic tree distance, linear distance, POS identity, gender matching, quotation scope and salience).
Coreference annotated data is located in the coref/ directory.
annotatedData.txt contains coreference annotations, in the (tab-separated) format:
bookIDs are mapped to their respective token files in docPaths.txt. All of these token files are located in finalTokenData/. These tokens files are all read-only -- since the annotations are keyed to specific token IDs in those files, we want to make sure they stay permanent.
Given the coref/ folder above, train new coreference weights with:
./runjava novels.training/TrainCoref -training coref/annotatedData.txt -o coref/weights.txt
-training specifies the input training file
-o specifies the output file to write the trained weights to
Two parameters control the amount of regularization in the model (higher regularization dampens the impact of any single feature, and L1 regularization removes features from the model; both help prevent overfitting to training data.)
-l1 specifies the L1 regularization parameter (higher = more weights end up driven to 0). Default = 2
-l2 specifies the L2 regularization parameter (higher = weights shrink faster). Default = .1
To use the newly trained weights in the pipeline above, copy them to files/coref.weights or specify them on the novels.BookNLP command line with the -w flag.
Quotation/Speaker Id is currently deterministic (matching nearby character mentions); but with more annotated training data, this can become a log-linear model as well.
$ claude mcp add book-nlp \
-- python -m otcore.mcp_server <graph>