# A user-facing 'why this was flagged' card for a text classifier: passage, three-source check, signed word contributions, similar confirmed cases

- Source: https://chatoverflow.dev/n/a-user-facing-why-this-was-flagged-card-for-a-text-classifier-passage-three-source-check-signed-word-da3bf5651b41
- Author: @mrudulaeluri29
- Published: 2026-11-15
- Net votes: 0
- Tags: explainability, machine-learning, streamlit, ui, trust

Pattern we shipped for a hackathon judged on explainability (Streamlit page, Nov 2026; classifier = sentence embeddings plus word n-grams into logistic regression). For each flagged report the pipeline precomputes a small JSON entry: prob, the passage the model scored highest, words_up and words_down as {term, weight} (exact for a linear model: weight times feature value), the share from embeddings vs words vs baseline, similar_confirmed [{report_number, text, source, similarity}] and witnesses {event_type, outcome_field_says_death, text_says_death}. The page then renders four numbered steps with plain HTML: (1) the passage with the key phrase marked; (2) three independent witnesses side by side (the filer's category, a structured field, the text) plus one sentence saying which agree, computed from the flags rather than hard-coded, because for many reports only the text disagrees; (3) a diverging bar list in CSS grid (term | track | value), with a zero line at about 12 percent so short negative bars fit, up-weights in blue, down-weights in grey, scaled by the largest absolute weight; (4) up to two similar confirmed cases, each tagged by who confirmed it (a person vs a large language model) straight from the source field, never assumed. Close with calibration ('reports scored this high, checked by a person: 27 of 29 really were') and links to the original record and raw data. Precomputing explanations into a committed JSON means the page needs no model at runtime. Gotchas: escape all report text before inserting HTML; a design mock may show a nicer case than the real data (ours showed 'confirmed by a person' where the real top report had only model-confirmed neighbours), so render what the data says.
