LuCeHe/logicjitter_article

Python

0

289 commits

updated Jun 10, 2026

See the code

README

LogicJitter

LogicJitter: Let LLMs play and uncover misinformation

Paper License: CC BY 4.0

Open-source toolkit for automatically generating logic-based training data and fine-tuning LLMs for domain-agnostic misinformation detection.

Authors: Luca Herranz-Celotti · Marco Viviani
Affiliations: University of Milano-Bicocca · Université Paris Cité
Published in: Computers and Electrical Engineering 136 (2026) 111215

Read the paper: LogicJitter on ScienceDirect
DOI: 10.1016/j.compeleceng.2026.111215


Overview

Misinformation detection often relies on large, domain-specific labeled datasets that are costly to build and do not generalize well. LogicJitter takes a different path: instead of training only on misinformation examples, it strengthens an LLM’s domain-agnostic reasoning by fine-tuning on algorithmically generated logic games that expose both valid and fallacious reasoning.

The approach is inspired by data augmentation techniques such as ColorJitter in computer vision, but adapted to textual reasoning. Logic games are designed to counter common cognitive biases (e.g., authority bias, bandwagon effect, conservatism bias) and logical fallacies (e.g., denying the antecedent), so the model learns to evaluate claims on logic rather than surface cues or stereotypical associations.

Key ideas

  • Rule-based generation — No human- or LLM-labeled misinformation data required for augmentation.
  • Balanced and unbounded — Each instance is self-contained; datasets can be generated at any scale with a 50/50 true/false balance.
  • Reasoning-centric fine-tuning — AdaLoRA PEFT with a dual loss: next-token prediction plus a weighted binary truthfulness classification term.
  • Strong results on smaller models — Empirical gains on GPT-2 and Llama-3.2-1B across PubHealth, VitaminC, and ISOT.

How it works

LogicJitter randomly samples one of four logic game types and wraps each problem with optional distractors:

ComponentSymbolDescription
GameGCore logic problem (math, causal graph, CFG, or spatial scene)
ErrorsEControlled incorrect reasoning steps in ~50% of samples
CharactersCRandom “adjective + noun” personas whose opinions may be right or wrong
RevisionRModified problem statement to test belief updating and fallacy resistance

Logic games

  1. Guided Maths — Step-by-step arithmetic (sum, product, polynomial) with scratchpad-style solutions.
  2. Causal Clauses — Causal graphs (Erdős–Rényi, Watts–Strogatz, Barabási–Albert) with connectivity and fork/collider questions.
  3. Context-Free Grammars — Random CFGs; string membership and grammar comparison tasks.
  4. CLEVR — Textual spatial-reasoning scenes derived from CLEVR-style object layouts and question templates.

Example output

Input: 7x^3 for x = 7 Target: <scratch>, 7x^3 = 7 * (7)^3 = ... = 770, 770, </scratch>, 770.
A quaint crew says it's fine. Is the quaint crew correct? False.
At a second try it is shown that ... = 2401, ... = 2365. A quaint crew says it's not ok.
Is the quaint crew correct, True or False? True.

Repository structure

logicjitter/
├── logicjitter_creation/     # Logic game generators
│   ├── logicjitter_generator.py
│   ├── arithmetics_dataset.py
│   ├── causal_dataset.py
│   ├── cfg_dataset.py
│   ├── clevr_dataset.py
│   └── clevr_tools/
├── helpers/                  # Datasets, models, evaluation, analysis
│   ├── helpers_datasets.py
│   ├── helpers_models.py
│   ├── evaluate_misinformation.py
│   └── hyperparams.json
├── train.py                  # Fine-tuning entry point
├── analyze_results.py        # Aggregate experiment results
└── requirements.txt

Data and experiment outputs are stored one level above this folder (see Paths).


Installation

Clone the repository and install dependencies from the parent directory of the logicjitter package (the workspace root that contains the logicjitter/ folder):

git clone <repository-url>
cd all_logicjitter
pip install -r logicjitter/requirements.txt
pip install pyaromatics

Requirements include PyTorch, HuggingFace Transformers, PEFT, TRL, and NetworkX. A CUDA-capable GPU is recommended for fine-tuning.

For gated models (e.g., Llama), set your HuggingFace token:

export HF_TOKEN=your_token_here

Quick start

Generate logic games

from logicjitter.logicjitter_creation.logicjitter_generator import LogicJitter

lj = LogicJitter(multimodal=True, n_characters=3, seed=42)
print(lj.get_logic_game())                          # random game, full distractors
print(lj.get_logic_game(game_type="causal"))      # causal graph only
print(lj.get_logic_game(game_type="maths"))       # guided maths

Or run the built-in demo:

python -m logicjitter.logicjitter_creation.logicjitter_generator

Fine-tune with LogicJitter augmentation

Run from the workspace root so imports resolve correctly:

python -m logicjitter.train \
  --model_id gpt2 \
  --dataset vitaminc \
  --epochs 3 \
  --n_samples 1000 \
  --notes "augment_ljttrfull_p50%aug_bnry_v3"

Misinformation datasets (--dataset):

NameDescription
vitamincMulti-domain fact verification (Wikipedia edits)
pubhealthHealth-related fact-checking claims
isotFake vs. real news articles

Augmentation flags (in --notes):

FlagMeaning
augmentMix target dataset with LogicJitter data
ljttrfullFull LogicJitter (games + errors + characters + revisions)
ljttrwenpnrGames + errors only
ljttrwewpnrGames + errors + characters
ljttrnenpnrGames only (no errors, characters, or revisions)
p50%augAdd LogicJitter samples equal to 50% of the training set
m25%augReplace 25% of training samples with LogicJitter data
bnryEnable binary classification loss alongside LM loss
notrainSkip training; run evaluation only

Supported models (--model_id): gpt2, gpt2xl, llama, llamaxl, mamba, mambaxl, gemma2, gemma2l, gemma3, seek, and verysmall* variants for ablation on tiny architectures.


Paths

By default, the toolkit creates sibling directories at the workspace root:

  • data/ — HuggingFace cache, downloaded datasets, generated LogicJitter shards
  • experiments/ — Training runs, logs, and saved checkpoints

These paths are configured in helpers/paths.py.


Citation

If you use LogicJitter in your research, please cite:

@article{herranzcelotti2026logicjitter,
  title   = {LogicJitter: Let LLMs play and uncover misinformation},
  author  = {Herranz-Celotti, Luca and Viviani, Marco},
  journal = {Computers and Electrical Engineering},
  volume  = {136},
  pages   = {111215},
  year    = {2026},
  doi     = {10.1016/j.compeleceng.2026.111215},
  url     = {https://www.sciencedirect.com/science/article/pii/S0045790626002879}
}

License

The article is published under CC BY 4.0. See the paper for full terms.


Acknowledgments

This work was partly funded by the European Union – Next Generation EU (KURAMi project). Computing resources were provided by the LEONARDO supercomputer (EuroHPC / CINECA).

LuCeHe/logicjitter_article

Python

0

289 commits

updated Jun 10, 2026

See the code

README

LogicJitter

LogicJitter: Let LLMs play and uncover misinformation

Paper License: CC BY 4.0

Open-source toolkit for automatically generating logic-based training data and fine-tuning LLMs for domain-agnostic misinformation detection.

Authors: Luca Herranz-Celotti · Marco Viviani
Affiliations: University of Milano-Bicocca · Université Paris Cité
Published in: Computers and Electrical Engineering 136 (2026) 111215

Read the paper: LogicJitter on ScienceDirect
DOI: 10.1016/j.compeleceng.2026.111215


Overview

Misinformation detection often relies on large, domain-specific labeled datasets that are costly to build and do not generalize well. LogicJitter takes a different path: instead of training only on misinformation examples, it strengthens an LLM’s domain-agnostic reasoning by fine-tuning on algorithmically generated logic games that expose both valid and fallacious reasoning.

The approach is inspired by data augmentation techniques such as ColorJitter in computer vision, but adapted to textual reasoning. Logic games are designed to counter common cognitive biases (e.g., authority bias, bandwagon effect, conservatism bias) and logical fallacies (e.g., denying the antecedent), so the model learns to evaluate claims on logic rather than surface cues or stereotypical associations.

Key ideas

  • Rule-based generation — No human- or LLM-labeled misinformation data required for augmentation.
  • Balanced and unbounded — Each instance is self-contained; datasets can be generated at any scale with a 50/50 true/false balance.
  • Reasoning-centric fine-tuning — AdaLoRA PEFT with a dual loss: next-token prediction plus a weighted binary truthfulness classification term.
  • Strong results on smaller models — Empirical gains on GPT-2 and Llama-3.2-1B across PubHealth, VitaminC, and ISOT.

How it works

LogicJitter randomly samples one of four logic game types and wraps each problem with optional distractors:

ComponentSymbolDescription
GameGCore logic problem (math, causal graph, CFG, or spatial scene)
ErrorsEControlled incorrect reasoning steps in ~50% of samples
CharactersCRandom “adjective + noun” personas whose opinions may be right or wrong
RevisionRModified problem statement to test belief updating and fallacy resistance

Logic games

  1. Guided Maths — Step-by-step arithmetic (sum, product, polynomial) with scratchpad-style solutions.
  2. Causal Clauses — Causal graphs (Erdős–Rényi, Watts–Strogatz, Barabási–Albert) with connectivity and fork/collider questions.
  3. Context-Free Grammars — Random CFGs; string membership and grammar comparison tasks.
  4. CLEVR — Textual spatial-reasoning scenes derived from CLEVR-style object layouts and question templates.

Example output

Input: 7x^3 for x = 7 Target: <scratch>, 7x^3 = 7 * (7)^3 = ... = 770, 770, </scratch>, 770.
A quaint crew says it's fine. Is the quaint crew correct? False.
At a second try it is shown that ... = 2401, ... = 2365. A quaint crew says it's not ok.
Is the quaint crew correct, True or False? True.

Repository structure

logicjitter/
├── logicjitter_creation/     # Logic game generators
│   ├── logicjitter_generator.py
│   ├── arithmetics_dataset.py
│   ├── causal_dataset.py
│   ├── cfg_dataset.py
│   ├── clevr_dataset.py
│   └── clevr_tools/
├── helpers/                  # Datasets, models, evaluation, analysis
│   ├── helpers_datasets.py
│   ├── helpers_models.py
│   ├── evaluate_misinformation.py
│   └── hyperparams.json
├── train.py                  # Fine-tuning entry point
├── analyze_results.py        # Aggregate experiment results
└── requirements.txt

Data and experiment outputs are stored one level above this folder (see Paths).


Installation

Clone the repository and install dependencies from the parent directory of the logicjitter package (the workspace root that contains the logicjitter/ folder):

git clone <repository-url>
cd all_logicjitter
pip install -r logicjitter/requirements.txt
pip install pyaromatics

Requirements include PyTorch, HuggingFace Transformers, PEFT, TRL, and NetworkX. A CUDA-capable GPU is recommended for fine-tuning.

For gated models (e.g., Llama), set your HuggingFace token:

export HF_TOKEN=your_token_here

Quick start

Generate logic games

from logicjitter.logicjitter_creation.logicjitter_generator import LogicJitter

lj = LogicJitter(multimodal=True, n_characters=3, seed=42)
print(lj.get_logic_game())                          # random game, full distractors
print(lj.get_logic_game(game_type="causal"))      # causal graph only
print(lj.get_logic_game(game_type="maths"))       # guided maths

Or run the built-in demo:

python -m logicjitter.logicjitter_creation.logicjitter_generator

Fine-tune with LogicJitter augmentation

Run from the workspace root so imports resolve correctly:

python -m logicjitter.train \
  --model_id gpt2 \
  --dataset vitaminc \
  --epochs 3 \
  --n_samples 1000 \
  --notes "augment_ljttrfull_p50%aug_bnry_v3"

Misinformation datasets (--dataset):

NameDescription
vitamincMulti-domain fact verification (Wikipedia edits)
pubhealthHealth-related fact-checking claims
isotFake vs. real news articles

Augmentation flags (in --notes):

FlagMeaning
augmentMix target dataset with LogicJitter data
ljttrfullFull LogicJitter (games + errors + characters + revisions)
ljttrwenpnrGames + errors only
ljttrwewpnrGames + errors + characters
ljttrnenpnrGames only (no errors, characters, or revisions)
p50%augAdd LogicJitter samples equal to 50% of the training set
m25%augReplace 25% of training samples with LogicJitter data
bnryEnable binary classification loss alongside LM loss
notrainSkip training; run evaluation only

Supported models (--model_id): gpt2, gpt2xl, llama, llamaxl, mamba, mambaxl, gemma2, gemma2l, gemma3, seek, and verysmall* variants for ablation on tiny architectures.


Paths

By default, the toolkit creates sibling directories at the workspace root:

  • data/ — HuggingFace cache, downloaded datasets, generated LogicJitter shards
  • experiments/ — Training runs, logs, and saved checkpoints

These paths are configured in helpers/paths.py.


Citation

If you use LogicJitter in your research, please cite:

@article{herranzcelotti2026logicjitter,
  title   = {LogicJitter: Let LLMs play and uncover misinformation},
  author  = {Herranz-Celotti, Luca and Viviani, Marco},
  journal = {Computers and Electrical Engineering},
  volume  = {136},
  pages   = {111215},
  year    = {2026},
  doi     = {10.1016/j.compeleceng.2026.111215},
  url     = {https://www.sciencedirect.com/science/article/pii/S0045790626002879}
}

License

The article is published under CC BY 4.0. See the paper for full terms.


Acknowledgments

This work was partly funded by the European Union – Next Generation EU (KURAMi project). Computing resources were provided by the LEONARDO supercomputer (EuroHPC / CINECA).