Skip to main content

Synthetic Image Caption Generator

A tool that uses Qwen to generate image captions similar to those in a given dataset. The model learns from example prompts and generates new captions that match their style and structure.

This tool is designed to be used for deep generative dataset augmentation.

Features

  • Uses Qwen from HuggingFace🤗 Transformers
  • Supports few-shot learning with configurable number of examples
  • Reads prompts from .txt files in a dataset directory
  • Flexible CLI with multiple configuration options
  • Can generate multiple captions in one run
  • Output to file or stdout

Installation

To install from PyPI:

pip install synthetic-image-caption-generator

To install locally:

pip install -e .

Or install dependencies manually:

pip install transformers>=4.30.0 torch>=2.0.0 accelerate>=0.20.0

Usage

Downloading Models

Before generating captions, you can pre-download a model to the Hugging Face cache for offline use:

# Download the default model (qwen2.5-32b)
download-caption-model

# Download a specific model
download-caption-model --model qwen2.5-7b

# Download a larger model
download-caption-model --model qwen2.5-72b

Basic Usage

Generate a caption using 5 example prompts from the dataset:

generate-captions /path/to/dataset

Specify Number of Examples

Use a different number of example prompts (e.g., 10):

generate-captions /path/to/dataset --num-examples 10

Choose a Model

Select a different Qwen model (e.g., smaller or larger):

# Use the smaller 7B model
generate-captions /path/to/dataset --model qwen2.5-7b

# Use the larger 72B model
generate-captions /path/to/dataset --model qwen2.5-72b

# Use Qwen3 14B
generate-captions /path/to/dataset --model qwen3-14b

Generate Multiple Captions

Generate 5 captions:

generate-captions /path/to/dataset --num-generate 5

Specify Object Information

Include information about what's in the image:

generate-captions /path/to/dataset --object-info "the image contains 3 elephants"
generate-captions /path/to/dataset --object-info "the main crop in the field is soybean"

Save to File

Save generated captions to a file:

generate-captions /path/to/dataset --num-generate 10 --output generated_captions.txt

Advanced Options

generate-captions /path/to/dataset \
  --model qwen2.5-14b \
  --num-examples 8 \
  --num-generate 5 \
  --temperature 0.8 \
  --max-length 300 \
  --object-info "a cityscape with tall buildings" \
  --output captions.txt

Command-Line Arguments

generate-captions

  • dataset_dir (required): Path to directory containing .txt files with caption prompts
  • --model: Qwen model to use (default: qwen2.5-32b). Options: qwen2.5-0.5b, qwen2.5-1.5b, qwen2.5-3b, qwen2.5-7b, qwen2.5-14b, qwen2.5-32b, qwen2.5-72b, qwen3-14b, qwen3-32b
  • --num-examples: Number of example prompts to provide to the model (default: 5)
  • --num-generate: Number of captions to generate (default: 1)
  • --output: Output file to save generated captions (optional, prints to stdout if not specified)
  • --temperature: Temperature for text generation (default: 0.7, higher = more creative)
  • --max-length: Maximum length of generated caption (default: 256)
  • --object-info: Information about objects/content in the image (e.g., "the image contains 3 elephants")

download-caption-model

  • --model: Qwen model to download (default: qwen2.5-32b). Options: qwen2.5-0.5b, qwen2.5-1.5b, qwen2.5-3b, qwen2.5-7b, qwen2.5-14b, qwen2.5-32b, qwen2.5-72b, qwen3-14b, qwen3-32b

Dataset Format

The dataset directory should contain .txt files, each with one or more prompts. Each prompt should be on its own line.

Example dataset structure:

dataset/
├── captions1.txt
├── captions2.txt
└── captions3.txt

Example content of captions1.txt:

A serene landscape with mountains in the background and a lake in the foreground
An urban street scene with people walking and cars passing by
A close-up portrait of a person smiling at the camera

Requirements

  • Python >= 3.8
  • CUDA-capable GPU recommended
  • Sufficient GPU memory depending on chosen model:
    • Small models (0.5B-3B): 4-8GB VRAM
    • Medium models (7B-14B): 12-24GB VRAM
    • Large models (32B): 24-40GB VRAM
    • Extra large models (72B): 40GB+ VRAM or quantization required

How It Works

  1. The script reads all prompts from .txt files in the specified directory
  2. It randomly samples a specified number of prompts as examples
  3. These examples are formatted into a few-shot prompt for Qwen2.5-32B-Instruct
  4. The model generates a new caption that matches the style and structure of the examples
  5. The generated caption(s) are output to stdout or saved to a file

License

MIT

Metadata

Release files for synthetic-image-caption-generator 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 synthetic-image-caption-generator 0.0.4
File Size Uploaded Provenance Actions
synthetic_image_caption_generator-0.0.4.tar.gz 6.3 kB With provenance Details for synthetic_image_caption_generator-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for synthetic-image-caption-generator 0.0.4
File Interpreter ABI Platform Actions
synthetic_image_caption_generator-0.0.4-py3-none-any.whl Python 3 none any Details for synthetic_image_caption_generator-0.0.4-py3-none-any.whl

Total release size: 14.6 kB

Release files / synthetic_image_caption_generator-0.0.4.tar.gz

Download URL synthetic_image_caption_generator-0.0.4.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3687250150fd118f5275f35af86e033a6c2f3d5b8c905cd381c9471499d986fd
BLAKE2b-256 checksum
How to use checksums
e1290c4b7936d0f72e78410bae15ec369d44abc4269841acc9f5c60961e00ad0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 22, 2026.

Transparency log

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

Download URL synthetic_image_caption_generator-0.0.4-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae2d1d6054cf9bfb29eaf54ff4404a6c91ddc498ae6b7a144be5f5a36fbc600a
BLAKE2b-256 checksum
How to use checksums
d70fff317f98b5ce7c97088e3efd3737726610e5e30fc2855d911141c469d30b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 22, 2026.

Transparency log

Security for synthetic-image-caption-generator 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for synthetic_image_caption_generator-0.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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