Skip to main content

Create synthetic datasets with LLM generators and samplers

Project description

Chatan

Create diverse, synthetic datasets. Start from scratch or augment an existing dataset. Simply define your dataset schema as a set of generators, typically being LLMs with a prompt describing what kind of examples you want.

Installation

Basic installation (includes OpenAI, Anthropic, and core functionality):

pip install chatan

With optional features:

# For local model support (transformers + PyTorch)
pip install chatan[local]

# For advanced evaluation features (semantic similarity, BLEU score)
pip install chatan[eval]

# For all optional features
pip install chatan[all]

Getting Started

import asyncio
import chatan

async def main():
    # Create a generator
    gen = chatan.generator("openai", "YOUR_API_KEY")

    # Define a dataset schema
    ds = chatan.dataset({
        "topic": chatan.sample.choice(["Python", "JavaScript", "Rust"]),
        "prompt": gen("write a programming question about {topic}"),
        "response": gen("answer this question: {prompt}")
    })

    # Generate the data (async for concurrent API calls)
    df = await ds.generate(n=10)
    return df

df = asyncio.run(main())

Generator Options

API-based Generators (included in base install)

# OpenAI
gen = chatan.generator("openai", "YOUR_OPENAI_API_KEY")

# Anthropic
gen = chatan.generator("anthropic", "YOUR_ANTHROPIC_API_KEY")

Local Model Support (requires pip install chatan[local])

# HuggingFace Transformers
gen = chatan.generator("transformers", model="microsoft/DialoGPT-medium")

Examples

Create Data Mixes

import asyncio
from chatan import dataset, generator, sample

async def main():
    gen = generator("openai", "YOUR_API_KEY")

    mix = [
        "san antonio, tx",
        "marfa, tx",
        "paris, fr"
    ]

    ds = dataset({
        "id": sample.uuid(),
        "topic": sample.choice(mix),
        "prompt": gen("write an example question about the history of {topic}"),
        "response": gen("respond to: {prompt}"),
    })

    df = await ds.generate(n=100)
    return df

df = asyncio.run(main())

Augment datasets

import asyncio
from chatan import generator, dataset, sample
from datasets import load_dataset

async def main():
    gen = generator("openai", "YOUR_API_KEY")
    hf_data = load_dataset("some/dataset")

    ds = dataset({
        "original_prompt": sample.from_dataset(hf_data, "prompt"),
        "variation": gen("rewrite this prompt: {original_prompt}"),
        "response": gen("respond to: {variation}")
    })

    df = await ds.generate(n=100)
    return df

df = asyncio.run(main())

Evaluation

Evaluate rows inline or compute aggregate metrics:

import asyncio
from chatan import dataset, eval, sample

async def main():
    ds = dataset({
        "col1": sample.choice(["a", "a", "b"]),
        "col2": "b",
        "score": eval.exact_match("col1", "col2")
    })

    df = await ds.generate(n=100)

    # Aggregate evaluation
    aggregate = ds.evaluate({
        "exact_match": ds.eval.exact_match("col1", "col2")
    })
    return df, aggregate

df, aggregate = asyncio.run(main())

Advanced Evaluation (requires pip install chatan[eval])

# Semantic similarity using sentence transformers
aggregate = ds.evaluate({
    "semantic_sim": ds.eval.semantic_similarity("col1", "col2")
})

# BLEU score evaluation
aggregate = ds.evaluate({
    "bleu": ds.eval.bleu_score("col1", "col2")
})

Installation Options Summary

Feature Install Command What's Included
Basic pip install chatan OpenAI, Anthropic, core sampling, basic evaluation
Local Models pip install chatan[local] + HuggingFace Transformers, PyTorch
Advanced Eval pip install chatan[eval] + Semantic similarity, BLEU scores, NLTK
Everything pip install chatan[all] All features above

Citation

If you use this code in your research, please cite:

@software{reetz2025chatan,
  author = {Reetz, Christian},
  title = {chatan: Create synthetic datasets with LLM generators.},
  url = {https://github.com/cdreetz/chatan},
  year = {2025}
}

Contributing

Community contributions are more than welcome, bug reports, bug fixes, feature requests, feature additions, please refer to the Issues tab.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatan-0.3.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatan-0.3.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file chatan-0.3.0.tar.gz.

File metadata

  • Download URL: chatan-0.3.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chatan-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b5401bb9c73ff8a90d5169744a3de428ac9d56970658e4290e73d367894bcf8e
MD5 09d4c7d9199506b1a0c889d6b01b6a36
BLAKE2b-256 373fdb9fe7be0956f28d465670ef7d0bf88f9ce4e6e5e3fd29e094f613ccedb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatan-0.3.0.tar.gz:

Publisher: publish.yml on cdreetz/chatan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatan-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: chatan-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chatan-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13d16ec36d254d2eee7a302abfcced10fa892b7e924d502b19a41d484e7625fc
MD5 7bcc89ab8bf13dc9c42bb2fd6bca9d15
BLAKE2b-256 dfe0f01026f8dead27671e1b1e6974df6a35951d4564ab6a5daa7a4c734a9d6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatan-0.3.0-py3-none-any.whl:

Publisher: publish.yml on cdreetz/chatan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page