Learning Causality in LLMs
2024
Do large language models understand cause and effect, or just recognise patterns?
overview
Overview
“An Empirical Study on the Capability of Large Language Models in Learning Causality” — my undergraduate honors thesis at the University of Arkansas, submitted December 2024 under Dr. Lu Zhang, with Dr. Susan Gauch and Dr. Xintao Wu on the committee.
The question: when a language model answers correctly about a cause-and-effect relationship, is it reasoning about causation, or is it pattern-matching its way to an answer that happens to be right?
To separate those, I built a task where the correct answer stays identical but the causal direction changes. Three models, three prompt framings, a thousand Yelp reviews, and a measurable gap between them.
problem
The problem
A star rating and the review that accompanies it have a causal relationship, and which way it runs depends on how they were written. If you decide on the rating first and then write a review explaining it, the rating caused the review — predicting the rating from the review is causal inference. If you write the review first and then settle on a rating, the review caused the rating, and predicting it is anti-causal inference. The text on screen is the same either way.
That makes it a clean instrument. Three prompts describe the same review and ask for the same number, differing only in which direction they say the causation ran. A model that genuinely reasons about causal structure should be sensitive to that difference in a principled way. A model that pattern-matches review sentiment to a rating should be largely indifferent, or should favour whichever framing best matches how it was trained.
Prior work on this task used GPT-2 and found the causal framing performed best, followed by third-party, then anti-causal. The question I set out to answer was whether that ordering held on the models that had replaced it.
architecture
Architecture
- 01
Dataset
The Yelp review dataset from Hugging Face — 700k reviews across many business types, split 650k train / 50k test. I used the first 1,000 reviews of the test set, labelled 0–4 for a 1–5 star rating.
- 02
Three causal setups
Setup 1 (causal): the rating was given first, and the review explains it. Setup 2 (anti-causal): the review was written first, and the rating follows from it. Setup 3 (third person): you are reading someone else's review and inferring what they gave. Same review text in all three; only the stated direction of causation changes.
- 03
Zero-shot prompting
No examples, no demonstrations, no fine-tuning. The point was to measure what each model brings pre-trained, rather than how well it adapts once shown the pattern.
- 04
Model harness
One consistent pipeline per model in Python 3.11.5, so all three received identical inputs: GPT-3.5-turbo via OpenAI's chat completions endpoint, Gemini Pro via the Google API, and Llama-3-8B run locally after requesting access from Meta.
- 05
Output extraction
Models answer in prose, not integers. A parser strips each response down to a rating, matching either the numeral or the written word. Reviews too empty or malformed to rate at all returned -1 and were excluded rather than counted as wrong.
- 06
Scoring
Ten subsets of 100 entries per model per prompt, scored with scikit-learn for accuracy, F1, precision, recall, and runtime — reported both per subset and combined.
challenges
What was hard
Three providers, three sets of obstacles
GPT-3.5 was a library import and an API key. Gemini's safety filters silently degraded results until every category was set to BLOCK_NONE, and the free tier's rate limit capped throughput at roughly six requests a minute — which is why its runs took nearly three hours each against GPT-3.5's nine to seventeen minutes. Llama 3 meant requesting model access from Meta, cloning the repo, and batching prompts to stay inside the model's processing capacity.
Getting a number out of a paragraph
The task asks for a rating; the models return explanations. Sometimes the rating is a numeral, sometimes a word, sometimes buried in a sentence of justification. Extraction had to be consistent across three models with different verbosity, because a parsing failure is indistinguishable from a wrong answer in the final score.
Reviews that aren't reviews
The dataset contains entries like the single string "session key" — no sentiment, nothing to rate. Counting those as errors would have measured data quality rather than model capability, so unratable reviews were dropped instead.
results
Results
| Model | Setup | Accuracy | F1 |
|---|---|---|---|
| GPT-3.5 | 1 — causal | 64.03% | 62.92% |
| GPT-3.5 | 2 — anti-causal | 63.90% | 63.41% |
| GPT-3.5 | 3 — third person | 64.50% | 63.74% |
| Gemini Pro | 1 — causal | 62.41% | 61.61% |
| Gemini Pro | 2 — anti-causal | 64.28% | 63.33% |
| Gemini Pro | 3 — third person | 64.04% | 62.86% |
| Llama 3 | 1 — causal | 51.51% | 48.29% |
| Llama 3 | 2 — anti-causal | 51.54% | 49.07% |
| Llama 3 | 3 — third person | 53.37% | 51.31% |
lessons
What I took from it
The causal framing finished last for all three models — the exact inverse of the earlier GPT-2 result, which had ranked it first. Whatever changed between GPT-2 and this generation moved the ordering, and it moved it consistently.
GPT-3.5 and Llama 3 did best on the third-person prompt; Gemini Pro did best on anti-causal, with third-person close behind. Every model preferred a framing where the review comes first and the rating is inferred from it.
That shared preference points at a review-to-rating habit: summarise the text, then produce a number that fits. My reading is that this comes out of RLHF — the reward model is trained on human preference data, which pushes the actor toward responses humans would have written, and a human reading a review and guessing a rating works in exactly that direction.
Answering correctly and reasoning causally are different things. All three models scored respectably on a task they appear to be solving the wrong way round, which is the finding: fluent, useful output is not evidence of causal understanding.
Model architecture matters more than scale here. Llama-3-8B trailed the other two by roughly ten points across every setup, but showed the same directional preference — so the ordering is not an artifact of one provider.
screenshots
Screenshots
screenshot slot
screenshot slot
screenshot slot
stack
Tech stack
next
Future work
Widen the dataset beyond Yelp reviews. One domain and one task shape is enough to show the effect but not enough to generalise it.
Re-run the sweep on frontier models — GPT-4 and later — to test whether the causal deficit narrows as capability increases, or whether it is structural.
Vary the prompts further. Three framings isolate direction cleanly, but more variations would separate the causal effect from ordinary prompt sensitivity.