Could I give a comment a topic by comparing it with the descriptions of the available categories? I explored that question in a notebook because it offered a way to try a new set of labels without first collecting training examples for each one.
The example uses a pretrained BERT model to turn text into numerical features, then compares them with cosine similarity.
From text to a vector
Once documents have numerical representations, cosine similarity compares their directions. A labeling rule can use those comparisons to assign a category.
The notebook reads a CBC comments CSV and builds category descriptions from lists of keywords. For entertainment, for instance, the starting words include cinema, movies, and music. The BERT code removes the boundary tokens and averages the remaining token vectors for each cleaned document. It also averages vectors for each category’s keywords. The predicted label is the one with the highest cosine similarity to the document.
This exposes several choices that a high-level classification function can hide: which model output becomes the document vector, how longer text is handled, and how the categories are represented.
Similarity needs a test set
Avoiding a new training run does not remove the need to evaluate assignments. Two comments about the same event can express opposing positions. A model may recognize their shared subject while missing the distinction the task requires.
For a useful comparison, I would keep the labels and test documents fixed, then inspect how feature and pooling choices change the assignments. Ambiguous cases help expose what a representation captures.
Where this fits
The 2018 BERT paper is a useful historical anchor for contextual language features. The notebook shows their appeal as reusable inputs to a smaller downstream task.
I don’t have an accuracy measurement for this notebook. I’d start an evaluation with the comments where the two highest-scoring categories are close enough that either label looks plausible.