Skip to main content

fastdata

fastdata is a minimal library for generating synthetic data for training deep learning models. For example, below is how you can generate a dataset to train a language model to translate from English to Spanish.

First you need to define the structure of the data you want to generate. claudette, which is the library that fastdata uses to generate data, requires you to define the schema of the data you want to generate.

from fastcore.utils import *
class Translation():
    "Translation from an English phrase to a Spanish phrase"
    def __init__(self, english: str, spanish: str): store_attr()
    def __repr__(self): return f"{self.english} ➡ *{self.spanish}*"

Translation("Hello, how are you today?", "Hola, ¿cómo estás hoy?")
Hello, how are you today? ➡ *Hola, ¿cómo estás hoy?*

Next, you need to define the prompt that will be used to generate the data and any inputs you want to pass to the prompt.

prompt_template = """\
Generate English and Spanish translations on the following topic:
<topic>{topic}</topic>
"""

inputs = [{"topic": "Otters are cute"}, {"topic": "I love programming"}]

Finally, we can generate some data with fastdata.

[!NOTE]

We only support Anthropic models at the moment. Therefore, make sure you have an API key for the model you want to use and the proper environment variables set or pass the api key to the FastData class FastData(api_key="sk-ant-api03-...").

from fastdata.core import FastData
fast_data = FastData(model="claude-3-haiku-20240307")
translations = fast_data.generate(
    prompt_template=prompt_template,
    inputs=inputs,
    schema=Translation,
)
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:01<00:00,  1.57it/s]
from IPython.display import Markdown
Markdown("\n".join(f'- {t}' for t in translations))
  • I love programming ➡ Me encanta la programación
  • Otters are cute ➡ Las nutrias son lindas

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/AnswerDotAI/fastdata.git

or from pypi

$ pip install python-fastdata

If you’d like to see how best to generate data with fastdata, check out our blog post here and some of the examples in the examples directory.

Developer Guide

If you are new to using nbdev here are some useful pointers to get you started.

Install fastdata in Development mode

# make sure fastdata package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to fastdata
$ nbdev_prepare

Release files for python-fastdata 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-fastdata 0.0.4
File Size Uploaded
python_fastdata-0.0.4.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-fastdata 0.0.4
File Interpreter ABI Platform
python_fastdata-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / python_fastdata-0.0.4.tar.gz

Download URL python_fastdata-0.0.4.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fa40b1479ba7555377e3c78fc3a0ee4e7ca19c3d83b094314eec04d2f35b599b
BLAKE2b-256 checksum
How to use checksums
693bc5802b1e2ec584cbd0ba6a2b404d05e875ef215c183ae0a42a566a3d4bd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / python_fastdata-0.0.4-py3-none-any.whl

Download URL python_fastdata-0.0.4-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
647acfcea0543c0d1325e2dc1bb60691d4151eda1bc3973a1d3aee615b5a3903
BLAKE2b-256 checksum
How to use checksums
2d051354a4081d3a93f677f6c965fe9e5a17876899a6f48569374c865ba4860d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page