More tuning data
Continuing with the discipline of investing in hand-labeled evaluation data, I doubled the amount of tuning data examples available in each of the six error categories. The base text for the new batch is Isaac Asimov's novel Second Foundation, the third of the Foundation Trilogy, pulled from archive.org.
I re-ran tuning using the new double-sized tuning data to check whether it changed the performance. The original tuning data was all based on Frankenstein, perhaps the earliest example of full-fledged science fiction, and the language and punctuation in it is archaic in places. Asimov wrote mid-20th century in a style that is closer to what would be expected in a modern high school English class.
Here's the head-to-head overall performance, across alphabet size of tokenizers
| version | alphabet | old tuning data | expanded tuning data |
|---|---|---|---|
| 046 precision recall f-score |
20k | 0.48 0.39 0.41 |
0.42 0.42 0.42 |
| 022 precision recall f-score |
10k | 0.55 0.39 0.43 |
0.65 0.29 0.36 |
| 025 precision recall f-score |
5k | 0.47 0.38 0.40 |
0.66 0.21 0.28 |
| 028 precision recall f-score |
2k | 0.42 0.38 0.39 |
0.59 0.29 0.35 |
| 019 precision recall f-score |
1k | 0.50 0.27 0.32 |
0.50 0.27 0.32 |
| 031 precision recall f-score |
500 | 0.33 0.32 0.33 |
0.51 0.20 0.25 |
| 034 precision recall f-score |
200 | 0.34 0.20 0.23 |
0.47 0.12 0.16 |
The F-scores are flat or down in every case, so that is disappointing at first glance. But a closer look shows that precision is up in the majority of cases, sometimes by quite a bit. This is the big win here. Precision is the more valuable metric in these component models. Recall (and F-score) can go up by combining different models, but precision sets the ceiling.
Compared across tokenizer settings at the 10k alphabet size, there is a similar pattern.
| version | tokenizer | old tuning data | expanded tuning data |
|---|---|---|---|
| 022 precision recall f-score |
no normalization | 0.55 0.39 0.43 |
0.65 0.29 0.36 |
| 049 precision recall f-score |
byte-pair encoding (BPE) | 0.60 0.39 0.44 |
0.54 0.42 0.45 |
| 052 precision recall f-score |
split by whitespace | 0.53 0.32 0.37 |
0.60 0.23 0.29 |
| 055 precision recall f-score |
NFKC normalization | 0.59 0.40 0.45 |
0.54 0.41 0.44 |
| 058 precision recall f-score |
NFKC + case folding | 0.38 0.38 0.38 |
0.57 0.24 0.30 |
| 061 precision recall f-score |
NFKC + BPE | 0.55 0.45 0.48 |
0.59 0.35 0.41 |
F-scores are flat or down, but precision goes up more often than not. Taken together, this builds confidence that enriching the tuning data set results in component models with higher precision. (Tentatively, there also appears to be a little bit more structure to the α, β, and error threshold parameters, but it's still early to say whether the patterns there will settle into something stable.)
Combining models with different alphabet sizes
The strong collection of performance numbers, especially precision, across the combined forward/backward models at so many different vocabulary sizes suggests that there is a big performance jump to be had if I can combine models that use tokenizers with different vocabularies. In order to do this, I need to reduce them to a shared representation of the text. I need each model to flag its detected errors based on their character locations within the text, rather than the token number.
After making this change to the innards of the proofreader (and writing some tests to catch all my bugs), I was able to verify that the results in the previous tables are unchanged. This made the combination of models with different alphabet size tokenizers straightforward. I started with the smallest and worked up, adding one at a time.
| version | alphabet sizes | overall |
|---|---|---|
| 062 precision recall f-score |
200, 500 | 0.52 0.23 0.29 |
| 063 precision recall f-score |
200, 500, 1k | 0.48 0.33 0.37 |
| 064 precision recall f-score |
200, 500, 1k, 2k | 0.49 0.42 0.44 |
| 065 precision recall f-score |
200, 500, 1k, 2k, 5k | 0.49 0.47 0.48 |
| 066 precision recall f-score |
200, 500, 1k, 2k, 5k, 10k | 0.50 0.52 0.52 |
| 067 precision recall f-score |
200, 500, 1k, 2k, 5k, 10k, 20k | 0.40 0.59 0.51 |
As expected, precision acted roughly as a ceiling. I added in the models with the lowest precision last (20k alphabet), and they predictably drug the overall precision down with them. Recall, however, only continued to climb. Adding each new model pair bumped recall appreciably, suggesting that each model helps catch blind spots in the others.
It's also worth celebrating that, for the first time here, we've achieved an F-score over one-half! While there is still a way to go, I'm comfortable declaring that this approach has moved from "quirky idea" staus to "clunky prototype".
Combining other tokenizers
In a fantastic stroke of good fortune, I checked and discovered that all of the different tokenzer variants we've been working with keep the token size consistent, so when those tokens get concatenated, they form a string with exactly as many characters as the original text. This is great! It means that we won't have to do any special registration or shifting to get the outputs from these tokenizers to line up with each other, and they are ready to be calcualted and combined.
I started with the byte-pair encoding tokenizer. Here are the the paired forward/backward models at each alphabet size.
| version | alphabet size | overall |
|---|---|---|
| 069 precision recall f-score |
20k | 0.63 0.33 0.40 |
| 049 precision recall f-score |
10k | 0.52 0.38 0.42 |
| 070 precision recall f-score |
5k | 0.53 0.38 0.42 |
| 071 precision recall f-score |
2k | 0.58 0.32 0.38 |
| 072 precision recall f-score |
1k | 0.69 0.19 0.25 |
| 073 precision recall f-score |
500 | 0.70 0.17 0.22 |
| 074 precision recall f-score |
200 | 0.58 0.16 0.21 |
The precision of BPE tokenizers is adequate (>0.5) or exceptional (>0.6) at every alphabet size, which means all of these can be folded into a proofreader. Combining them one by one shows how they build on each other.
| version | alphabet sizes | overall |
|---|---|---|
| 075 precision recall f-score |
200, 500 | 0.59 0.24 0.30 |
| 076 precision recall f-score |
200, 500, 1k | 0.59 0.30 0.36 |
| 077 precision recall f-score |
200, 500, 1k, 2k | 0.53 0.40 0.44 |
| 078 precision recall f-score |
200, 500, 1k, 2k, 5k | 0.50 0.52 0.51 |
| 079 precision recall f-score |
200, 500, 1k, 2k, 5k, 10k | 0.46 0.58 0.53 |
| 080 precision recall f-score |
200, 500, 1k, 2k, 5k, 10k, 20k | 0.45 0.62 0.55 |
This progression behaves mostly as expected. Recall increases with every new model added to the ensemble. However, the precision doesn't follow the rule of thumb we've been working with so far. The final precision of 0.45 is noticeably lower than the precision of any of the individual models.
This destructive effect on precision during combination hasn't been observed quite so clearly before. It appears to be due to the fact that some models in the ensemble have similar sets of true positives, but less-overlapping sets of false positives. When this happens, the recall may go up slightly, but the precision can drop by quite a bit. This behavior means that we can no longer assume that precision will hover near the lesser of the two. It can drop well below either.
Combining Identity and BPE tokenizers
Now that the multiple alphabet sizes of separate tokenizer types have been combined, we can experiment with combining them further, mixing tokenizer types. To combat precision degradation, only tokenizer pairs with precision >0.55 were kept for the ensemble. This means that the 10k alphabet tokenizer was dropped from the BPE collection, and the only identity tokenizers kept were the 5k and 10k alphabet sizes.
| version | tokenizers | overall |
|---|---|---|
| 084 precision recall f-score |
identity: 5k, 10k | 0.59 0.41 0.45 |
| 085 precision recall f-score |
BPE: 200, 500, 1k, 2k, 20k | 0.55 0.55 0.55 |
| 086 precision recall f-score |
0.52 0.63 0.59 |
The precision of the resulting ensemble was 0.52, less than the 0.59 and 0.55 of either tokenizer type, but still over the target of 0.5. And the recall was a 0.63, a healthy combination of 0.41 and 0.55 of the two tokenizer types. The F-score was a best yet of 0.59. Almost 0.6! This is really getting somewhere.
Breaking the score down by error type
The high score gets even more interesting when separated out into its separate categories.
| version | capitalization | extra words | grammar | missing words | punctuation | spelling | overall |
|---|---|---|---|---|---|---|---|
| 086 precision recall f-score |
0.48 0.62 0.57 |
0.78 0.84 0.82 |
0.20 0.44 0.32 |
0.63 0.58 0.60 |
0.46 0.50 0.49 |
0.58 0.78 0.70 |
0.52 0.63 0.59 |
A few aspects are striking. Most notable is that grammar precision is abysmal at 0.2. Out of every 5 errors reported in the grammar evals, only one is real. This may reflect the fact that grammatical word selection often depends on words that are far removed and on abstract notions, such as singular/plural an past/present/future. These would be naturally challenging for a first-order Markov model that focus on a snall neighborhood.
Another thing that pops out is that spelling and extra words both have relatively high recall, in the neighbhorhood of 0.8. These are both types of errors that can be detected locally, without knowing much about the words that come before or after.
There is an implicit assumption in the eval and tuning data at the moment, that each of these six error types occurs roughly equally and are of equal concern. This is almost certainly inaccurate. This balance can vary considerably, depending on the text being scanned and the intent of the user, but it is a reasonble starting place for a general purpose evaluation.
A fork in the road: Traditional machine learning vs. Artisanal
This is a great time to stop and find ourselves on the map and figure out where we want to go from here. We've learned some really useful tricks and come out with not-ridiculous baseline proofreading model. There are a couple of ways to take the project from here.
On the right fork is the traditional machine learning approach: scale up, optimize, and generate variants. Namely:
Train on more data
The Project Gutenberg data set that proofreader's models are tuned on is pathetically small compared to corpuses used to train commercial LLMs.
Generate more models
We've only scratched the surface of first-order Markov model variants that could be included in the ensemble. And while we briefly experimented with second-order models, that is another avenue to go back to and explore. (In fact second-order Markov models with large and variable skips is a very rough approximation of how transformers work, the engine behind LLMs.)
With the benefit of a narrow field of application, we could also pursue domain specific models and features, like incorporating part-of-speech taggers and rule-based grammar checkers.
Optimize ensemble contruction
The proofreader ensemble performance is quite sensitive to which models are included, and each permutation produces a somewhat unpredictable overall performance. Solving this problem perfectly is capital-H hard, but solving it pretty OK is something that we could dive into. Heuristics, like greedy agglomerative (adding in new models one at a time) or ablative (removing models one at a time) ensemble construction could juice more performance out of a set of models, once it gets too big to try every possible combination.
Scale up compute
Of course, most of these options would require using more computational power, maybe millions of times more. They would also end up needing more sophisticated ML operations tools, automated training and deployment workflows, the involvement of vendors to support these, and a large bag of cash.
or...
The left fork is the artisanal approach, in this case, keeping the model small and manageable so that it can stay nimble and adapt to the human who is using it. An artisanal model, living on someone's personal computer, is free to adapt wholly to that user, without having to worry about being all things to all people.
This is where we'll start heading in the next post.