
A support article repeats one command several times. A ranking feature can count repetitions or merely record whether the term appeared. The fixed vocabulary makes the output columns inspectable. Out-of-vocabulary terms contribute no column in this example.
Set up the evaluation
These fixtures model a small index or a short ranked list. They deliberately make it possible to inspect individual tokens and documents. A production evaluation should preserve the query, corpus revision and candidate list that generated each score.
from sklearn.feature_extraction.text import CountVectorizer
def evaluate(v):
return CountVectorizer(vocabulary=["cache","disk","app"],binary=v[1]).fit_transform([v[0]]).toarray()[0].tolist()
for sample in [['cache cache disk', False], ['cache cache disk', True], ['app update', False]]:
print(evaluate(sample))What changes across the three cases
| Example input | Calculated output |
|---|---|
| ["cache cache disk", false] | [2, 1, 0] |
| ["cache cache disk", true] | [1, 1, 0] |
| ["app update", false] | [0, 0, 1] |
For ["cache cache disk", false], the observed output is [2, 1, 0]. With ["cache cache disk", true], it becomes [1, 1, 0]. A UI screenshot alone would discard some of this evidence. Keep the original data, the expected return value and the runtime version together when filing a regression report.
For ["app update", false], the operation returns 3 top-level items. An assertion on that count would miss a change in their contents. Capture the expected sequence or compare membership explicitly if order has no meaning in the product.
Keep the shape of these outputs with the recorded result. A list used as a feature vector needs its column order, while a pair of measurements needs a name for each component. A downstream dashboard cannot reconstruct that meaning from a sequence of unlabelled numbers.
What the release review still needs
Default tokenization drops some one-character tokens. Match the production tokenizer before comparing feature vectors.
For a repeatable comparison, retain one counterexample as well as one ordinary success. In this fixture, ["cache cache disk", true] makes a useful starting point: its reference result is [1, 1, 0]. A changed result is a prompt to inspect the inputs, dependency version and chosen policy before accepting a new baseline.
A reproduction of word count vector should keep the corpus revision with the case. Here the original first input is ["cache cache disk", false]. In a production note, include the text snapshot, vocabulary and relevance judgements used for this run. This makes it possible to tell a code regression apart from a document added or removed from the index when the same evaluation is run again.
scikit-learn text feature extraction · Python numeric types
Sources and further reading
Cover photograph: Late 2016 MacBook Pro by Sonicdrewdriver. CC BY-SA 4.0. Cropped and typeset for this cover. The photograph illustrates the topic. This image adaptation uses the same share-alike license.
