Skip to content

About

Logical Fallacy Detection and Controlled Text Generation: A project exploring whether neural networks can detect logical fallacies and generate text that maintains logical consistency, highlighting the gap between language fluency and reasoning.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

LoFa-De_CTG: Logical Fallacy Detection & Controlled Text Generation

This repository explores whether neural networks can truly detect logical fallacies and generate text that maintains logical consistency, highlighting the gap between language fluency and reasoning.


📈 Project Status & Milestones

🏁 Stage 1: Logical Fallacy Classification (COMPLETED)

  • Model: Fine-tuned roberta-base for 3 epochs with balanced class weighting & Threshold Calibration.
  • Performance:
    • Calibrated Test F1 Score: 80.65% (Val F1: 79.42%, Test Accuracy: 80.00%).
    • Baseline Improvement: +5.60% absolute gain over the unweighted 1-epoch baseline (75.05%).
  • Key Achievement:
    • Class weighting resolved the severe dataset imbalance.
    • Threshold calibration ($T = 0.700$) fixed the fallback boundaries: none class recall rose from 66% ➔ 80%, and hasty generalization precision rose from 42% ➔ 61%.
  • Robustness Probing: Achieved 66.67% (8/12 passed) on our counterfactual suite. The failures on valid inversions empirically document the gap between language fluency and reasoning.

⏳ Stage 2: Controlled Fallacy Generation (CTG) (READY)

  • The data loading and model configuration pipelines for both causal (GPT-2) and seq2seq (T5) architectures are fully integrated and ready.

📝 Progress & Analysis Summary (Stage 1)

1. Empirical Verification (Calibrated Decision Boundaries)

If the network were incapable of recognizing logical fallacies, performance on the 9-class dataset would be close to random noise (~11.1% accuracy). While inverse-frequency class weighting forced the model to learn rare fallacies, it introduced hyper-sensitivity, misclassifying neutral texts as fallacies (e.g. 42 false positives for hasty generalization).

We resolved this by introducing Threshold Calibration ($T = 0.700$) on the softmax probabilities: the model only predicts a fallacy if its confidence is $\ge 70%$, otherwise defaulting to none. This post-processing optimization yielded our state-of-the-art 80.65% Test F1 (an absolute gain of +5.60%).

2. Semantic Generalization (Synonym Swaps)

To prove the model generalizes semantically rather than relying on exact word memorization, I used counterfactual Synonym Swap tests:

  • Replacing "tradition" with "age-old custom" and "routinely practiced" successfully preserved the correct appeal to tradition classification.
  • Replacing "Dr. Smith" with "the most prominent expert in the field" successfully preserved the appeal to authority classification.

3. Fluency vs. Reasoning Gap

The model's robustness suite failures provide empirical evidence of the gap between fluency and reasoning:

  • Valid Inversions: The model failed on structurally valid arguments that contained fallacy-associated words. For example, it misclassified "Dr. Smith supported the theory with ten years of experimental data" (a valid empirical citation) as appeal to authority.
  • The model recognizes superficial rhetorical structures and linguistic patterns, but lacks the formal reasoning logic to separate valid evidence from fallacious reasoning.

📂 Project Structure

  • data/: Contains raw (.json) and processed (.csv) splits of the CoCoLoFa dataset.
  • src/:
    • preprocess.py: Processes and cleans raw comments into training contexts.
    • data_loader.py: Dataset loaders for classification (detection) and generation (CTG).
    • model.py: Model wrappers for Sequence Classification and Causal/Seq2Seq language modeling.
    • trainer.py: Custom training and evaluation logic with class-weighting and MPS fallback mechanisms.
  • notebooks/: Jupyter notebooks for exploratory data analysis (EDA) and prototyping.
  • notes/: (Ignored locally) Markdown files detailing model logs, progress updates, and milestone reports.
  • models/: (Ignored locally) Saved model checkpoints (.pt files).
  • probe_counterfactuals.py: Automated testing suite validating model robustness against synonym swaps and distractors.
  • main.py: Command-line entry point to orchestrate stages of the project.

Trust & Transparency notes

  • Source & Attribution: Developed as an original machine learning project using the open-source Hugging Face Transformers library, PyTorch, and the CoCoLoFa logical fallacy dataset.
  • Motive: Created as an academic study to analyze and empirically document the limits of transformer-based classifiers when distinguishing between linguistic fluency and structured logical reasoning.
  • Modifications: Engineered class-balanced loss functions, calibrated decision thresholds, and wrote custom counterfactual synonym swap testing scripts.
  • Limitations:
    • The model operates at sentence level and cannot detect fallacies distributed across larger contextual paragraphs or multi-turn dialogues.
    • The classifier remains susceptible to false-positive classification on structurally valid arguments containing vocabulary associated with fallacies.
    • Stage 2 (Controlled Text Generation) components are scaffolded but lack full evaluation benchmarks.
  • Tooling & AI Usage: AI coding assistants via the Antigravity CLI were utilized to generate the PyTorch training loop, formulate class weight calibration heuristics, and structure the test harness for counterfactual verification.

About

Logical Fallacy Detection and Controlled Text Generation: A project exploring whether neural networks can detect logical fallacies and generate text that maintains logical consistency, highlighting the gap between language fluency and reasoning.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages