fr

Research

Making language models reliable enough for formal reasoning: grammars, solvers and small models.

Watch a grammar keep a small model honest

A small model translates a problem into a program, and a solver runs it. Generate once with the grammar on, then switch it off and try again. At each step you can see the model's top candidate tokens, and which ones the grammar rules out.

1. Problem

2. Small model writes a program

Next-token candidatesMasked so far: 0

    3. Solver

    Papers and theses

    Grammar-constrained decoding makes large language models better logical parsers

    ACL 2025, Industry Track

    With Tanir Özçelebi and Mike Holenderski, Eindhoven University of Technology

    If you let a language model translate a logic problem into a formal program and hand the reasoning to a theorem prover, the weak link is syntax: one misplaced bracket and the solver can't run it. I forced the model's output to follow the solver's grammar while it generates, and small models went from almost never producing runnable programs to almost always doing so.

    Read the full storyClose

    The problem

    LLMs look good on reasoning benchmarks like GSM8K, but their scores drop when problems are lightly perturbed, which suggests they're pattern-matching rather than reasoning. A popular fix is to split the job: the LLM acts as a parser that turns the natural-language problem into a symbolic program, and a solver such as Prover9 does the actual inference. That moves the failure point to syntax. The usual remedies are few-shot examples in the prompt, or asking the model to check and fix its own output, and neither guarantees a valid program.

    The approach

    I wrote context-free grammars for first-order logic (for FOLIO) and for arithmetic programs (for GSM-symbolic), and used grammar-constrained decoding: at every generation step, tokens that would break the grammar are masked out. The model can still choose what to say, but it can only say it in a form the solver accepts.

    Problem inplain English LLM grammar masks tokens Symbolicprogram SolverProver9 TrueFalseUnknown The model only parses. The solver reasons.

    What I found

    I tested 13 instruction-tuned open models from four families (Gemma 2, Llama 3, Mistral, Qwen 2.5), from 0.5B to 27B parameters, with 0, 2 and 5 in-context examples. The chart shows the share of generated programs the solver could actually run, with no examples in the prompt.

    Unconstrained Grammar-constrained
    Show the numbers
    • Constraints helped every model, and helped small models most. Llama 3.2 1B went from 0.00 to 0.98 executable programs on GSM-symbolic.
    • In most cases, zero-shot with constraints beat unconstrained five-shot, which matters wherever expert-written examples are scarce or the prompt budget is tight.
    • Constraints and examples are complementary: the best scores usually came from using both.
    • For the largest models with several examples, unconstrained decoding sometimes won on accuracy. This fits recent theoretical work showing that constrained decoding biases the output distribution. My reading is that grammars steer small models toward good outputs, but once a model is good enough, the bias starts to cost more than it saves.
    • A context-free grammar guarantees syntax, not meaning. Errors like inconsistent predicates still slip through, which is where I think the next step lies.

    Tools

    • llama.cpp
    • GBNF grammars
    • GGUF models
    • Prover9
    • NLTK
    • Python

    Greench-v1: distilling small language models for greenwashing detection

    NLP4Ecology workshop at LREC 2026

    With Simona Scala, İrem Demirtaş, Alessandro Pietro Bardelli, Marilena Di Bari and Michele Filannino, Prometeia

    A 4B-parameter model that reads ESG reports paragraph by paragraph, flags possible greenwashing and explains why. After reinforcement learning, it beat both a model eight times its size and Claude Sonnet 4.5 at spotting greenwashing. I designed the reinforcement learning reward, ran the evaluation and wrote much of the paper.

    Read the full storyClose

    The problem

    Banks and other financial institutions have to check that what companies say about sustainability matches what they do. Today that means people reading long reports by hand, which is slow, expensive and inconsistent. The goal was a model small and fast enough to screen large volumes of text, that gives auditors a reason with each flag rather than a bare score.

    What it produces

    For each paragraph, Greench-v1 returns one of three labels (greenwashing alert, no greenwashing, not relevant) and a short justification grounded in that paragraph. Here's an example from a real ESG report:

    Paragraph
    In 2022, Mango joined the network of the Ellen MacArthur Foundation, an international charity dedicated to promoting the circular economy…
    Label
    Possible greenwashing
    Justification
    A general statement about joining a foundation, with no concrete actions or measurable outcomes behind it.

    How we trained it

    We built a dataset of about 2,000 paragraphs adapted from the ClimateBERT corpus. To fix the class imbalance, we paraphrased rare positive examples, and GPT-4o wrote evidence-based justifications. Then we compared four ways of training Qwen3-4B:

    ~2,000 labelledparagraphs Qwen3-4B Hard distillation (fine-tuning) Soft distillation from Qwen3-14B GRPO, exact-match reward Hard distillation, then GRPO Evaluate
    The highlighted path is the one I worked on.

    My part: reward design and evaluation

    For GRPO, the model samples 10 candidate answers per step and gets pushed toward the ones that score higher. We tried richer rewards, but getting one that was stable was the hard part. The version that worked was deliberately blunt: +1 if the label exactly matches the ground truth, 0 otherwise. I also built the evaluation: weighted F1 for the labels and BERTScore F1 for how close the justifications are to the reference ones.

    Results

    Weighted F1 on the greenwashing alert label:

    Show the numbers
    • GRPO scored highest at 0.73, a 49% relative gain over the best untuned baseline. Soft distillation reached 0.67 and also gave the best justifications.
    • Model size didn't help on its own: untuned Qwen3-32B did no better than untuned Qwen3-4B. Claude Sonnet 4.5 wrote good justifications but flagged too many paragraphs as greenwashing.
    • The exact-match reward sharpened the labels but didn't improve the justifications. A reward that also scores the rationale is the obvious next step.
    • The whole 400-paragraph evaluation set runs in under five minutes on a single A100.

    Tools

    • Qwen3
    • GRPO
    • Knowledge distillation
    • Hugging Face
    • PyTorch
    • BERTScore

    Constrained generation in large language models: methods, applications and future directions

    Survey paper, in revision

    Started at Eindhoven University of Technology

    Submitted for review. Reviewers liked it and asked for more work before acceptance.

    An overview of the ways to make an LLM's output follow rules: from keyword constraints, through finite automata and context-free grammars, to probabilistic and semantic methods.

    What it coversClose
    • Constraint types: lexical (include these words), syntactic (follow this grammar) and semantic (be valid by these rules).
    • Where constraints are applied: in the prompt, at decoding time (from grid beam search to grammar masks and PICARD), at sampling time (probabilistic and Monte Carlo methods), through iterative generate-check-refine loops, or inside the transformer layers.
    • Applications: code and query languages, domain-specific languages, semantic parsing and information extraction, scientific notation and constrained machine translation, plus the benchmarks used for each.
    • Open problems: computational overhead, losing meaning while enforcing syntax, tokenizers that split text differently from the grammar, and the fact that many of the best models are only available through APIs that don't expose token probabilities.

    Grammar-constrained large language models for logical reasoning

    MSc thesis, 2024, graded 9/10

    Eindhoven University of Technology and Université Côte d'Azur

    Where the ACL paper started. I combined grammar constraints with self-verification: when a generated logic program failed, open models repaired it under a grammar that was updated as the program changed.

    Read the full storyClose

    The method, which I called GCLLM, raised the share of executable programs by up to 21% on FOLIO and LogicNLI. It also produced a negative result: better syntax didn't translate into better answers, and chain-of-thought prompting stayed the most reliable way to get semantically correct ones.

    I also tested whether models fix syntax better after fine-tuning on broken formulas. To do that, I built FOLIO-Refinement, a synthetic dataset made by injecting syntax errors into FOLIO's formulas. I added a fallback that lets the LLM answer directly when repair fails, too. That negative result is why the ACL paper drops self-repair and constrains the first generation directly.

    • FOLIO
    • LogicNLI
    • Prover9
    • Self-verification
    • Fine-tuning

    Sentiment analysis for cryptocurrency market signalling

    BSc thesis, 2022

    Bocconi University, supervised by Prof. Dirk Hovy

    My first real ML project, from before the LLM era. Can the mood of news, Reddit, Telegram and Twitter predict Bitcoin, Ethereum and Ripple prices?

    Read the full storyClose

    The data was 12 GB of prices and posts collected every five minutes over 2019. I cleaned and split the text, scored each piece with VADER sentiment, then looked at lagged cross-correlations, regressions and simple trading signals.

    Sentiment explained very little: the average R² was about 0.05. The exception was Bitcoin with Telegram, at about 0.25. My explanation is that Telegram crypto groups are both specialised and near real-time, while Twitter mixed enthusiasts and newcomers into noise. Looking back, the more interesting lesson was the one I wrote in the conclusion: I chose simple, explainable models on purpose, even if a deep network might score higher. I still care about that trade-off.

    • Python
    • pandas
    • VADER
    • Regression
    • Time series