{ "cells": [ { "cell_type": "markdown", "id": "intro", "metadata": {}, "source": [ "# Abuse Model Inference Test\n", "\n", "This notebook loads the saved production abuse model and its local artifacts from this folder, then runs inference on a calibrated set of example sentences. It performs inference only.\n", "\n", "Note: this checkpoint is a subtype classifier, not a generic toxicity detector. It predicts `Age`, `Ethnicity`, `Gender`, `Religion`, or `Not Cyberbullying`, and it responds most strongly when the text explicitly names the targeted group." ] }, { "cell_type": "markdown", "id": "load-notes", "metadata": {}, "source": [ "## 1. Load the model artifacts\n", "\n", "The code below reads the local model config, tokenizer, weights, and label mapping directly from the current folder." ] }, { "cell_type": "code", "execution_count": 1, "id": "load-code", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "37774b8a0e1f4d959c6e6a3293e0e766", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading weights: 0%| | 0/201 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
textpredicted_labelconfidencetoken_counttop_3probabilities
0go do your homework you stupid childAge0.99719[Age (0.9971), Not Cyberbullying (0.0014), Ethnicity (0.0009)]{'Age': 0.9971, 'Ethnicity': 0.0009, 'Gender': 0.0003, 'Not Cyberbullying': 0.0014, 'Religion': 0.0003}
1immigrants like you ruin everything in this countryEthnicity0.997910[Ethnicity (0.9979), Not Cyberbullying (0.0013), Religion (0.0007)]{'Age': 0.0, 'Ethnicity': 0.9979, 'Gender': 0.0001, 'Not Cyberbullying': 0.0013, 'Religion': 0.0007}
2women are stupid and should stay quietGender0.99999[Gender (0.9999), Not Cyberbullying (0.0001), Ethnicity (0.0000)]{'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.9999, 'Not Cyberbullying': 0.0001, 'Religion': 0.0}
3muslims like you are the problem with this countryReligion1.000011[Religion (1.0000), Not Cyberbullying (0.0000), Age (0.0000)]{'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.0, 'Not Cyberbullying': 0.0, 'Religion': 1.0}
4the project update was sent to the team this morningNot Cyberbullying0.999912[Not Cyberbullying (0.9999), Gender (0.0000), Religion (0.0000)]{'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.0, 'Not Cyberbullying': 0.9999, 'Religion': 0.0}
\n", "" ], "text/plain": [ " text predicted_label \\\n", "0 go do your homework you stupid child Age \n", "1 immigrants like you ruin everything in this country Ethnicity \n", "2 women are stupid and should stay quiet Gender \n", "3 muslims like you are the problem with this country Religion \n", "4 the project update was sent to the team this morning Not Cyberbullying \n", "\n", " confidence token_count \\\n", "0 0.9971 9 \n", "1 0.9979 10 \n", "2 0.9999 9 \n", "3 1.0000 11 \n", "4 0.9999 12 \n", "\n", " top_3 \\\n", "0 [Age (0.9971), Not Cyberbullying (0.0014), Ethnicity (0.0009)] \n", "1 [Ethnicity (0.9979), Not Cyberbullying (0.0013), Religion (0.0007)] \n", "2 [Gender (0.9999), Not Cyberbullying (0.0001), Ethnicity (0.0000)] \n", "3 [Religion (1.0000), Not Cyberbullying (0.0000), Age (0.0000)] \n", "4 [Not Cyberbullying (0.9999), Gender (0.0000), Religion (0.0000)] \n", "\n", " probabilities \n", "0 {'Age': 0.9971, 'Ethnicity': 0.0009, 'Gender': 0.0003, 'Not Cyberbullying': 0.0014, 'Religion': 0.0003} \n", "1 {'Age': 0.0, 'Ethnicity': 0.9979, 'Gender': 0.0001, 'Not Cyberbullying': 0.0013, 'Religion': 0.0007} \n", "2 {'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.9999, 'Not Cyberbullying': 0.0001, 'Religion': 0.0} \n", "3 {'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.0, 'Not Cyberbullying': 0.0, 'Religion': 1.0} \n", "4 {'Age': 0.0, 'Ethnicity': 0.0, 'Gender': 0.0, 'Not Cyberbullying': 0.9999, 'Religion': 0.0} " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_sentences = [\n", " \"go do your homework you stupid child\",\n", " \"immigrants like you ruin everything in this country\",\n", " \"women are stupid and should stay quiet\",\n", " \"muslims like you are the problem with this country\",\n", " \"the project update was sent to the team this morning\",\n", "]\n", "\n", "results = predict_texts(example_sentences)\n", "results\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "diagnostic-code", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Diagnostic: sample bank produced 5 distinct labels across 5 examples.\n" ] } ], "source": [ "distinct_labels = results[\"predicted_label\"].nunique()\n", "if distinct_labels == 1:\n", " print(\n", " \"Warning: all sample predictions collapsed to one label. \"\n", " \"That usually means the sample bank is too weak for this checkpoint or the export should be re-verified.\"\n", " )\n", "else:\n", " print(f\"Diagnostic: sample bank produced {distinct_labels} distinct labels across {len(results)} examples.\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }