Versions tested. Tribuotribuo-classification-sgd4.3.2 (the latest GA on Maven Central on 2026-12-01; the metadata was last updated 2025-04-08) and Smilesmile-core7.3.0 (metadata last updated 2026-11-16), on Temurin JDK 25.0.5.1 with Maven 3.9.11 and JUnit 6.1.3. Versions were read frommaven-metadata.xml, not from a blog. Smile 7.3.0’s bytecode needs Java 25; Tribuo 4.3.2’s needs Java 8. The measurement is in the class-file transcript.
Two limits you should know before reading a single number. First, the 3,000 tickets are synthetic: a seeded generator wrote them, so every figure here measures the harness, not what you will get on your own tickets. Second, no language model was called while this module was written, so there is no LLM accuracy figure anywhere in this post. The zero-shot client is tested against a local fake endpoint that proves the request shape and the reply handling, nothing more. If someone shows you an accuracy number for an LLM from this module, it is not from here.
A classifier is a function from words to a label, and training is how it gets its weights
Strip the vocabulary away and a text classifier does four small things. It cuts the text into words. It turns the words into a list of counts, one slot per word the model knows. It multiplies those counts by weights it learned earlier, which gives one score per category. It answers with the category whose score is highest. The only step that ever changes the weights is training: show the model a ticket with its recorded label, see whether the scores agreed, nudge the weights, repeat a few thousand times.
Logistic regression keeps one weight per word per category and learns them by repeated nudging. Naive Bayes skips the nudging: it just counts how often each word appears in each category and turns the counts into probabilities. That is why it trains in milliseconds and why it is a sensible first thing to try.
The diagram is the whole module in one line. Everything that follows is a different way of filling the amber box, and a different way of being wrong about it. Every contender implements one three-method contract so the harness measures them identically; the interface is in TextClassifier.java.
public interface TextClassifier {
String name();
void train(List<Ticket> train);
Category predict(String text);
}
Go deeper: why predict() is allowed to return null
The Javadoc on predict says it returns null when the model has no basis to answer, and Metrics.java counts that as wrong rather than skipping the ticket. That decision came from a failure found while writing the drift test, described in the section on unseen words below. A harness that silently drops the tickets a model cannot answer will report a better accuracy than the model deserves.
- scikit-learn: metrics and scoring — the clearest short reference for accuracy, precision, recall and F1.
- Measuring RAG retrieval quality in Java — the same discipline of a golden dataset and a failing build, applied to retrieval.
The test: five categories and 3,000 tickets I made up
The categories are BILLING, ACCESS, BUG, FEATURE and CANCEL. A seeded generator, TicketGenerator.java, writes each ticket from an opener, one core complaint, a sentence of context and a closer. To keep it from being trivially easy, 15% of tickets carry a second complaint from a different class, 12% have a typo, and 3% have a randomly wrong label, which is what human labelling noise looks like. The same seed always produces the same tickets, and a test asserts that. The split is stratified, so each class keeps the same share in train and test; the counts come straight from the dataset transcript.
## Class counts
class train test
BILLING 474 118
ACCESS 474 118
BUG 484 121
FEATURE 485 121
CANCEL 484 121
total 2401 599
Those 3% of random labels set a ceiling. A label drawn at random from five categories is wrong four times in five, so about 2.4% of tickets (0.03 × 0.8) have a label no model can match. That is back-of-envelope arithmetic, not a measurement, but it means a score near 97.6% would be perfect here and nothing above it is real.
Go deeper: the knobs on the generator
The generator takes an Options record: a seed, a count, relative class weights, the cross-complaint rate, the typo rate, the label-noise rate and a drift flag. The tests turn those knobs to build the skewed set and the drifted set used later, so every pitfall in this post is one changed argument away from the baseline. Real tickets are messier, longer and written by people who do not read your category list. Treat the generator as a way to make a failure reproducible, never as a stand-in for your data.
- TicketGenerator.java — the phrase pools and the noise.
- Splits.java — the stratified split and the duplicate check.
Tribuo: the smallest thing that works
Tribuo is Oracle Labs’ machine-learning library for Java. It wants three things: text turned into an Example (a bag of named features plus a label), a MutableDataset to hold the examples, and a trainer. The extractor, built from a tokeniser and an n-gram size of 1, turns a string into an Example; LogisticRegressionTrainer fits the model. This is the core of TribuoClassifier.java.
private final LabelFactory labels = new LabelFactory();
private final TextFeatureExtractor<Label> extractor =
new TextFeatureExtractorImpl<>(new BasicPipeline(new BreakIteratorTokenizer(Locale.US), 1));
private org.tribuo.Model<Label> model;
private MutableDataset<Label> trainingSet;
@Override public void train(List<Ticket> train) {
trainingSet = dataset(train);
model = new LogisticRegressionTrainer().train(trainingSet);
}
Building the dataset is a loop that extracts one Example per ticket. The text is normalised first, for a reason explained in the box below the code.
public MutableDataset<Label> dataset(List<Ticket> tickets) {
MutableDataset<Label> ds = new MutableDataset<>(new SimpleDataSourceProvenance("tickets", labels), labels);
for (Ticket t : tickets) {
ds.add(extractor.extract(new Label(t.label().name()), normalise(t.text())));
}
return ds;
}
On the 599 test tickets this model gets 0.9232 accuracy; the full table is in the scoreboard below and in 02-models.txt. A test also asks Tribuo’s own LabelEvaluator for the same numbers and asserts they match the harness’s, so the harness is not grading itself with a ruler it made up.
## Tribuo's own evaluator against ours
Tribuo LabelEvaluator accuracy : 0.9232
harness Metrics accuracy : 0.9232
Tribuo LabelEvaluator macro F1 : 0.9233
harness Metrics macro F1 : 0.9233
Go deeper: why the text is normalised before Tribuo sees it
The Javadoc on normalise in the source explains it: left alone, BasicPipeline with a BreakIteratorTokenizer turns punctuation such as “.” “,” and “!” into features. I saw that by printing an Example while writing the module; that scratch run is not a committed transcript, so take it as an observation rather than a verified claim. The fix is to hand Tribuo exactly the tokens the Smile models see, so the comparison is about the libraries and not about the tokenisers.
private static String normalise(String text) {
return String.join(" ", Tokens.of(text));
}
That one-liner lives in the same file as the classifier, and Tokens.of is a lower-case, letters-and-digits splitter in Tokens.java.
- tribuo.org — the project’s documentation and tutorials.
- Running ONNX models in Java — the neural alternative: a pre-trained sentiment model instead of one you train.
Smile: the same job in a different shape
Smile has no text pipeline of its own to configure here. You build a vocabulary yourself, and its BagOfWords turns a string into an array of counts, one slot per vocabulary word. SmileClassifiers.java holds both Smile contenders. The vocabulary keeps words seen at least twice in training, so a typo that appears once never becomes a column.
vocab = vocabulary(train, 2);
bow = new BagOfWords(Tokens::of, vocab);
double[][] x = new double[train.size()][];
int[] y = new int[train.size()];
for (int i = 0; i < x.length; i++) {
x[i] = toDouble(bow.apply(train.get(i).text()));
y[i] = train.get(i).label().ordinal();
}
model = LogisticRegression.fit(x, y);
Naive Bayes uses the same BagOfWords but skips the optimiser: new DiscreteNaiveBayes(DiscreteNaiveBayes.Model.MULTINOMIAL, Category.values().length, vocab.length) followed by model.update(x, y) on the integer counts. It is the shortest path from tickets to a working classifier in either library.
Go deeper: dense arrays, and the Java 25 bytecode
LogisticRegression.fit takes a dense double[][]. With a vocabulary of a few hundred words that is fine; with a real vocabulary of tens of thousands the matrix is mostly zeros, and Smile ships a SparseLogisticRegression that takes a SparseDataset instead (I confirmed both signatures with javap, and did not benchmark the sparse one). Separately, Smile 7.3.0’s classes are compiled for Java 25, which matters if your production JVM is older: a project pinned to Java 17 or 21 cannot load them.
class-file major version 52 = Java 8, 61 = Java 17, 65 = Java 21, 69 = Java 25
Tribuo 4.3.2 org.tribuo.Model major 52 (Java 8)
Smile 7.3.0 smile.classification.Maxent major 69 (Java 25)
That output is from 10-class-file-versions.txt, written by a test that reads the class-file header of one class from each jar.
- Smile documentation — the classification and feature-extraction guides.
- Code-search MCP server with embeddings — when you want meaning rather than word counts, embeddings are the next step.
The scoreboard: three classic models, one baseline, one split
All four contenders train on the same 2,401 tickets and are scored on the same 599. The baseline always answers the commonest training label, which is the floor any real model has to clear. Here is the transcript, trimmed to the table.
model accuracy macro-F1 train ms median us p99 us model KB
Majority-class baseline 0.2020 0.0672 5 0.1 0.4 -
Tribuo LogisticRegression (SGD) 0.9232 0.9233 1141 13.9 93.2 58.9
Smile LogisticRegression 0.9182 0.9182 2796 7.3 45.2 10.1
Smile DiscreteNaiveBayes 0.9048 0.9049 49 7.5 31.9 16.9
The picture says one thing: all three real models are far above the baseline and close to each other. The gap from Tribuo’s 0.9232 to Smile logistic regression’s 0.9182 is three tickets (553 against 550 right), and to naive Bayes it is 11 (542). On 599 test tickets the sampling error alone is about two percentage points either way, again by back-of-envelope arithmetic, so none of these three beats another. Pick on the other columns: Smile naive Bayes trained in 49 ms against over a second for the others, and Smile’s logistic regression wrote the smallest model file, 10.1 KB. Those timings come from one run on a machine that was running other jobs at the same time, so read them as an order of magnitude, not a ranking. Accuracy and F1 are deterministic; the timing columns are not.
Go deeper: where Tribuo’s 46 mistakes went
A confusion matrix has one row per true category and one column per predicted one; the diagonal is right, everything else is a mistake. This one is from 03-confusion-tribuo.txt.
actual\pred BILLING ACCESS BUG FEATURE CANCEL
BILLING 108 1 3 2 4
ACCESS 1 111 3 2 1
BUG 1 1 116 1 2
FEATURE 2 4 5 107 3
CANCEL 1 4 5 0 111
The errors are spread thinly rather than piled into one pair of classes, which is what you would expect when the mistakes come from noise and cross-complaints rather than from two categories that genuinely overlap. If your matrix shows one hot off-diagonal cell, that pair of categories needs a clearer definition before it needs a better model.
- Metrics.java — accuracy, per-class precision, recall, F1 and the matrix, computed once for every contender.
Accuracy lies when one class is rare
Real ticket queues are not balanced. Most tickets are about billing; very few are cancellations, and cancellations are exactly the ones you cannot afford to miss. Accuracy counts every ticket equally, so a model can look good while failing the rare class entirely. Macro-F1 is the fix: it scores each category on its own, then averages them without weighting by size, so a class with 2% of the tickets counts as much as one with 55%.
The imbalance transcript regenerates the data with the mix 55% billing, 25% access, 12% bug, 6% feature and 2% cancel. A model that always says BILLING now clears 50% accuracy while understanding nothing.
model accuracy macro-F1 CANCEL recall
Majority-class baseline 0.5308 0.1387 0.000
Tribuo LogisticRegression (SGD) 0.9318 0.9083 0.800
The baseline’s 0.5308 accuracy sounds respectable; its macro-F1 of 0.1387 tells the truth. Tribuo’s macro-F1 is lower than its accuracy, and its recall on CANCEL is 0.800, meaning one cancellation in five was missed. That is the number to watch, and a test asserts the baseline’s accuracy is above 0.5 while its macro-F1 stays under 0.2, so the demonstration cannot quietly stop being true.
Go deeper: what to do about a rare class
Report per-class recall for the categories that matter and set the acceptance bar on those, not on the average. Beyond that, the usual levers are collecting more examples of the rare class, weighting it more heavily during training (Tribuo’s MutableDataset has a setWeights method for this; I did not run it here), and moving the decision threshold so the model answers CANCEL more readily at the cost of more false alarms.
- scikit-learn: metrics and scoring — macro, micro and weighted averages explained.
- PitfallsTest.java — the test that builds the skewed set.
Your test set may already be in your training set
Support tickets repeat. Customers paste the same error and use the same stock phrases, so a random split often puts a ticket in the test set that is word-for-word identical to one in training. The model has not generalised on those; it has memorised them. In this data, the duplicates transcript finds 122 of the 599 test tickets, about a fifth, already present in training once case and spacing are ignored.
test tickets also in train : 122 accuracy 0.9836
test tickets never seen : 477 accuracy 0.9078
whole test set : 599 accuracy 0.9232
The headline 0.9232 is an average of two very different populations. On tickets the model has seen the score is 0.9836; on tickets it has not, it is 0.9078. If production traffic is mostly new wording, the second number is the one to plan around. Deduplicate before you split, or at least report both.
Go deeper: how the duplicate check works
Splits.key lower-cases the text and collapses whitespace, so “Hi team” and “hi team” are the same ticket. testSeenInTraining and testUnseen partition the test set on that key. Real data needs a looser notion of duplicate, such as the same text with a different order number, and a hash over the tokens with digits removed is a reasonable next step.
- Splits.java —
key,testSeenInTraining,testUnseen.
When customers change their wording, a classic model fails quietly
A trained classifier knows only the words it was shown. If your product ships passkeys next quarter and customers start writing “my passkey is not recognised”, the model has no weight for “passkey” and nothing to go on. The drift transcript trains on the normal set and tests on 1,000 new tickets in which ACCESS and BUG use new wording: passkey, magic link, device verification, “the new editor glitches”, “the widget flickers”, “the sync spinner”.
model normal drifted ACCESS rec. BUG rec.
Tribuo LogisticRegression (SGD) 0.9232 0.6990 0.580 0.172
Smile LogisticRegression 0.9182 0.6970 0.488 0.263
Smile DiscreteNaiveBayes 0.9048 0.7190 0.605 0.239
All three lose more than twenty points, and the damage is not spread evenly: Tribuo recalls only 0.172 of the BUG tickets. Only two of the five classes changed their wording, and the other three are as easy as before, so the overall figure understates how bad it is for the classes that moved. A zero-shot language model reads “passkey” without ever having seen your tickets, which is the one place in this post where it has a structural advantage. This module does not measure how large that advantage is; that is exactly the experiment the client below is for.
Go deeper: what to do about drift
Three practical defences. Monitor the share of incoming tickets that contain few or no known words, because that share rises before accuracy visibly falls. Keep a small, freshly labelled sample every month and score the live model on it. And retrain on a schedule: training takes a second on this data, so the expensive part is the labelling, not the compute. The unseen-word case is the extreme end of drift, and it is handled differently by each library, as the next section shows.
- PitfallsTest.java — the drift test and its 0.05 assertion.
A ticket made only of new words gets three different answers
The extreme form of drift is a ticket in which not one word was in the training data. Writing the drift test exposed a crash: Smile’s naive Bayes threw an ArrayIndexOutOfBoundsException on “Device verification loops forever.” The no-known-words transcript calls each library directly on that ticket and records what comes back.
Tribuo LogisticRegression raw : throws IllegalArgumentException: No features found in Example ArrayExample(...)
Smile LogisticRegression raw : returns class index 1 (ACCESS), a guess from the intercepts alone
Smile DiscreteNaiveBayes raw : returns -2147483648 (Integer.MIN_VALUE, not a class index)
harness wrappers (predict) : null / null / null (null = no answer, counted as wrong)
Three libraries, three behaviours, and only one of them is an honest one. Tribuo refuses and throws. Smile’s logistic regression silently answersACCESS, a guess dressed as a prediction, so a service built on it would route every unrecognisable ticket to the access team with no warning. Smile’s naive Bayes returnsInteger.MIN_VALUE, which becomes a crash the moment you use it as an array index. The wrapper in this module checks for an all-zero vector (or catches Tribuo’s exception) and returnsnull, and the metrics count that as wrong. In production, route those tickets to a human.
Go deeper: the guard in the Smile wrapper
Both Smile classes in SmileClassifiers.java use the same one-line guard, and expose rawPredict so a test can still see what the library does on its own.
@Override public Category predict(String text) {
return allZero(bow.apply(text)) ? null : Category.values()[rawPredict(text)];
}
A stricter guard would also abstain when only one or two known words are present, because a ticket with a single known word is nearly as uninformed as one with none. Where to set that threshold depends on how costly a wrong routing is for you.
- NoKnownWordsTest.java — the three raw calls and the assertions on each.
Where a zero-shot LLM fits, and what this post cannot tell you
A zero-shot classifier needs no training data: you describe the categories in a prompt and ask for one word back. That is its strength — it works on day one, and it copes with wording it has never seen. Its costs are the ones in the opening paragraph, plus a new failure mode: the reply is free text, so you must decide what to do when it is not exactly one of your categories. ZeroShotLlm.java posts the instruction and the ticket to any OpenAI-compatible /v1/chat/completions endpoint (a hosted API, Ollama, vLLM, llama.cpp) and refuses to guess on a bad reply.
public static Optional<Category> parse(String reply) {
Set<Category> found = EnumSet.noneOf(Category.class);
String upper = reply.toUpperCase();
for (Category c : Category.values()) {
if (Pattern.compile("\\b" + c.name() + "\\b").matcher(upper).find()) found.add(c);
}
return found.size() == 1 ? Optional.of(found.iterator().next()) : Optional.empty();
}
The guard accepts a reply only when exactly one category name appears in it. The harness transcript shows it against a local fake server whose replies are scripted. No model produced these replies; the point is the plumbing and the guard.
## Reply guard, ZeroShotLlm.parse
"BILLING" -> BILLING (accepted)
"Access." -> ACCESS (accepted)
"The category is Bug" -> BUG (accepted)
"BILLING or CANCEL" -> (none) (rejected: two categories)
"I think this is a refund request" -> (none) (rejected: no category name)
"" -> (none) (rejected: empty)
To get a real number, point the client at your own endpoint and call new ZeroShotLlm(baseUrl, model, apiKey).score(test) on the same 599 test tickets; replies that cannot be parsed count as wrong, never as a guess. Compare that accuracy with the table above, with the drifted set above, and with your own tickets rather than mine. I would expect the language model to do better on the drifted set and cost far more; but that is an expectation, and this module has no measurement behind it.
Go deeper: the exact request the client sends
This is the first request body the client sent to the fake endpoint, copied from the same transcript. Temperature is 0 and the reply is capped at 8 tokens, because you want one word back, not an explanation.
{"model":"any-model","temperature":0,"max_tokens":8,"messages":[{"role":"system","content":"You classify customer support tickets. Reply with exactly one word from this list and nothing else: BILLING, ACCESS, BUG, FEATURE, CANCEL. BILLING is about charges, invoices and refunds. ACCESS is about login, passwords and locked accounts. BUG is about something that is broken. FEATURE is a request for something new. CANCEL is about ending a subscription or account."},{"role":"user","content":"Ticket: I was charged twice for this month.\nCategory:"}]}
The instruction alone is estimated at 93 tokens, and an average ticket plus instruction at about 118. Those estimates use characters divided by four, which is a rule of thumb; a real tokeniser gives different counts for every model.
- LlmHarnessTest.java — the fake server and the assertions on the request.
- Semantic caching for LLM calls in Spring Boot — if you do call a model per ticket, a cache is the first cost lever.
What a million tickets cost: a formula, not a price list
The honest comparison of cost is a formula you fill in with your own prices. A language model bills by token: tickets times (prompt tokens times the input price, plus output tokens times the output price). A classic model running inside your service costs CPU time: tickets times the measured microseconds per ticket, at whatever a core-hour costs you. Both are short functions in CostModel.java.
public static double llmDollars(long tickets, double promptTokens, double outputTokens,
double dollarsPerMillionInput, double dollarsPerMillionOutput) {
return tickets * (promptTokens * dollarsPerMillionInput + outputTokens * dollarsPerMillionOutput) / 1_000_000.0;
}
The cost transcript runs it with three assumed input prices, output priced at five times input in every row, and one assumed core price. Those prices are placeholders I picked for the arithmetic; they are not any provider’s rate card, so replace them before drawing a conclusion.
EVERY PRICE BELOW IS AN ASSUMPTION. Replace the three rate cards with the ones you actually pay.
inputs: 117.9 prompt tokens per ticket (estimate), 3 output tokens, 1,000,000 tickets
## LLM, billed per token (output priced at 5x input in every row)
assumed $ per 1M input tokens $ per 1M tickets
0.10 13.29
1.00 132.92
3.00 398.76
## Classic model, in-process on one CPU core
measured median predict (Tribuo, 02-models.txt run): 13.9 microseconds
assumed core price: $0.05 per core-hour
core-seconds for 1M tickets: 13.9 cost: $0.0002
The shape is the message: the model-per-ticket cost scales with the price you negotiate and is in dollars per million tickets, while the in-process classifier costs seconds of CPU and rounds to nothing. What the table leaves out is just as important and usually decides the real comparison: the classic model needs labelled data and someone to retrain it, and the language model needs retries, rate-limit handling and a plan for when the provider changes the model underneath you.
Go deeper: the third option, a hybrid
You do not have to choose. A common shape is to run the cheap classifier first and send only the tickets it is unsure about, or the ones it abstains on, to a language model. The abstain behaviour built in the unseen-word section is the hook for this: a null from the classic model is the trigger to spend tokens. I have not built or measured that hybrid here; it is the natural next experiment, and the harness has the pieces for it.
- CostModelTest.java — the test that writes the cost transcript and asserts the ordering.
Before you pick a library: licence and Java version
Two facts about the libraries matter more than the 0.005 accuracy gap between them. Tribuo is Apache-2.0 licensed and its 4.3.2 bytecode runs on Java 8. Smile 7.3.0 is offered under GPL-3.0-or-later or a separate commercial licence (both are listed in the smile-core 7.3.0 POM), and its bytecode needs Java 25. If you ship proprietary software, the GPL option is a conversation with your lawyers before it is a Maven dependency; I am not a lawyer, and the project’s own licensing page is the place to read the terms. If your runtime is Java 17 or 21, Smile 7.3.0 will not load at all.
Should you build this at all? Train your own classifier when you have a few hundred labelled tickets per category, a stable set of categories, a latency or cost budget that a network call breaks, or text you cannot send out. Reach for a language model when you have no labelled data, the categories change often, the wording drifts, or volume is low enough that the bill does not matter. Whichever you choose, measure per-class recall on the rare classes, deduplicate before you split, decide what happens to a ticket the model cannot answer, and re-score on fresh tickets every month. And do not trust any number in this post as a prediction for your data: the tickets here are synthetic, and the language-model side was never run.
Further reading
- The companion module
classic-ml-vs-llm— every transcript quoted above is in itsoutput/folder, regenerated byscripts/run-all.sh. - Running ONNX models in Java with ONNX Runtime and DJL — a pre-trained neural classifier served from Java.
- Measuring RAG retrieval quality in Java — the same measure-first habit for retrieval.
- Code-search MCP server with embeddings — a swappable embedder, the step beyond word counts.
- Tribuo and Smile — the two libraries’ own documentation.
- scikit-learn metrics and scoring — the clearest reference for the metrics used here.
No Comments yet!