Update README.md
Browse files
README.md
CHANGED
|
@@ -1,71 +1,126 @@
|
|
| 1 |
---
|
| 2 |
license: cc0-1.0
|
| 3 |
-
task_categories:
|
| 4 |
-
- reinforcement-learning
|
| 5 |
-
- tabular-classification
|
| 6 |
-
language:
|
| 7 |
-
- en
|
| 8 |
-
tags:
|
| 9 |
-
- chess
|
| 10 |
-
- opening-theory
|
| 11 |
-
- lichess
|
| 12 |
-
- elite-games
|
| 13 |
-
- gambitflow
|
| 14 |
-
size_categories:
|
| 15 |
-
- 1M<n<10M
|
| 16 |
-
pretty_name: 'GambitFlow: Elite Chess Opening Theory'
|
| 17 |
---
|
| 18 |
|
| 19 |
-
#
|
| 20 |
|
| 21 |
-
|
| 22 |
-
This dataset serves as the **"Opening Memory"** for the GambitFlow AI project (Synapse-Edge). It contains millions of chess positions extracted exclusively from **Elite Level Games (Elo 2000+)** played on Lichess.
|
| 23 |
|
| 24 |
-
The goal is to provide
|
| 25 |
|
| 26 |
-
|
| 27 |
-
- **Filter:** White & Black Elo ≥ 2000
|
| 28 |
-
- **Depth:** First 35 plies (moves)
|
| 29 |
-
- **Format:** SQLite Database (`.db`)
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
| Column | Type | Description |
|
| 36 |
-
| :--- | :--- | :--- |
|
| 37 |
-
| `fen` | TEXT (PK) | The board position in Forsyth–Edwards Notation (Cleaned: no move counters). |
|
| 38 |
-
| `move_stats` | JSON | Aggregated statistics of moves played in this position by elite players. |
|
| 39 |
-
|
| 40 |
-
### Example `move_stats` JSON:
|
| 41 |
-
```json
|
| 42 |
-
{
|
| 43 |
-
"e4": 15400,
|
| 44 |
-
"d4": 12300,
|
| 45 |
-
"Nf3": 5000
|
| 46 |
-
}
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
## 🛠️ Usage
|
| 50 |
|
| 51 |
```python
|
| 52 |
import sqlite3
|
| 53 |
import json
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
cursor = conn.cursor()
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
- **Raw Data:** [Lichess Open Database](https://database.lichess.org/)
|
| 68 |
-
- **Processed By:** GambitFlow Team
|
| 69 |
-
- **License:** CC0 1.0 Universal (Public Domain)
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: cc0-1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
| 4 |
|
| 5 |
+
# GambitFlow Opening Database
|
| 6 |
|
| 7 |
+
A curated, high-quality chess opening theory database in SQLite format, designed for chess engines and analysis tools. This dataset contains aggregated move statistics derived from thousands of recent, high-rated (2600+ ELO) grandmaster-level games.
|
|
|
|
| 8 |
|
| 9 |
+
The goal of this database is to provide a powerful, statistically-backed foundation for understanding modern opening theory, without relying on traditional, human-annotated opening books.
|
| 10 |
|
| 11 |
+
## How to Use
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
The database is a single SQLite file (`opening_theory.db`). You can download it directly from the "Files" tab or use the `huggingface_hub` library to access it programmatically.
|
| 14 |
|
| 15 |
+
Here is a Python example to query the database for the starting position:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
```python
|
| 18 |
import sqlite3
|
| 19 |
import json
|
| 20 |
+
from huggingface_hub import hf_hub_download
|
| 21 |
|
| 22 |
+
# 1. Download the database file
|
| 23 |
+
db_path = hf_hub_download(
|
| 24 |
+
repo_id="GambitFlow/Opening-Database",
|
| 25 |
+
filename="opening_theory.db",
|
| 26 |
+
repo_type="dataset"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# 2. Connect to the database
|
| 30 |
+
conn = sqlite3.connect(db_path)
|
| 31 |
cursor = conn.cursor()
|
| 32 |
|
| 33 |
+
# 3. Query a position (FEN)
|
| 34 |
+
# The FEN should be "canonical" (position, turn, castling, en passant)
|
| 35 |
+
start_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"
|
| 36 |
+
|
| 37 |
+
cursor.execute("SELECT move_data FROM openings WHERE fen = ?", (start_fen,))
|
| 38 |
+
row = cursor.fetchone()
|
| 39 |
+
|
| 40 |
+
if row:
|
| 41 |
+
# 4. Parse the JSON data
|
| 42 |
+
moves_data = json.loads(row)
|
| 43 |
+
|
| 44 |
+
# Sort moves by frequency
|
| 45 |
+
sorted_moves = sorted(
|
| 46 |
+
moves_data.items(),
|
| 47 |
+
key=lambda item: item['frequency'],
|
| 48 |
+
reverse=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
print(f"Top moves for FEN: {start_fen}\n")
|
| 52 |
+
for move, data in sorted_moves[:5]:
|
| 53 |
+
print(f"- Move: {move}")
|
| 54 |
+
print(f" Frequency: {data['frequency']:,}")
|
| 55 |
+
print(f" Avg Score: {data.get('avg_score', 0.0):.3f}\n")
|
| 56 |
+
|
| 57 |
+
conn.close()
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## Data Collection and Processing
|
| 61 |
+
|
| 62 |
+
This dataset was meticulously created through a multi-stage pipeline to ensure the highest quality and statistical relevance.
|
| 63 |
|
| 64 |
+
**1. Data Source:**
|
| 65 |
+
The foundation of this dataset is the **Lichess Elite Database**, a filtered collection of games from high-rated players, originally curated by [Nikonoel](https://database.nikonoel.fr/). We used multiple monthly PGN files from the 2023-2024 period to capture modern theory.
|
| 66 |
+
|
| 67 |
+
**2. Filtering Criteria:**
|
| 68 |
+
Only games meeting the following strict criteria were processed:
|
| 69 |
+
* **Minimum ELO:** Both players had a rating of **2600 or higher**.
|
| 70 |
+
* **Maximum Depth:** Only the first **25 moves** of each game were analyzed to focus on opening theory.
|
| 71 |
+
|
| 72 |
+
**3. Processing Pipeline:**
|
| 73 |
+
* **Distributed Processing:** The PGN files were processed in parallel across multiple sessions to handle the large volume of games efficiently.
|
| 74 |
+
* **Perspective-Aware Scoring:** Each move's quality was scored from the perspective of the player whose turn it was. A win scored `1.0`, a loss `0.0`, and a draw `0.5`.
|
| 75 |
+
* **Aggregation:** For each unique board position (FEN), statistics for every move played were aggregated, including frequency and the sum of scores.
|
| 76 |
+
* **Merging:** The databases from the distributed sessions were merged into a single master file. This process recalculated weighted averages for ELO and move scores, ensuring statistical accuracy.
|
| 77 |
+
|
| 78 |
+
## Dataset Structure
|
| 79 |
+
|
| 80 |
+
The database contains a single table named `openings`.
|
| 81 |
+
|
| 82 |
+
**File:** `opening_theory.db`
|
| 83 |
+
**Table:** `openings`
|
| 84 |
+
|
| 85 |
+
| Column | Type | Description |
|
| 86 |
+
|---------------|---------|-------------------------------------------------------------|
|
| 87 |
+
| `fen` | TEXT | The canonical board position (FEN string, Primary Key). |
|
| 88 |
+
| `move_data` | TEXT | A JSON object containing statistics for each move played. |
|
| 89 |
+
| `total_games` | INTEGER | The total number of times this position was seen. |
|
| 90 |
+
| `avg_elo` | INTEGER | The average ELO of players who reached this position. |
|
| 91 |
+
|
| 92 |
+
### `move_data` JSON Structure
|
| 93 |
+
|
| 94 |
+
The `move_data` column contains a JSON string with the following structure:
|
| 95 |
+
|
| 96 |
+
```json
|
| 97 |
+
{
|
| 98 |
+
"e4": {
|
| 99 |
+
"frequency": 153944,
|
| 100 |
+
"score_sum": 76972.0,
|
| 101 |
+
"avg_score": 0.5
|
| 102 |
+
},
|
| 103 |
+
"d4": {
|
| 104 |
+
"frequency": 65604,
|
| 105 |
+
"score_sum": 32802.0,
|
| 106 |
+
"avg_score": 0.5
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
```
|
| 110 |
+
* **`frequency`**: The number of times this move was played from the given position.
|
| 111 |
+
* **`score_sum`**: The sum of all perspective-aware scores for this move.
|
| 112 |
+
* **`avg_score`**: The average score, calculated as `score_sum / frequency`.
|
| 113 |
+
|
| 114 |
+
## Citation
|
| 115 |
|
| 116 |
+
If you use this dataset in your work, please consider citing it:
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
```bibtex
|
| 119 |
+
@dataset{gambitflow_opening_database_2024,
|
| 120 |
+
author = {GambitFlow Project},
|
| 121 |
+
title = {GambitFlow Opening Database},
|
| 122 |
+
year = {2024},
|
| 123 |
+
publisher = {Hugging Face},
|
| 124 |
+
url = {https://huggingface.co/datasets/GambitFlow/Opening-Database}
|
| 125 |
+
}
|
| 126 |
+
```
|