|
340 | 340 | " print(f\"{token:<12} | {prob:<10.4f} | {status}\")\n", |
341 | 341 | "\n", |
342 | 342 | "# Example 1: A natural sentence (all tokens should be marked REAL)\n", |
343 | | - "detect_fake_tokens(\"The doctor examined the patient carefully.\")\n", |
| 343 | + "detect_fake_tokens(\"The company announced record profits for the third quarter.\")\n", |
344 | 344 | "\n", |
345 | 345 | "print(\"\\n\" + \"=\"*40 + \"\\n\")\n", |
346 | 346 | "\n", |
347 | | - "# Example 2: Same sentence but 'examined' → 'watched' (plausible but wrong in context)\n", |
348 | | - "detect_fake_tokens(\"The doctor watched the patient carefully.\")\n", |
| 347 | + "# Example 2: 'quarter' replaced with 'half' — grammatical but semantically wrong\n", |
| 348 | + "# (companies report in quarters, not halves)\n", |
| 349 | + "detect_fake_tokens(\"The company announced record profits for the third half.\")\n", |
349 | 350 | "\n", |
350 | 351 | "print(\"\\n\" + \"=\"*40 + \"\\n\")\n", |
351 | 352 | "\n", |
352 | | - "# Example 3: 'doctor' → 'musician' (semantically odd with 'patient')\n", |
353 | | - "detect_fake_tokens(\"The musician examined the patient carefully.\")" |
| 353 | + "# Example 3: 'case' replaced with 'mystery' — creates redundancy with 'mysterious'\n", |
| 354 | + "detect_fake_tokens(\"The detective solved the mysterious mystery in just two days.\")" |
354 | 355 | ] |
355 | 356 | }, |
356 | 357 | { |
|
360 | 361 | "outputs": [], |
361 | 362 | "source": [ |
362 | 363 | "# Let's visualize the discriminator's confidence\n", |
363 | | - "# 'published' has been swapped in for 'presented' — plausible but detectable\n", |
364 | | - "sentence = \"The researcher published her findings at the annual conference.\"\n", |
| 364 | + "# 'painted' has been swapped to 'created' — plausible synonym, but ELECTRA\n", |
| 365 | + "# flags 'landscape' as suspicious (you 'paint' a landscape, not 'create' one)\n", |
| 366 | + "sentence = \"The artist created a beautiful landscape of the countryside.\"\n", |
365 | 367 | "inputs = tokenizer(sentence, return_tensors=\"pt\")\n", |
366 | 368 | "tokens = tokenizer.convert_ids_to_tokens(inputs[\"input_ids\"][0])[1:-1] # Remove CLS/SEP\n", |
367 | 369 | "\n", |
|
387 | 389 | "source": [ |
388 | 390 | "### \ud83d\udca1 Discussion\n", |
389 | 391 | "\n", |
390 | | - "- In Example 2, did ELECTRA flag \"watched\" as suspicious? Doctors *examine* patients — \"watched\" is grammatical but semantically odd in a clinical context.\n", |
391 | | - "- In Example 3, did swapping \"doctor\" → \"musician\" get detected? Why might that be easier or harder to detect than swapping the verb?\n", |
| 392 | + "- In Example 2, did ELECTRA flag \"half\" as fake? Why is \"third half\" suspicious even though it's grammatically correct?\n", |
| 393 | + "- In Example 3, the discriminator flags \"mysterious\" rather than \"mystery\" — why might it flag the *context* around a fake token rather than the fake token itself?\n", |
| 394 | + "- In the bar chart, ELECTRA flags \"landscape\" as fake even though it's the *original* word. The swap was \"painted\" → \"created\". Why does suspicion propagate to neighboring tokens?\n", |
392 | 395 | "- How is this task different from BERT's masked language modeling? Why might it be more efficient? (Hint: how many tokens does each approach learn from per sentence?)\n", |
393 | 396 | "- Try replacing a word with a close synonym (e.g., \"quickly\" → \"rapidly\"). Does ELECTRA flag it?" |
394 | 397 | ] |
|
0 commit comments