File size: 2,309 Bytes
91325ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22030f1
91325ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
license: apache-2.0
dataset_info:
  features:
  - name: image
    dtype: image
  - name: target
    dtype: string
  - name: turn
    dtype: string
  splits:
  - name: train
    num_bytes: 82595245
    num_examples: 3500
  download_size: 81770022
  dataset_size: 82595245
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
task_categories:
- image-to-text
pretty_name: BIG-Bench Checkmate In One Move (Images)
---

# Dataset Card for BIG-Bench Checkmate In One Move (Images)
## Description
This is an adapted version of the [BIG-Bench Checkmate in One Move task](https://github.com/google/BIG-bench/tree/main/bigbench/benchmark_tasks/checkmate_in_one)
as originally made by Nitish Keskar ([email protected]).
Copying the original task description:
>The goal of this task is to probe the ability of language models to play chess in standard algebraic notation (SAN). The input to the model is a sequence of moves such that a next possible move is a checkmate. We curate 3,500 games and measure the performance of the system in exact match accuracy.

This version simply replaces the text input with images of the board state before the checkmate move.
## Example
![Chess Game State](game_0.png)

turn: black

target: Rg5#

## Generation Code
The code used to generate this was:
```python
def svg_to_png(svg_data, output_file):
    """Convert SVG data to PNG and save it"""
    # Convert SVG to PNG using cairosvg
    png_data = cairosvg.svg2png(bytestring=svg_data)

    # Write the PNG data to the output file
    with open(output_file, "wb") as f:
        f.write(png_data)


def pgn_to_images(pgn, f_name):
    """Convert a PGN file to an image of the final board position"""
    pgn = io.StringIO(pgn)
    game = chess.pgn.read_game(pgn)
    board = game.board()
    for move in game.mainline_moves():
        board.push(move)
    svg = chess.svg.board(board)
    turn_str = "white" if board.turn == chess.WHITE else "black"
    # use a temporary file to convert the SVG to PNG
    with open("temp.svg", "w") as f:
        f.write(svg)
    with open("temp.svg", "rb") as f:
        svg_data = f.read()
        svg_to_png(svg_data, f_name)
    os.remove("temp.svg")
    return turn_str
```
Thanks to the python chess library and cairosvg for making this possible.