Back to projects
Python Llama 3.1 Hugging Face DPO

Project Silkworm

An automated pipeline that spins out a growing DPO preference dataset. The same model answers every prompt twice under two system prompts, one expert and one terse, and the gap between the answers becomes the training signal. No human annotation is needed.

2,870 Accepted pairs
4,758 Generations attempted
17 Topic domains
63 Hub uploads

Snapshot from the pipeline's local stats, covering runs from 2026-06-08 to 2026-08-18. The Hub dataset is the source of truth for its current size.

A loop that generates, filters and uploads

01

Sample a prompt

topics.py picks a domain, a topic (about 50 per domain) and one of 30 prompt templates, such as “What is {topic} and why does it matter?”

02

Generate twice

generator.py asks Llama 3.1 8B Instruct through the Hugging Face Inference API: once as a thorough expert (chosen, up to 512 tokens) and once as a hurried assistant (rejected, up to 256 tokens).

03

Filter

A pair is dropped if the chosen answer is under 200 characters, the rejected under 30, or the two are identical.

04

Skip duplicates

Prompts that are already in the dataset are skipped, so the dataset only ever grows with new rows.

05

Batch and upload

Accepted pairs go to a pending file. Every 50 pairs, uploader.py merges them into a Parquet file and pushes it to the Hugging Face Hub.

06

Watch it run

main.py shows a live terminal dashboard. Ctrl+C stops cleanly and uploads the final batch.

Use it, with the licences in view

Five columns

prompt, chosen, rejected, topic and timestamp. Load it with load_dataset("iPwnds/Project-Silkworm") and use it straight away.

Built for DPO

The format works with TRL's DPOTrainer, so it plugs into preference-tuning pipelines without conversion.

Licences

The dataset is CC BY 4.0, plus the Llama 3.1 Community License because the outputs come from Llama 3.1. The code is MIT.

What the data is, and is not

Synthetic pairs

“Chosen” means “answered under the expert prompt”, not human-verified correctness, so answers can contain factual errors.

Mostly a length preference

The rejected side is deliberately low quality, so a model trained on it learns mostly a length and effort preference.

One model

Everything is generated by a single 8B model, so the dataset inherits that model's biases and gaps.

Built to be reproduced

Stack

Python 3.10+ Llama 3.1 8B Instruct HF Inference API Parquet pytest

Configuration

  • HF_MODEL sets the generation model
  • UPLOAD_EVERY defaults to 50 pairs
  • MIN_CHOSEN_LENGTH 200 and MIN_REJECTED_LENGTH 30
  • REQUEST_DELAY defaults to 1.5 seconds

Quick start

  • Clone the repo and create a virtual environment
  • pip install -r requirements.txt
  • Copy .env.example to .env and set HF_TOKEN and HF_DATASET_REPO
  • python main.py

Project layout

  • generator.py chosen and rejected generation, quality filter
  • topics.py topic lists and prompt templates
  • uploader.py local storage, stats and Hub upload
  • tests/ covers sampling, the filter and storage

See the data and the source

Project Silkworm is open source. The code is MIT, the dataset is CC BY 4.0, and the dataset lives on the Hugging Face Hub.

← braunf.com