TinyPython
收藏资源简介:
TinyPython Tasks 是一个受 TinyStories 理念启发的合成 Python 数据集,其核心思想是:如果数据分布狭窄、干净且高质量,即使是非常小的语言模型也能学习有用的结构。与广泛的仓库代码或竞争性编程解决方案不同,TinyPython 专注于将简短的自然语言编程任务与完整的、类型化的、独立的 Python 函数配对。该数据集旨在为训练和评估小模型在 Python 语法、类型签名、有意义的标识符、简单控制流、内置数据结构和基本程序语义方面,提供一个紧凑的指令到代码语料库。数据集包含约 220 万个样本,由两个本地教师模型(Qwen2.5-Coder-7B 和 Phi-4 Mini)生成,分为两个生成批次:原始生成批次(small,约 20 万样本)和扩展生成批次(big,约 200 万样本)。每个样本至少包含两个核心字段:`task_description`(描述要编写函数的简短英文指令)和 `code`(一个带有参数和返回类型注解的完整 Python 3 函数)。完整记录还包括生成元数据,如使用的教师模型、结构化的语义种子和采样索引。数据通过从受控的语义种子空间合成生成,每个种子指定了输入类型、操作、条件、预期输出、边缘行为、实现风格、命名变体和指令措辞等属性,并经过严格的结构验证以确保代码质量。数据集范围有意限定,典型示例包括列表的计数、过滤、转换和搜索,简单的字符串操作,字典的选择、聚合和转换,两个整数列表的基本操作,以及使用内置 Python 数据结构的简短类型化函数。它排除了标准输入/输出程序、类、第三方库、仓库级上下文、长算法、广泛解释和任意高级编程任务。该数据集适用于训练小语言模型进行任务描述到函数的生成、简单 Python 代码的持续预训练、指令到代码生成的有监督微调、Python 和代码领域的分词器实验、受控缩放实验、小规模代码生成实验、数据管道和模型训练的冒烟测试,以及语法学习和基本语义代码生成的受控评估。需要注意的是,这是一个合成数据集,样本仅经过结构验证,未进行详尽的语义执行测试,因此可能存在逻辑错误或不一致。任务分布是刻意约束的,不代表真实世界的 Python 编程。模型若仅在此数据集上训练,可能会对短独立函数过拟合。
TinyPython Tasks is a synthetic Python dataset inspired by the TinyStories concept, with the core idea that even very small language models can learn useful structures if the data distribution is narrow, clean, and high-quality. Unlike broad repository code or competitive programming solutions, TinyPython focuses on pairing short natural language programming tasks with complete, typed, standalone Python functions. The dataset aims to provide a compact instruction-to-code corpus for training and evaluating small models in Python syntax, type signatures, meaningful identifiers, simple control flow, built-in data structures, and basic program semantics. The dataset contains approximately 2.2 million samples, generated by two local teacher models (Qwen2.5-Coder-7B and Phi-4 Mini), divided into two generation batches: the original generation batch (small, about 200,000 samples) and the extended generation batch (big, about 2 million samples). Each sample includes at least two core fields: `task_description` (a short English instruction describing the function to be written) and `code` (a complete Python 3 function with parameter and return type annotations). Full records also include generation metadata, such as the teacher model used, structured semantic seeds, and sampling indices. The data is synthesized from a controlled semantic seed space, where each seed specifies attributes like input types, operations, conditions, expected outputs, edge behaviors, implementation styles, naming variants, and instruction phrasing, and undergoes rigorous structural validation to ensure code quality. The dataset scope is intentionally limited, with typical examples including counting, filtering, transforming, and searching lists; simple string operations; selecting, aggregating, and transforming dictionaries; basic operations on two integer lists; and short typed functions using built-in Python data structures. It excludes standard input/output programs, classes, third-party libraries, repository-level context, long algorithms, extensive explanations, and arbitrary advanced programming tasks. The dataset is suitable for training small language models for task description-to-function generation, continued pre-training on simple Python code, supervised fine-tuning for instruction-to-code generation, tokenizer experiments in Python and code domains, controlled scaling experiments, small-scale code generation experiments, smoke testing for data pipelines and model training, and controlled evaluation of syntax learning and basic semantic code generation. Note that this is a synthetic dataset; samples are only structurally validated and not exhaustively tested for semantic execution, so logical errors or inconsistencies may exist. The task distribution is deliberately constrained and does not represent real-world Python programming. Models trained solely on this dataset may overfit to short independent functions.
数据集概述:TinyPython Tasks
核心概念
TinyPython 是一个合成Python数据集,其设计灵感来源于 TinyStories:通过构建狭窄、干净、高质量的数据分布,使即使是极小的语言模型也能学习到有用的结构。它专注于短的自然语言编程任务,并配以完整的、带类型注解的独立Python函数。
数据集规模
- 总样本数:约 220万 个示例。
- 数据拆分:所有数据属于一个逻辑上的
train分割,没有官方的训练/验证/测试划分。
数据来源与结构
数据集由两个本地教师模型生成,并分为两个运行批次:
- 教师模型:
- Qwen2.5-Coder-7B
- Phi-4 Mini
- 生成批次:
small:原始生成批次,约20万个示例。big:扩展生成批次,约200万个额外示例。
- 文件布局:
data/qwen25_coder_7b_small.jsonldata/phi4_mini_small.jsonldata/qwen25_coder_7b_big.jsonldata/phi4_mini_big.jsonl
数据集配置(Configurations)
该数据集提供了6种配置,方便用户按需加载:
| 配置名称 | 包含内容 | 说明 |
|---|---|---|
default |
全部4个文件 | 约220万示例,默认配置 |
combined |
全部4个文件 | 与 default 等价,显式别名 |
big |
仅 _big 文件 |
仅扩展生成批次(约200万示例) |
small |
仅 _small 文件 |
仅原始生成批次(约20万示例) |
qwen25_coder_7b |
仅Qwen2.5-Coder-7B生成的文件 | 按教师模型筛选 |
phi4_mini |
仅Phi-4 Mini生成的文件 | 按教师模型筛选 |
数据格式(JSONL)
每条记录包含以下字段:
task_description(str):描述要编写函数的简短英文指令。code(str):带有参数和返回类型注解的完整Python 3函数。model(str):生成该示例的本地教师模型。seed(dict):用于提示教师模型的结构化语义种子,包含输入类型、操作、条件、输出类型、边界行为、实现风格等属性。sample_index(int):针对特定语义种子的采样补全索引。
数据创建流程
- 语义种子空间:预先定义受控的语义种子(包括输入类型、操作、条件、输出期望、边界行为、实现风格、命名变化、指令措辞)。
- 生成:由本地指令调优的代码模型将每个种子转换为一个编程任务和对应的Python函数。
- 结构验证:生成后进行严格的结构验证,确保:
- 输出包含预期的
<task>和<code>部分。 - 代码可解析为有效的Python语法。
- 仅包含一个顶层函数。
- 所有参数和返回值都有类型注解。
- 禁止:装饰器、类、导入、测试、注释、文档字符串、
input()、print()。
- 输出包含预期的
数据集范围
典型示例包括:列表的计数、过滤、转换和搜索;简单字符串操作;字典的选择、聚合和转换;对两个整数列表的基本操作;使用内置Python数据结构的简短类型化函数。
明确排除:标准输入/输出程序、类、第三方库、仓库级上下文、长算法、长篇解释、任意高级编程任务。
预期用途
- 训练小模型进行任务描述到函数的生成。
- 在简单Python代码上进行持续预训练。
- 指令到代码生成的监督微调。
- Python和代码领域的分词器实验。
- 可控的缩放实验。
- 小规模代码生成实验。
- 数据管道和模型训练的冒烟测试。
- 语法学习和基本语义代码生成的可控评估。
局限性
- 合成性质:示例经过结构验证,但未通过语义执行测试全面验证,可能存在逻辑错误、描述不一致或边缘情况处理错误。
- 分布受限:任务分布刻意受限,不能代表真实世界的Python编程。
- 过拟合风险:仅在此数据集上训练的模型可能过拟合短函数,在更大程序、多文件项目、外部库等场景下表现不佳。
- 教师模型约束:用户应留意与教师模型相关的许可证和使用限制。
- 批次关系:
small和big批次生成过程和任务分布高度相似,不应被视为正式的训练/验证/测试集。
许可证
- Apache 2.0
语言
- 英语 (en)




