Metadata-Version: 2.4
Name: conducttraining
Version: 0.3.0
Summary: Insert any CSV, JSONL, TXT, or image folder -> auto-label & blind LLM jury -> 3-second flashcard UI -> kappa receipt & Colab trainer.
Author: Shuhan He
Author-email: ConductScience Foundation <foundation@conductscience.org>
License: MIT
Project-URL: Homepage, https://conductscience-foundation.github.io/conducttraining/
Project-URL: Repository, https://github.com/ConductScience-Foundation/conducttraining
Project-URL: Issues, https://github.com/ConductScience-Foundation/conducttraining/issues
Project-URL: Organization, https://conductscience.org
Keywords: active-learning,annotation,cohens-kappa,data-centric-ai,dataset-curation,dpo,fine-tuning,fleiss-kappa,inter-rater-reliability,llm-as-a-judge,weak-supervision
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic<3.0,>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/banner-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/banner-light.svg">
    <img alt="ConductTraining (ctrain) — Zero-Docker Dataset Distillation and 3-Second Flashcard Labeling" src="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/banner-light.svg" width="100%">
  </picture>
</p>

<p align="center">
  <a href="https://github.com/ConductScience-Foundation/conducttraining/actions/workflows/ci.yml"><img alt="CI Status" src="https://github.com/ConductScience-Foundation/conducttraining/actions/workflows/ci.yml/badge.svg"></a>
  <a href="https://pypi.org/project/conducttraining/"><img alt="PyPI" src="https://img.shields.io/pypi/v/conducttraining?color=F8D458&labelColor=10141A"></a>
  <img alt="Python 3.10+" src="https://img.shields.io/badge/python-3.10%2B-1E42A8?labelColor=10141A">
  <img alt="Runtime Dependencies: 1 (pydantic)" src="https://img.shields.io/badge/runtime%20deps-1%20(pydantic)-15803D?labelColor=10141A">
  <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-10141A?labelColor=10141A">
</p>

# ConductTraining (`ctrain`)

> **Insert any CSV, TSV, JSONL, TXT, or image folder -> auto-label with CPU rules & blind 3-model LLM juries -> review edge cases in a 3-second flashcard UI -> emit cryptographic Cohen/Fleiss kappa receipts & a disconnect-proof Google Colab A100 LoRA trainer.** Zero Docker, zero PostgreSQL, **1 runtime dependency (`pydantic>=2.0`)**.

Built by **[Shuhan He](https://github.com/ShuhanCS)** (`https://github.com/ShuhanCS`) and **[ConductScience](https://conductscience.com)** (`https://conductscience.com`), published openly through **[ConductScience Foundation](https://github.com/ConductScience-Foundation)** (`https://conductsciencefoundation.org`).

<p align="center">
  <sub>ATTRIBUTED TO &amp; SUPPORTED BY</sub>
  <br/><br/>
  <a href="https://conductscience.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/.github/main/assets/cs-badge-dark.svg"><img alt="ConductScience" src="https://raw.githubusercontent.com/ConductScience-Foundation/.github/main/assets/cs-badge-light.svg" height="38" align="middle"></picture></a>
  &nbsp;&nbsp;&nbsp;
  <a href="https://github.com/ShuhanCS"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/.github/main/assets/shuhancs-badge-dark.svg"><img alt="Shuhan He (@ShuhanCS)" src="https://raw.githubusercontent.com/ConductScience-Foundation/.github/main/assets/shuhancs-badge-light.svg" height="38" align="middle"></picture></a>
</p>

---

## Live Interface Preview

Every labeling session ships with WCAG 2.2 AA Light and Dark modes (press `T` anytime), keyboard-first `1`-`9` hotkeys, blind dual-reviewer URLs (`?reviewer=alice` vs `?reviewer=bob`), and append-only `fsync` JSONL storage.

### 3-Second Flashcard Review UI (`ctrain start` / `ctrain cards`)

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-flashcard-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-flashcard-light.png">
    <img alt="ConductTraining 3-Second Flashcard UI (Light and Dark Mode)" src="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-flashcard-light.png" width="96%">
  </picture>
</p>

<details>
<summary>View both Light and Dark mode screenshots side by side</summary>

| Light Mode (Warm Sand `#FBFAF6`) | Dark Mode (Low-Glare Slate `#0E1218`) |
| --- | --- |
| ![Flashcard UI Light](https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-flashcard-light.png) | ![Flashcard UI Dark](https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-flashcard-dark.png) |

</details>

### Zero-Backend Local Browser App (`ctrain export-webapp`)

**Try it live right now (zero install, files stay local in your browser):** https://conductscience-foundation.github.io/conducttraining/

Drag and drop `.csv`, `.tsv`, `.jsonl`, `.json`, `.txt`, or image folders directly in the browser with zero server, zero upload, and instant `.jsonl` + kappa receipt + Colab `.ipynb` export:

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-webapp-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-webapp-light.png">
    <img alt="ConductTraining Zero-Backend Browser App" src="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/ui-webapp-light.png" width="96%">
  </picture>
</p>

---

## What Is This?

Most data-labeling and fine-tuning stacks force you to write bespoke JSON converters, boot Docker + PostgreSQL, and stitch together five disconnected tools for programmatic rules, LLM pre-labeling, human review, inter-rater reliability, and LoRA training.

`conducttraining` (`ctrain`) installs in under one second with **one runtime dependency (`pydantic>=2.0`)** and runs straight on the raw files already on disk.

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/architecture-funnel-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/architecture-funnel-light.svg">
    <img alt="ConductTraining 3-Tier Active Distillation Pipeline" src="https://raw.githubusercontent.com/ConductScience-Foundation/conducttraining/main/assets/architecture-funnel-light.svg" width="100%">
  </picture>
</p>

---

## Quickstart

### Install

```bash
pip install conducttraining
```

Or install from source for development:

```bash
git clone https://github.com/ConductScience-Foundation/conducttraining.git
cd conducttraining
python -m pip install -e ".[dev]"
```

### Start Labeling Any File or Image Folder in One Command

```bash
# Label any CSV, TSV, JSONL, or TXT file directly:
ctrain start examples/text_and_quotes/raw_documents.csv \
  --prompt "Does the source passage support the claim?" \
  --labels "Supported,Unsupported,Contradicted"

# Or point directly at any directory of images (.png, .jpg, .webp, .svg):
ctrain start examples/shape_images/images/ \
  --prompt "Which geometric shape is shown?" \
  --labels "Circle,Square,Triangle"
```

### Choose Your Workflow Mode

| Mode | Command | Runtime Needed | Best For |
| --- | --- | --- | --- |
| **1-Command Local Server** | `ctrain start data.csv --prompt "..." --labels "A,B,C"` | Python 3.10+ (`pydantic`) | Fast keyboard labeling with append-only `fsync` JSONL and blind dual-reviewer links |
| **Full 3-Tier Distillation** | `ingest -> auto -> jury -> cards -> score -> split -> export-colab` | Python 3.10+ (+ optional LLM API / vLLM) | Distilling 10k to 1M records down to ~400 high-entropy human cards + Colab A100 training |
| **Zero-Backend Browser App** | `ctrain export-webapp --out-dir ./web_app` | Any modern browser (no server) | Sharing a single static `index.html` with collaborators whose files must stay on their machine |

---

## Four Native Task Card Modes

`conducttraining.schema` auto-detects the card layout from your columns or directory contents (and lets you override any column via `--text-col`, `--group-col`, `--option-a-col`, `--option-b-col`, `--claim-col`, or `--image-col`):

| Mode | Triggered By | Built-In Ergonomics |
| --- | --- | --- |
| `text_classification` | Text / passage column or line-delimited `.txt` | Automatic `<mark>` keyword highlighting, group badges, `1`-`9` hotkeys |
| `quote_verification` | Claim + source passage columns | Enforces character-exact substring verification (`verify_verbatim_quote`) to reject hallucinated LLM citations |
| `pairwise_dpo` | Option A + Option B response columns | Side-by-side preference layout exporting cleanly into `TRL` `DPOTrainer` |
| `vision_card` | Image folder or image path/URL column | Path-jailed local media serving, click-to-zoom, and low-glare dark mode (`T`) |

---

## Scope: What ConductTraining Is For (and What It Is Not)

### In Scope

- **Zero-schema data ingestion** from `.csv`, `.tsv`, `.jsonl`, `.json`, `.txt`, and local image folders.
- **3-tier active distillation:** deterministic CPU rules (`ctrain auto`), blind multi-model LLM juries (`ctrain jury`), and high-speed human review (`ctrain cards`).
- **Blind human calibration:** jury predictions stay hidden on active review cards so human raters are never anchored by model guesses.
- **Zero group leakage:** locks every `group_id` (document ID, thread ID, folder, or recording ID) into a single `train`/`dev`/`test` split with a Merkle SHA-256 `DatasetReceipt`.
- **Audit-grade inter-rater metrics:** exact Cohen's kappa, Fleiss' kappa (3+ raters/models), Wilson 95% confidence intervals, confusion matrices, and Jury-vs-Human calibration tables.
- **Disconnect-proof Colab A100 notebook export:** Drive-checkpointed cells for subprocess-isolated `vLLM`, `DeBERTa-v3`, and `Unsloth` + `TRL` 4-bit QLoRA (`SFTTrainer` / `DPOTrainer`).

### Out of Scope (Deliberate Design Decisions)

- **Pixel polygon / bounding-box segmentation editors:** `vision_card` is built for rapid image classification, quality triage, and preference ranking, not freehand mask drawing.
- **Hosted multi-tenant SaaS user management:** `ctrain` runs locally with zero Docker and zero database servers by design.
- **Opaque telemetry or automatic cloud uploads:** your files stay strictly on disk unless you explicitly point `ctrain jury` at an external API endpoint.

---

## End-to-End CLI Pipeline

```bash
# 1. Convert any raw CSV/TSV/TXT/JSONL or image folder into TaskCard JSONL
ctrain ingest examples/text_and_quotes/raw_documents.csv \
  --prompt "Does the source passage support the claim?" \
  --labels "Supported,Unsupported,Contradicted" \
  -o work/cards.jsonl

# 2. Tier-1 deterministic rules (CPU, ~100k items/sec, $0)
ctrain auto work/cards.jsonl \
  --rules examples/text_and_quotes/rules.json \
  --silver-out work/silver_t1.jsonl \
  --remaining-out work/tier2_queue.jsonl

# 3. Tier-2 blind 3-model LLM jury (mock:* offline, or openai:/vllm:/anthropic:/gemini:/ollama:)
ctrain jury work/tier2_queue.jsonl \
  --juror mock:juror-qwen \
  --juror mock:juror-llama \
  --juror mock:juror-gemma \
  --require-quote \
  --silver-out work/silver_t2.jsonl \
  --deck-out work/review_deck.json

# 4. Tier-3 3-second flashcard web app (blind dual-annotator links)
ctrain cards work/review_deck.json --judgments work/judgments.jsonl --port 8788
# Open http://127.0.0.1:8788/?reviewer=alice and http://127.0.0.1:8788/?reviewer=bob

# 5. Compute Cohen's kappa, Fleiss' kappa, Wilson 95% CIs, and Markdown report
ctrain score work/review_deck.json examples/text_and_quotes/sample_judgments.jsonl \
  --out work/BENCHMARK_RECEIPT.json \
  --markdown work/BENCHMARK_REPORT.md

# 6. Zero-leakage group train/dev/test split with Merkle SHA-256 receipt
ctrain split work/cards.jsonl --out-dir work/splits

# 7. Export disconnect-proof Google Colab A100 trainer + standalone static web app
ctrain export-colab --out work/conducttraining_a100.ipynb --track both
ctrain export-webapp --out-dir work/web_service
```

---

## Python API Example

```python
from conducttraining import (
    ABSTAIN,
    AutoLabelPipeline,
    BlindJuryEngine,
    MockJuryProvider,
    TaskCard,
    ingest_any_data,
    labeling_function,
    split_cards_zero_leakage,
)

cards = ingest_any_data(
    "examples/text_and_quotes/raw_documents.csv",
    prompt="Does the passage support the claim?",
    labels="Supported,Unsupported,Contradicted",
)

@labeling_function(name="low_confidence_score")
def lf_low_score(card: TaskCard) -> str | None:
    score = card.metadata.get("confidence_score")
    if score is not None and float(score) < 0.25:
        return "unsupported"
    return ABSTAIN

silver_t1, queue_t2, _, _ = AutoLabelPipeline([lf_low_score]).run_batch(cards)
jury = BlindJuryEngine([
    MockJuryProvider("juror-qwen"),
    MockJuryProvider("juror-llama"),
    MockJuryProvider("juror-gemma"),
])
silver_t2, review_deck, _, _ = jury.run_batch(queue_t2)
splits, receipt = split_cards_zero_leakage(cards)
assert receipt.zero_group_leakage is True
```

---

## Pluggable Jury Providers (Python Stdlib HTTP, Zero Extra SDKs)

| Provider Class | CLI Prefix | Use Case |
| --- | --- | --- |
| `MockJuryProvider` | `mock:<name>` | Deterministic CPU offline testing and CI smoke checks |
| `OpenAICompatibleProvider` | `openai:<model>` | OpenAI API or any OpenAI-compatible inference server |
| `VLLMBatchProvider` | `vllm:<model>` | Local or Colab A100 batched open-weight model serving |
| `OllamaProvider` | `ollama:<model>` | Local workstation models via Ollama |
| `AnthropicProvider` | `anthropic:<model>` | Anthropic Claude models |
| `GeminiProvider` | `gemini:<model>` | Google Gemini models |

---

## Runnable Examples & Documentation

| Path | Description |
| --- | --- |
| `examples/text_and_quotes/` | Raw CSV ingestion, quote verification, side-by-side A/B preference cards, 3-rater blind kappa scoring, and Colab export |
| `examples/shape_images/` | Raw image folder ingestion with CPU-generated SVG shapes, path-jailed local serving, and dual-rater kappa receipt |
| `docs/COMPETITIVE_LANDSCAPE.md` | Architectural comparison against Argilla, Label Studio, Prodigy, Snorkel, and Doccano |
| `STYLE_GUIDE.md` | WCAG 2.2 AA color tokens (Light/Dark), typography, and keyboard-first UI copy specification |
| `CHANGELOG.md` | Version history (`0.1.0` through `0.3.0`) |

---

## Testing & Repository Hygiene (100% CPU, Ephemeral Ports)

Every push and pull request runs the full test suite on Ubuntu and Windows across Python 3.10, 3.11, and 3.12, including automated checks for zero secrets, zero local filesystem paths, and version/citation synchronization:

```bash
python -m pytest -v
```

---

## Attribution, Links & Citation

- **Repository:** https://github.com/ConductScience-Foundation/conducttraining
- **Author:** Shuhan He (https://github.com/ShuhanCS, ORCID: https://orcid.org/0000-0002-9902-5077)
- **Supported by:** ConductScience (https://conductscience.com)
- **Open Research Hub:** https://conductscience.org
- **Foundation Hub:** https://conductsciencefoundation.org
- **Organization GitHub:** https://github.com/ConductScience-Foundation
- **License:** MIT (`LICENSE`)
- **Citation:** See `CITATION.cff` (or click **Cite this repository** on GitHub).
