Engineering experiment · Artificial intelligence
Logical fallacy detection: Text classification with machine learning

Automatic sorting of text by type, tested on a hard task: labeling logical fallacies.
- Type
- Engineering experiment
- Sector
- Artificial intelligence
- Includes
- A text classification model.
What the experiment does
Many businesses receive more messages and complaints than their team can sort by hand. We tested automatic sorting on a harder task than sorting by topic: a model that reads an English sentence and decides whether its reasoning holds or falls into one of three fallacies: faulty generalization, circular reasoning or a loaded question. “Mohammed is telling the truth, because he said he is telling the truth” is circular reasoning, for example.
What we can build for you
- The same method can sort your incoming messages by topic, so a complaint or request reaches the right team without manual triage.
- We can train the model on your categories and examples, so it sorts text by the labels your team already uses.
- We hand over the whole pipeline as code you can rerun, to add a category and retrain whenever you need.
How it works
The work starts when a sentence enters the model. The software splits it into words, notes each word's grammatical role and the word it links to, and counts the words, giving rare words more weight. It then turns all of that into numbers the classifier can compare. The classifier learned beforehand from more than 7,500 sentences labeled by type. It compares the new sentence's numbers with what it learned and outputs the closest of four labels: no fallacy, or one of the three fallacies. The hard part is keeping the types apart. A fallacy is a pattern in how an argument is built, and two different types can share similar words, so the model reads the sentence's structure as well as its words. Since the whole pipeline lives in code, we can rerun it at any time, add new examples and retrain the model.
For engineers: how it is built
We wrote the whole pipeline in Python, the most widely used language for text processing and machine learning. NLTK splits each sentence into words, and a parser adds each word's grammatical role and the word it links to. Scikit-learn weighs the words with TF-IDF and trains the classifier. We compared four classifiers with cross-validation, and logistic regression was the most accurate. The labeled sentences came from published research datasets, from articles and books on fallacies, and from examples we generated with ChatGPT for each type.
- Python
- Scikit-learn
- NLTK
Questions before you start
Can the same method classify Arabic text?
Yes, on two conditions. The experiment ran on English sentences. To work in Arabic, the model needs labeled Arabic examples to learn from, and text preparation suited to Arabic. Arabic attaches prefixes and suffixes to words, and writes some letters, such as the hamza, in more than one form.
How accurate is the model?
On 910 test sentences it had not seen in training, the model chose the right label 93 times in 100. Accuracy changes with the examples and the number of categories, so it should be measured on a sample of your own texts before anyone relies on the model.
