--- license: mit language: - en - es task_categories: - text-generation - fill-mask size_categories: - 10K

PyMini Banner

# PyMini – A Compact Python Instruction Dataset for Small Language Models **PyMini** is a synthetic instruction dataset built by [Inserloft](https://inserloft.com) to teach Python programming to small language models (<2B parameters). It covers fundamental Python concepts through a diverse set of tasks — code prediction, bug fixing, function completion, explanation, and conceptual Q&A. Available in **English, Spanish, or bilingual** versions. ## Dataset Description PyMini provides a **high-quality, compact, and fully synthetic** dataset for fine-tuning models that need a solid grasp of Python without unnecessary complexity. Every example is generated programmatically, avoiding license issues and giving exact control over difficulty and coverage. - **Languages:** English (`en`), Spanish (`es`), or mixed (`both`) - **Number of examples:** Configurable; default release contains **~49,200 examples** (balanced across task types) - **Format:** Parquet (native), auto-converted from the original generation output - **Generated with:** Python script (no web scraping, no copyrighted code) ## Dataset Structure Each example is a JSON object with three fields: ```json { "instruction": "string (the task description)", "input": "string (code snippet or empty)", "output": "string (the expected answer/code/explanation)" } ``` Example (English): ```json { "instruction": "What is the output of the following code?", "input": "```python\nprint(3 + 4 * 5)\n```", "output": "23" } ``` The `input` field may be empty for tasks like "Write a function...". ## Task Types and Distribution | Task Type | Description | Approx. Weight | |---|---|---| | Predict Output | Given a code snippet, predict what it prints or evaluates to. | 25% | | Fix Bug | Correct syntax or logical errors in provided code. | 15% | | Fill Missing Line | Complete a partially written function body to fulfill its purpose. | 15% | | Write Function | Write a whole function from a natural language specification. | 20% | | Explain Code | Explain in plain language what a piece of code does. | 15% | | Concept Question | Answer a theoretical question about Python (e.g., "What is a list?"). | 10% | | Convert Code | Transform a loop into a comprehension or vice versa. | 5% | All code examples are self-contained and focus on core Python: variables, types, conditionals, loops, functions, lists, dictionaries, sets, file handling, exceptions, basic OOP, and comprehensions. ## Usage Load the dataset directly with the Hugging Face `datasets` library: ```python from datasets import load_dataset dataset = load_dataset("inserloft/PyMini", split="train") print(dataset[0]) ``` The dataset is stored natively in **Parquet** format, so it loads quickly and works out of the box with the `datasets` library, Dataset Viewer, and any Parquet-based tooling (pandas, DuckDB, Polars, etc.): ```python import pandas as pd df = pd.read_parquet("hf://datasets/inserloft/PyMini/train.parquet") print(df.head()) ``` ## Data Fields - **instruction** (str): Task description in the chosen language. - **input** (str): Optional code block (formatted with ` ```python ` fences) or empty string. - **output** (str): Expected response (may contain code blocks, explanations, or short answers). ## Data Splits The default release includes a single training split. For evaluation, we recommend either: - Holding out a random 5–10% of the data, or - Using a separate, handcrafted test set of real-world Python problems. ## Generation Process PyMini is entirely synthetic, generated by a Python script that randomly combines templates and safe code evaluation to produce diverse examples. Key aspects of the generation: - **Deduplication:** A hash-based deduplication step prevents exact duplicate examples. - **Reproducibility:** The script uses a fixed random seed (42) for reproducible generation. - **Safety:** All code snippets are evaluated in a restricted environment (no file system access, limited built-ins). - **Customization:** Adjust the number of examples, language (`--lang es/en/both`), and task weights by modifying the script. The generation script is included in the repository (`generate_pymini.py`). Output is converted to Parquet for storage and distribution on the Hub. ## Intended Use This dataset is intended for fine-tuning small language models (under ~2 billion parameters) to improve their Python understanding and code generation abilities. It is particularly suitable for: - Code assistants that must explain or fix Python code. - Educational tools that teach Python basics. - Lightweight models running in resource-constrained environments (edge, mobile). ## Out-of-Scope Use PyMini is not designed for: - Large-scale production code generation. - Mastering advanced Python libraries (NumPy, pandas, Django, etc.). - Security-sensitive code auditing. The examples are deliberately simple and may not cover edge cases of real-world software. ## Bias, Risks, and Limitations - **Synthetic nature:** The dataset was generated from templates, so it may lack the stylistic variance of human-written code. - **Language coverage:** While bilingual, the vocabulary is limited to common Python terminology. Colloquial expressions or complex natural language instructions may be underrepresented. - **No malicious code:** The dataset does not include security vulnerabilities or harmful patterns; it is purely educational. - **Potential overfitting:** Because of the templated generation, models may memorize patterns rather than generalizing to unseen code. Evaluate on diverse, real-world test sets. ## License This dataset is released under the MIT License. You are free to use, modify, and distribute it for both research and commercial purposes. ## Citation If you use PyMini in your work, please cite it as: ```bibtex @misc{pymini2025, title = {PyMini: A Compact Python Instruction Dataset for Small Language Models}, author = {Inserloft}, year = 2025, howpublished = {\url{https://huggingface.co/datasets/inserloft/PyMini}} } ``` ## Contributing Feel free to open issues or pull requests if you have suggestions for new task types, additional languages, or improvements to the generation script. ## Contact For questions, reach out via the Hugging Face community tab or through [inserloft.com](https://inserloft.com).