遇见数据集

mauricett/lichess_sf

收藏
Hugging Face2024-02-15 更新2024-03-04 收录
官方服务:

资源简介:

--- license: cc0-1.0 tags: - chess - stockfish pretty_name: Lichess Games With Stockfish Analysis --- # Condensed Lichess Database This dataset is a condensed version of the Lichess database. It only includes games for which Stockfish evaluations were available. Currently, the dataset contains the entire year 2023, which consists of >100M games and >2B positions. Games are stored in a format that is much faster to process than the original PGN data. <br> <br> Requirements: ``` pip install zstandard python-chess datasets ``` <br> # Quick Guide In the following, I explain the data format and how to use the dataset. At the end, you find a complete example script. ### 1. Loading The Dataset You can stream the data without storing it locally (~100 GB currently). The dataset requires `trust_remote_code=True` to execute the [custom data loading script](https://huggingface.co/datasets/mauricett/lichess_sf/blob/main/lichess_sf.py), which is necessary to decompress the files. See [HuggingFace's documentation](https://huggingface.co/docs/datasets/main/en/load_hub#remote-code) if you're unsure. ```py # Load dataset. dataset = load_dataset(path="mauricett/lichess_sf", split="train", streaming=True, trust_remote_code=True) ``` <br> ### 2. Data Format The following definitions are important to understand. Please reread this section slowly and correctly when you have to decide how to draw FENs, moves and scores from the dataset. Let's draw a single sample and discuss it. ```py example = next(iter(dataset)) ``` A single sample from the dataset contains one complete chess game as a dictionary. The dictionary keys are as follows: 1. `example['fens']` --- A list of FENs in a slightly stripped format, missing the halfmove clock and fullmove number (see [definitions on wiki](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation#Definition)). The starting positions have been excluded (no player made a move yet). 2. `example['moves']` --- A list of moves in [UCI format](https://en.wikipedia.org/wiki/Universal_Chess_Interface). `example['moves'][42]` is the move that **led to** position `example['fens'][42]`, etc. 3. `example['scores']` --- A list of Stockfish evaluations (in centipawns) and the game's terminal outcome condition if one exists. Evaluations are from the perspective of the player who is next to move. If `example['fens'][42]` is black's turn, `example['scores'][42]` will be from black's perspective. If the game ended with a terminal condition, the last element of the list is a string 'C' (checkmate), 'S' (stalemate) or 'I' (insufficient material). Games with other outcome conditions have been excluded. 4. `example['WhiteElo'], example['BlackElo']` --- Player's Elos. <br> ### 3. Define Functions for Preprocessing To use the data, you will require to define your own functions for transforming the data into your desired format. For this guide, let's define a few mock functions so I can show you how to use them. ```py # A mock tokenizer and functions for demonstration. class Tokenizer: def __init__(self): pass def __call__(self, example): return example # Transform Stockfish score and terminal outcomes. def score_fn(score): return score def preprocess(example, tokenizer, score_fn): # Get number of moves made in the game... max_ply = len(example['moves']) # ...and pick a position at random. random_position = random.randint(0, max_ply-2) # Get the FEN of our random choice. fen = example['fens'][random_position] # To get the move that leads to the *next* FEN, we have to add # +1 to the index. Same with the score, which is the evaluation # of that move. Please read the section about the data format clearly! move = example['moves'][random_position + 1] score = example['scores'][random_position + 1] # Transform data into the format of your choice. example['fens'] = tokenizer(fen) example['moves'] = tokenizer(move) example['scores'] = score_fn(score) return example tokenizer = Tokenizer() ``` <br> ### 4. Shuffle And Preprocess Use `dataset.shuffle()` to properly shuffle the dataset. Use `dataset.map()` to apply our preprocessors. This will process individual samples in parallel if you're using multiprocessing (e.g. with PyTorch dataloader). ```py # Shuffle and apply your own preprocessing. dataset = dataset.shuffle(seed=42) dataset = dataset.map(preprocess, fn_kwargs={'tokenizer': tokenizer, 'score_fn': score_fn}) ``` <br> <br> <br> # COMPLETE EXAMPLE You can try pasting this into Colab and it should work fine. Have fun! ```py import random from datasets import load_dataset from torch.utils.data import DataLoader # A mock tokenizer and functions for demonstration. class Tokenizer: def __init__(self): pass def __call__(self, example): return example def score_fn(score): # Transform Stockfish score and terminal outcomes. return score def preprocess(example, tokenizer, score_fn): # Get number of moves made in the game... max_ply = len(example['moves']) # ...and pick a position at random. random_position = random.randint(0, max_ply-2) # Get the FEN of our random choice. fen = example['fens'][random_position] # To get the move that leads to the *next* FEN, we have to add # +1 to the index. Same with the score, which is the evaluation # of that move. Please read the section about the data format clearly! move = example['moves'][random_position + 1] score = example['scores'][random_position + 1] # Transform data into the format of your choice. example['fens'] = tokenizer(fen) example['moves'] = tokenizer(move) example['scores'] = score_fn(score) return example tokenizer = Tokenizer() # Load dataset. dataset = load_dataset(path="mauricett/lichess_sf", split="train", streaming=True, trust_remote_code=True) # Shuffle and apply your own preprocessing. dataset = dataset.shuffle(seed=42) dataset = dataset.map(preprocess, fn_kwargs={'tokenizer': tokenizer, 'score_fn': score_fn}) # PyTorch dataloader dataloader = DataLoader(dataset, batch_size=1, num_workers=1) for batch in dataloader: # do stuff print(batch) break # Batch now looks like: # {'WhiteElo': tensor([1361]), 'BlackElo': tensor([1412]), 'fens': ['3R4/5ppk/p1b2rqp/1p6/8/5P1P/1PQ3P1/7K w - -'], 'moves': ['g8h7'], 'scores': ['-535']} # Much better! ```

提供机构:
mauricett
原始信息汇总

数据集概述

数据集名称

Lichess Games With Stockfish Analysis

数据集描述

该数据集是Lichess数据库的精简版本,仅包含具有Stockfish评估的游戏。目前,数据集包含2023年全年的游戏,总计超过1亿局游戏和超过20亿个局面。游戏以比原始PGN数据更快的处理格式存储。

数据格式

每个样本包含一局完整的国际象棋游戏,以字典形式存储,包含以下键:

  1. example[fens] - 一个FEN列表,格式稍作简化,缺少半移动时钟和全移动数。起始位置已被排除。
  2. example[moves] - 一个UCI格式的移动列表。example[moves][42] 是导致 example[fens][42] 位置的移动。
  3. example[scores] - 一个Stockfish评估列表(以百分之一 pawn为单位),以及游戏的最终结果条件(如果有)。评估是从下一个移动玩家的角度进行的。如果 example[fens][42] 是黑方的回合,example[scores][42] 将是黑方的视角。如果游戏以终端条件结束,列表的最后一个元素是字符串 C(将死)、S(逼和)或 I(不足材料)。具有其他结果条件的游戏已被排除。
  4. example[WhiteElo], example[BlackElo] - 玩家的Elo评分。

数据加载

数据集支持流式加载,无需本地存储(当前约100GB)。加载数据集需要设置 trust_remote_code=True 以执行自定义数据加载脚本。

py

加载数据集

dataset = load_dataset(path="mauricett/lichess_sf", split="train", streaming=True, trust_remote_code=True)

数据预处理

用户需要定义自己的函数来将数据转换为所需格式。以下是一个示例预处理函数:

py

示例预处理函数

def preprocess(example, tokenizer, score_fn): max_ply = len(example[moves]) random_position = random.randint(0, max_ply-2) fen = example[fens][random_position] move = example[moves][random_position + 1] score = example[scores][random_position + 1] example[fens] = tokenizer(fen) example[moves] = tokenizer(move) example[scores] = score_fn(score) return example

数据集操作

使用 dataset.shuffle() 进行数据集洗牌,使用 dataset.map() 应用预处理函数。

py

数据集洗牌和预处理

dataset = dataset.shuffle(seed=42) dataset = dataset.map(preprocess, fn_kwargs={tokenizer: tokenizer, score_fn: score_fn})

完整示例

以下是一个完整的示例代码,展示了如何加载、预处理和使用数据集:

py import random from datasets import load_dataset from torch.utils.data import DataLoader

class Tokenizer: def init(self): pass def call(self, example): return example

def score_fn(score): return score

def preprocess(example, tokenizer, score_fn): max_ply = len(example[moves]) random_position = random.randint(0, max_ply-2) fen = example[fens][random_position] move = example[moves][random_position + 1] score = example[scores][random_position + 1] example[fens] = tokenizer(fen) example[moves] = tokenizer(move) example[scores] = score_fn(score) return example

tokenizer = Tokenizer()

dataset = load_dataset(path="mauricett/lichess_sf", split="train", streaming=True, trust_remote_code=True)

dataset = dataset.shuffle(seed=42) dataset = dataset.map(preprocess, fn_kwargs={tokenizer: tokenizer, score_fn: score_fn})

dataloader = DataLoader(dataset, batch_size=1, num_workers=1)

for batch in dataloader: print(batch) break

搜集汇总
数据集介绍
mauricett/lichess_sf 数据集图片
构建方式
该数据集源自Lichess平台2023年全年的对局记录,经过精炼与压缩,仅保留经过Stockfish引擎评估的棋局。原始PGN格式数据被转换为更高效的存储格式,便于快速处理。数据集包含超过1亿局对局和20亿个局面,每个样本以字典形式存储,包含FEN列表、UCI格式的着法列表、Stockfish评估分数(以厘兵为单位)以及双方棋手的等级分。终端局面以特定字符串标记(如'C'表示将杀)。
使用方法
使用该数据集时,需通过HuggingFace Datasets库以流式模式加载,并启用`trust_remote_code=True`以执行自定义解压脚本。用户应自定义预处理函数,如随机选取局面并提取对应的着法和评估分数。注意索引对齐:`moves[i]`和`scores[i]`对应`fens[i]`的后续状态。利用`dataset.shuffle()`和`dataset.map()`进行打乱与并行预处理,最终可配合PyTorch DataLoader进行批量训练。
背景与挑战
背景概述
国际象棋作为人工智能研究的经典试验田,长期以来为机器学习算法提供了极具挑战性的决策环境。在此背景下,mauricett/lichess_sf数据集应运而生,由研究者在2023年基于全球最大的开源国际象棋平台Lichess的棋谱库构建而成。该数据集的核心创新在于,它不仅收录了超过1亿局完整对局,更整合了顶级引擎Stockfish对超过20亿个局面的深度评估分数,将原始PGN格式压缩为更易处理的紧凑结构。这一庞大规模与精细标注的结合,使得研究者能够直接获取从初始局面到终局的完整决策链与对应评估值,为探索棋类AI的策略学习、局面评估与搜索算法优化提供了前所未有的数据基础,深刻推动了国际象棋人工智能领域从人工特征工程向数据驱动范式的转变。
当前挑战
该数据集所面临的挑战首先体现在领域问题的复杂性上:国际象棋的决策空间极其庞大,局面评估不仅需考虑棋子价值,更涉及深远战术组合与长期战略规划,要求模型从海量对局中捕捉非线性的高阶模式。构建过程中的挑战同样严峻,数据清洗需剔除不完整或异常对局,确保每局棋的FEN序列、UCI走法与Stockfish评分严格对齐;压缩存储虽提升处理速度,却增加了数据加载与解析的工程复杂度。此外,Stockfish评分本身存在引擎局限,如对某些封闭局面的误判,而玩家等级分(Elo)的波动性也引入了噪声,这些因素均对基于该数据集训练的模型泛化能力构成考验。
常用场景
经典使用场景
在国际象棋人工智能与计算博弈领域,mauricett/lichess_sf数据集凭借其海量的对局记录与Stockfish引擎的深度评估,成为训练和评估棋类策略模型的核心资源。研究者常利用该数据集中超过100万局对局与20亿个棋局位置,结合其提供的FEN字符串、UCI格式走法与引擎评分,构建监督学习或强化学习框架。例如,通过随机采样的方式提取棋局中的中间局面、对应走法与评估分数,用于训练神经网络模型预测最优走法或局面价值。该数据集的紧凑存储格式与流式加载特性,使得大规模分布式训练成为可能,显著降低了数据预处理的门槛。
解决学术问题
在学术研究中,该数据集有效解决了棋类人工智能领域长期存在的两大难题:高质量标注数据的稀缺性与数据格式的异构性。传统PGN格式对局数据缺乏标准化的局面评估,而Stockfish引擎的介入为每个局面提供了精确的分数(以厘兵为单位)与终局条件(如将杀、逼和),从而支撑起局面价值函数的回归建模。此外,数据集统一了FEN与UCI格式,消除了研究者自行解析与对齐数据的繁琐工作。这一数据资源的开放,推动了从局面评估网络到走法策略网络等一系列基础模型的进步,为AlphaZero等自博弈方法的性能对比提供了可复现的基准。
实际应用
在现实应用层面,该数据集广泛服务于棋类教学辅助系统、在线对弈平台的智能分析引擎以及棋力提升工具。开发者可基于数据集中包含的玩家等级分(Elo)与引擎评估,构建个性化推荐系统,为不同水平的棋手提供针对性的局面改进建议。例如,通过分析特定等级分区间内常见失误走法对应的引擎评分变化,系统能够自动生成错误复盘报告。同时,该数据集也用于训练实时棋局解说模型,在直播或对弈过程中生成自然语言评述,显著提升了棋类娱乐与教育的智能化水平。
数据集最近研究
最新研究方向
在国际象棋人工智能研究领域,mauricett/lichess_sf数据集凭借其海量的对局与Stockfish引擎深度分析结果,为棋类强化学习与神经网络的训练提供了前所未有的数据支撑。该数据集涵盖了2023年全年超过1亿局棋谱和20亿个局面,其独特的压缩存储格式极大提升了数据处理效率,使得研究者能够高效挖掘棋局中的战略模式与评估函数。当前前沿方向聚焦于利用该数据集改进AlphaZero类算法的搜索效率,探索基于Transformer的棋局理解模型,以及开发更精准的残局评估网络。随着Stockfish引擎本身成为研究基准,该数据集在推动可解释AI与博弈论交叉研究中扮演着关键角色,其开放许可特性更促进了全球棋类AI社区的协作创新。
以上内容由遇见数据集搜集并总结生成
二维码
社区交流群
二维码
科研交流群
商业服务