Skip to content

filipbasara0/llm-jigsaw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

A benchmark for testing multimodal LLM spatial reasoning capabilities through iterative jigsaw puzzle solving.

๐ŸŽฎ โ†’ Try it yourself - The puzzle that challenges frontier VLMs

Reference Image Solving Process

๐Ÿ† Benchmark Results

Can frontier LLMs solve jigsaw puzzles? We tested GPT-5.2, Gemini 3 Pro, and Claude Opus 4.5 across grid sizes from 3ร—3 to 5ร—5 on 20 hand-picked images.

Performance vs Grid Size

Grid Pieces GPT-5.2 Gemini 3 Pro Claude Opus 4.5
3ร—3 9 95% solve, 97% acc 85% solve, 93% acc 20% solve, 47% acc
4ร—4 16 40% solve, 77% acc 25% solve, 72% acc -
5ร—5 25 0% solve, 46% acc 10% solve, 49% acc -

Solve = fully completed puzzles. Acc = % of pieces in correct position.

Key insights:

  • ๐Ÿ”ด Difficulty scales steeply - solve rates crash from 95% to 0% between 3ร—3 and 5ร—5
  • ๐Ÿ”ด No model reliably solves 5ร—5 - spatial reasoning hits a wall at 25 pieces
  • ๐ŸŸก Partial progress is common - models often hit a wall at 50-80% piece accuracy for 4x4 and 5x5

GPT-5.2 and Gemini 3 Pro tested with low reasoning effort; Claude Opus 4.5 with high. Higher reasoning showed slightly better performance on individual images, but both GPT-5.2 and Gemini 3 Pro would still get stuck at around 50-70% piece accuracy on average for 5x5 grid sizes.

All models received the reference image, correct piece count, and last 3 moves as context.

๐Ÿ“Š Detailed benchmark results


Overview

This project shuffles an image into an Nร—N grid and challenges an LLM to restore the original image by iteratively swapping pieces. The task tests:

  • Visual understanding: Recognizing piece content and how pieces fit together
  • Spatial reasoning: Understanding grid coordinates and piece relationships
  • Iterative problem solving: Making progress across multiple turns
  • Memory/context: Tracking previous moves and learning from them

Features

  • Configurable difficulty: Square (4ร—4) or rectangular (3ร—5) grids
  • Multiple LLM providers: OpenAI, Anthropic, Google
  • Visual annotations: Grid labels, colored borders for easy piece identification
  • Comprehensive metrics: Tracks moves, accuracy, tokens, timing
  • Reproducible: Seed-based shuffling for consistent benchmarks
  • Optional hints: Show correct count, provide reference image
  • Animated GIF output: Visualize the solving process

Installation

# Clone the repository
git clone https://github.com/yourusername/llm-jigsaw.git
cd llm-jigsaw

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Quick Start

# Set your API key
export OPENAI_API_KEY="your-key-here"
export GOOGLE_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"

# Run a simple puzzle
python main.py --image images/sample.jpg --resize 512 --grid-size 3 --model openai/gpt-5.2

๐Ÿ“– Full CLI reference ยท Benchmark guide

Running Benchmarks

Test multiple models across many images:

python benchmark.py \
  --models openai/gpt-5.2 google/gemini-3-pro-preview \
  --image-folder images \
  --grid-size 4 \
  --reasoning-effort low \
  --resize 768 \
  --parallel

๐Ÿ“Š Full benchmark guide

How It Works

The LLM receives the shuffled puzzle image and responds with JSON specifying swaps:

{
  "reasoning": "The sky piece at 1,3 belongs at 1,1 based on color continuity",
  "moves": [
    {"op": "swap", "a": "1,1", "b": "1,3"},
    {"op": "swap", "a": "2,4", "b": "4,2"}
  ]
}

Coordinates use 1-indexed "row,col" format (top-left is "1,1").

Output

Results are saved to the output directory:

results/run_name/
โ”œโ”€โ”€ result.json       # Complete metrics and move history
โ”œโ”€โ”€ initial_state.png # Shuffled puzzle at start
โ”œโ”€โ”€ final_state.png   # Puzzle state at end
โ””โ”€โ”€ game.gif          # Animated solving process

Project Structure

llm-jigsaw/
โ”œโ”€โ”€ src/                      # Core library
โ”‚   โ”œโ”€โ”€ benchmark/            # Benchmark framework
โ”‚   โ”œโ”€โ”€ image_processor.py    # Image slicing and state management
โ”‚   โ”œโ”€โ”€ grid_annotator.py     # Visual annotations
โ”‚   โ”œโ”€โ”€ llm_interface.py      # LLM API abstraction
โ”‚   โ”œโ”€โ”€ game.py               # Game controller
โ”‚   โ””โ”€โ”€ prompts.py            # Prompt templates
โ”œโ”€โ”€ streamlit_app/            # Human player web app
โ”‚   โ”œโ”€โ”€ app.py                # Streamlit app
โ”‚   โ””โ”€โ”€ requirements_app.txt  # App dependencies
โ”œโ”€โ”€ docs/                     # Documentation
โ”‚   โ”œโ”€โ”€ RESULTS.md            # Benchmark results
โ”‚   โ”œโ”€โ”€ BENCHMARK.md          # Benchmark guide
โ”‚   โ””โ”€โ”€ USAGE.md              # CLI usage guide
โ”œโ”€โ”€ tests/                    # Test suite
โ”œโ”€โ”€ images/                   # Test images
โ”œโ”€โ”€ main.py                   # CLI entry point
โ””โ”€โ”€ benchmark.py              # Benchmark runner

License

MIT License

About

Testing how well LLMs can solve jigsaw puzzles

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors