Upload moderat_speed_test.ipynb with huggingface_hub
Browse files- moderat_speed_test.ipynb +6 -6
moderat_speed_test.ipynb
CHANGED
|
@@ -96,7 +96,7 @@
|
|
| 96 |
"metadata": {},
|
| 97 |
"outputs": [],
|
| 98 |
"source": [
|
| 99 |
-
"# @title 4. PII Detector Class (FIXED)\n",
|
| 100 |
"class PIIDetector:\n",
|
| 101 |
" \"\"\"Detect PII with proper age-based social media rules\"\"\"\n",
|
| 102 |
" \n",
|
|
@@ -223,7 +223,7 @@
|
|
| 223 |
"metadata": {},
|
| 224 |
"outputs": [],
|
| 225 |
"source": [
|
| 226 |
-
"# @title 6. PII Detection Tests (FIXED)\n",
|
| 227 |
"print(\"π PII Detection Results (Fixed)\\n\")\n",
|
| 228 |
"print(\"Expected: Address and Credit Card now detected correctly\")\n",
|
| 229 |
"print(\"Expected: Social media ALLOWED for 13+ (unless grooming)\\n\")\n",
|
|
@@ -257,7 +257,7 @@
|
|
| 257 |
"metadata": {},
|
| 258 |
"outputs": [],
|
| 259 |
"source": [
|
| 260 |
-
"# @title
|
| 261 |
"test_text = \"damn that's crazy\"\n",
|
| 262 |
"\n",
|
| 263 |
"# Warm up\n",
|
|
@@ -285,7 +285,7 @@
|
|
| 285 |
"metadata": {},
|
| 286 |
"outputs": [],
|
| 287 |
"source": [
|
| 288 |
-
"# @title
|
| 289 |
"test_cases = [\n",
|
| 290 |
" (\"that was a great game\", 10),\n",
|
| 291 |
" (\"that was a great game\", 15),\n",
|
|
@@ -312,7 +312,7 @@
|
|
| 312 |
"metadata": {},
|
| 313 |
"outputs": [],
|
| 314 |
"source": [
|
| 315 |
-
"# @title
|
| 316 |
"batch_texts = [\n",
|
| 317 |
" \"that was a great game\",\n",
|
| 318 |
" \"shit that sucks\",\n",
|
|
@@ -348,7 +348,7 @@
|
|
| 348 |
"metadata": {},
|
| 349 |
"outputs": [],
|
| 350 |
"source": [
|
| 351 |
-
"# @title
|
| 352 |
"print(\"π moderat Summary\")\n",
|
| 353 |
"print(\"=\"*60)\n",
|
| 354 |
"print(\"\")\n",
|
|
|
|
| 96 |
"metadata": {},
|
| 97 |
"outputs": [],
|
| 98 |
"source": [
|
| 99 |
+
"# @title 4. Unicode Deobfuscator\n", "class UnicodeDeobfuscator:\n", " CIRCLED_MAP = {\n", " 'β': 'a', 'β': 'b', 'β': 'c', 'β': 'd', 'β': 'e',\n", " 'β': 'f', 'β': 'g', 'β': 'h', 'β': 'i', 'β': 'j',\n", " 'β': 'k', 'β': 'l', 'β': 'm', 'β': 'n', 'β': 'o',\n", " 'β': 'p', 'β ': 'q', 'β‘': 'r', 'β’': 's', 'β£': 't',\n", " 'β€': 'u', 'β₯': 'v', 'β¦': 'w', 'β§': 'x', 'β¨': 'y', 'β©': 'z',\n", " 'βΆ': 'A', 'β·': 'B', 'βΈ': 'C', 'βΉ': 'D', 'βΊ': 'E',\n", " 'β»': 'F', 'βΌ': 'G', 'β½': 'H', 'βΎ': 'I', 'βΏ': 'J',\n", " 'β': 'K', 'β': 'L', 'β': 'M', 'β': 'N', 'β': 'O',\n", " 'β
': 'P', 'β': 'Q', 'β': 'R', 'β': 'S', 'β': 'T',\n", " 'β': 'U', 'β': 'V', 'β': 'W', 'β': 'X', 'β': 'Y', 'β': 'Z',\n", " }\n", " \n", " @classmethod\n", " def detect(cls, text):\n", " suspicious = []\n", " normalized = []\n", " for char in text:\n", " if char in cls.CIRCLED_MAP:\n", " suspicious.append((char, 'circled'))\n", " normalized.append(cls.CIRCLED_MAP[char])\n", " else:\n", " normalized.append(char)\n", " return len(suspicious) > 0, suspicious, ''.join(normalized)\n", "\n", "# @title 5. PII Detector Class (FIXED)\n",
|
| 100 |
"class PIIDetector:\n",
|
| 101 |
" \"\"\"Detect PII with proper age-based social media rules\"\"\"\n",
|
| 102 |
" \n",
|
|
|
|
| 223 |
"metadata": {},
|
| 224 |
"outputs": [],
|
| 225 |
"source": [
|
| 226 |
+
"# @title 6. Unicode Deobfuscation Tests\n", "print(\"π€ Unicode Deobfuscation Tests\\n\")\n", "\n", "unicode_tests = [\n", " (\"have you tried like β/ βk\", 15),\n", " (\"you're a βββββ of β’βββ£\", 15),\n", " (\"ββββ yourself\", 15),\n", "]\n", "\n", "for text, age in unicode_tests:\n", " is_obf, chars, norm = UnicodeDeobfuscator.detect(text)\n", " result = check_content(text, age)\n", " status = \"β
\" if result['allowed'] else \"β\"\n", " print(f\"{status} Original: {text}\")\n", " print(f\" Normalized: {norm}\")\n", " print(f\" β {result['reason']}\")\n", " print()\n", "\n", "# @title 7. PII Detection Tests (FIXED)\n",
|
| 227 |
"print(\"π PII Detection Results (Fixed)\\n\")\n",
|
| 228 |
"print(\"Expected: Address and Credit Card now detected correctly\")\n",
|
| 229 |
"print(\"Expected: Social media ALLOWED for 13+ (unless grooming)\\n\")\n",
|
|
|
|
| 257 |
"metadata": {},
|
| 258 |
"outputs": [],
|
| 259 |
"source": [
|
| 260 |
+
"# @title 8. Speed Test - Single Inference\n",
|
| 261 |
"test_text = \"damn that's crazy\"\n",
|
| 262 |
"\n",
|
| 263 |
"# Warm up\n",
|
|
|
|
| 285 |
"metadata": {},
|
| 286 |
"outputs": [],
|
| 287 |
"source": [
|
| 288 |
+
"# @title 9. Dual-Mode Content Test\n",
|
| 289 |
"test_cases = [\n",
|
| 290 |
" (\"that was a great game\", 10),\n",
|
| 291 |
" (\"that was a great game\", 15),\n",
|
|
|
|
| 312 |
"metadata": {},
|
| 313 |
"outputs": [],
|
| 314 |
"source": [
|
| 315 |
+
"# @title 10. Batch Processing Speed Test\n",
|
| 316 |
"batch_texts = [\n",
|
| 317 |
" \"that was a great game\",\n",
|
| 318 |
" \"shit that sucks\",\n",
|
|
|
|
| 348 |
"metadata": {},
|
| 349 |
"outputs": [],
|
| 350 |
"source": [
|
| 351 |
+
"# @title 11. Summary\n",
|
| 352 |
"print(\"π moderat Summary\")\n",
|
| 353 |
"print(\"=\"*60)\n",
|
| 354 |
"print(\"\")\n",
|