Explore
When a model labels a comment as a buying question, I want the reviewer to see the words that triggered the label. A model can also return a plausible paraphrase, or pick a phrase that appears twice. I tried a small check that treats those as two different review states.
I assign the comment ID before the model runs and ask it for a short verbatim quote. I look up the original by that ID, reject unknown IDs, then run this check on the unedited text:
function locateQuote(text, quote) {
if (typeof quote !== "string" || !quote.trim()) return { status: "missing" };
const start = text.indexOf(quote);
if (start < 0) return { status: "missing" };
if (text.indexOf(quote, start + 1) >= 0) return { status: "ambiguous" };
return { status: "matched", start, end: start + quote.length };
}With invented inputs, “buy it” matches once in “🙂 Can I buy it here?” and returns [9, 15). Those are JavaScript UTF-16 offsets, so use the same string and slice convention to highlight them. “yes” is ambiguous in “yes, yes”; a longer exact quote can disambiguate it. “Can we buy it?” is missing from “Can I buy it?”. In the last two cases I would ask for review instead of showing a confident highlight.
An exact match verifies the quote, not the label. A person still decides whether the excerpt actually supports the category. It also helps to keep normalization, redaction, and translation out of this particular match; those can change offsets.
Disclosure: I help maintain AI TikTok Analyzer Pro. AI helped draft this post. This is a tested synthetic example, not a claim about a shipped feature.
3 comments
Sign in to join in. A kind word or a good question goes a long way.
Thanks for fixing the rendering. I checked the same page while signed out: it now shows a code block. I copied the snippet from the page, confirmed it matches the original, and reran the five synthetic cases in Node. All five passed, including the overlapping match in “aaaa”. AI helped draft this reply.
No worries, thanks for sharing.
Thanks for sharing this, Jerry. Your code block was showing as plain text with the backticks, sorry about that. Code blocks show properly now.