Skip to main content

No project description provided

Project description

Visual SPaRC: Visual Puzzle Representations for the SPaRC benchmark

Overview

SPaRC (sparc-puzzle) provides a comprehensive framework for evaluating language models on spatial reasoning tasks inspired by "The Witness" puzzle game. This package (sparc-visualization) includes various visual puzzle representations and an improved visual reasoning prompt to complement the functionality of the sparc-puzzle package.

Installation

Install the package from PyPI:

pip install sparc-visualization

Or install from source:

git clone https://github.com/flowun/sparc-visualization.git
cd sparc-visualization
pip install -e .

Example Usage

from sparc_visualization.plot import get_puzzle_image
from sparc_visualization.prompt import generate_prompt
from sparc.validation import extract_solution_path, validate_solution, analyze_path
from datasets import load_dataset

# Load the dataset
dataset = load_dataset("lkaesberg/SPaRC", "all", split="test")
puzzle = dataset[0]

puzzle_image = get_puzzle_image(puzzle, plot_type="path_cell_annotated")

# Generate prompt and image, e.g.
plot_type = "path_cell_annotated"
prompt_type = "prompt_engineering"

b64_image = get_puzzle_image(puzzle, plot_type=plot_type, base_64_image=True)
text_prompt = generate_prompt(puzzle, plot_type, prompt_type)

# create message array and payload for an LLM
puzzle_prompt = [
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/png;base64,{b64_image}"
                    }
                },
                {
                    "type": "text",
                    "text": text_prompt
                }
            ]
        }
    ]

payload = {
    "model": your_model_name,
    "messages": puzzle_prompt,
    "temperature": temperature,
    "max_tokens": max_tokens,
}

# Your model generates a response
model_response = "... model response with path coordinates ..."

# Analysis using sparc-puzzle package

# Extract the path from model response
extracted_path = extract_solution_path(model_response, puzzle)
# Returns: [{"x": 0, "y": 2}, {"x": 0, "y": 1}, ...]

# Validate against ground truth
is_correct = validate_solution(extracted_path, puzzle)
# Returns: True/False

# Get detailed analysis
analysis = analyze_path(extracted_path, puzzle)
# Returns: {
#   "starts_at_start_ends_at_exit": True,
#   "connected_line": True,
#   "non_intersecting_line": True,
#   "no_rule_crossing": True,
#   "fully_valid_path": True
# }

Core Functions

get_puzzle_image(puzzle: Dict, plot_type: str = "original", base_64_image: bool = False, show_plot: bool = False, save_to_disk: bool = False, save_dir: str = ".", save_filename: str = "puzzle_image.png") -> PIL.Image.Image | str Renders a SPaRC puzzle into one of the supported visual representations (plot_type values). To get a base64-encoded string of the image suitable for LLM input, set base_64_image=True. Besides returning the image object or base64 string, the function has options to display the image (show_plot=True) or save it to disk (save_to_disk=True).

generate_prompt(puzzle: Dict, plot_type: str = "original", prompt_type: str = "prompt_engineering") -> str Generates the text prompt (based on prompt_type values) that should be paired with the rendered image for an LLM call. Available prompt_type values are:

  • "default_tr": visual prompt from the SPaRC paper (with textual coordinates)
  • "default_no_tr": visual prompt from the SPaRC paper (however with textual coordinates removed)
  • "prompt_engineering": improved vision-only prompt with prompt engineering (no textual coordinates) puzzle and plot_type should be provided the same as in get_puzzle_image to allow small prompt adjustments.

Available Puzzle Representations (plot_type)

original
original
start_end_marked
start_end_marked
coordinate_grid
coordinate_grid
coordinate_grid_and_start_end_marked
coordinate_grid_and_start_end_marked
path_cell_annotated
path_cell_annotated
text
text
low_contrast
low_contrast
low_contrast_and_path_cell_annotated
low_contrast_and_path_cell_annotated
low_resolution
low_resolution
low_resolution_and_path_cell_annotated
low_resolution_and_path_cell_annotated
rotated
rotated
rotated_and_path_cell_annotated
rotated_and_path_cell_annotated
black_frame
black_frame
black_frame_and_path_cell_annotated
black_frame_and_path_cell_annotated

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

Citation

If you use SPaRC in your research, please cite:

@article{kaesberg2025sparc,
  title     = {SPaRC: A Spatial Pathfinding Reasoning Challenge},
  author    = {Kaesberg, Lars Benedikt and Wahle, Jan Philip and Ruas, Terry and Gipp, Bela},
  year      = {2025},
  url       = {https://arxiv.org/abs/2505.16686}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sparc_visualization-0.1.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sparc_visualization-0.1.1-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file sparc_visualization-0.1.1.tar.gz.

File metadata

  • Download URL: sparc_visualization-0.1.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sparc_visualization-0.1.1.tar.gz
Algorithm Hash digest
SHA256 10f0e5765b0c5461e32da070a24386bd374f1b4daff48422dcd341304407d30c
MD5 95a89603262d2502b5a1b98a087b8de0
BLAKE2b-256 2082dc465c3b153453f6e783ab47d8707e97a0ae20372e2e366924d1d5197f81

See more details on using hashes here.

File details

Details for the file sparc_visualization-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sparc_visualization-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c75ca10209661696e0e82257ee3792bc0bf65f2b074bc53e4fc94575796c77a1
MD5 a89186f6f1286249f191e6cf60728413
BLAKE2b-256 03ed68ec3cf32ce98a6b9698ff0d480857e58c771f1525714d3b258d602c02bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page