Skip to content

Classify every message and show its bot-probability#3

Open
mkhlndrv wants to merge 3 commits into
open-cu:mainfrom
mkhlndrv:feature/classify-messages
Open

Classify every message and show its bot-probability#3
mkhlndrv wants to merge 3 commits into
open-cu:mainfrom
mkhlndrv:feature/classify-messages

Conversation

@mkhlndrv

Copy link
Copy Markdown

Upgrades the echo-chat so every message gets a bot-probability instead of the placeholder random number.

Server (FastAPI):

  • app/core/classifier.py loads a zero-shot text-classification model (same setup as the baseline youarebot-classifier: candidate labels bot/human, take the bot score). Model name comes from MODEL_NAME, default typeform/distilbert-base-uncased-mnli.
  • The model is loaded once on startup via the app lifespan, and /predict now returns a real is_bot_probability for the message text.

Client (Streamlit):

  • Every user message is sent to /predict and the probability is shown under the bubble.
  • Because the bot echoes the user, the reply has the same text, so I reuse the same probability for it (no second call) and count it as a bot sample.
  • st.session_state keeps the chat history and running metrics (count, average bot-probability, and accuracy@0.5 using the known roles — user = human, echo = bot), shown in the sidebar.

Also fixed IncomingMessage to extend CustomBaseModel so its model_dump() stringifies the UUID fields — otherwise the client's requests call to /predict fails to serialize. Added transformers, torch and requests to the deps and re-locked.

Ran it locally (FastAPI on 6872, Streamlit on 8502): each message shows its probability and the metrics update live. With the default model the scores sit around 0.2–0.4 and accuracy hovers at 50%, which makes sense — the user message and its echo have identical text, so the model gives them the same score and can't separate the human/bot pair.

mkhlndrv added 3 commits June 17, 2026 16:16
Replace the English-only typeform/distilbert-base-uncased-mnli baseline with
MoritzLaurer/mDeBERTa-v3-base-mnli-xnli so RU+EN chats are both handled.

- Compare two explicit hypotheses (single-label softmax): "written by a real
  person" vs "written by an AI chatbot"; is_bot_probability = bot score.
- Wording chosen by a local sweep on the Kaggle train set (best ROC-AUC 0.60 /
  log-loss 0.72 of the variants tested).
- Load once at startup, log per-call latency, empty text -> 0.5, cap at 1500 chars.

/predict and /get_message request/response contracts are unchanged.
@mkhlndrv
mkhlndrv force-pushed the feature/classify-messages branch from 5c17786 to 4acb48d Compare June 22, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant