|
Download docs/trajectory_schema.md from Heisenger/sft-benchmark-trajectories: direct link, hf CLI and curl.
- Browser
- Download file 9.48 kB
-
https://huggingface.co/datasets/Heisenger/sft-benchmark-trajectories/resolve/main/docs/trajectory_schema.md
- Command line
-
hf download hf://datasets/Heisenger/sft-benchmark-trajectories/docs/trajectory_schema.md
-
curl -L -o trajectory_schema.md https://huggingface.co/datasets/Heisenger/sft-benchmark-trajectories/resolve/main/docs/trajectory_schema.md
9.48 kB
| # Canonical trajectory and SFT-view schema | |
| The library keeps one immutable, model-agnostic canonical record per imported | |
| attempt. Training examples are projections; they never mutate or truncate the | |
| canonical record. JSON objects are UTF-8 and may be stored as `.jsonl` or | |
| `.jsonl.gz` shards. | |
| ## Canonical record | |
| `Trajectory` schema version `1.0` contains: | |
| | Field | Meaning | | |
| |---|---| | |
| | `trajectory_id` | Stable content-addressed ID for one attempt. | | |
| | `task_id` / `task_key` | Native task ID and cross-source normalized task identity. Alternative attempts share `task_key`. | | |
| | `source` | `source_id`, direct URL, immutable revision, row/file locator and optional file SHA-256. | | |
| | `task_family`, `domain`, `split` | Benchmark family, environment domain and the untouched upstream split label. Derived train/evaluation assignment lives in `task_splits.jsonl.gz`. | | |
| | `events` | Causally ordered system, user, assistant and tool/environment events. | | |
| | `tools` | Available function definitions when published. Missing definitions are declared, never invented. | | |
| | `artifacts` | External image/file references and hashes when present. | | |
| | `provenance` | Demonstrator class, producer/scaffold, exact model when supplied and source metadata. | | |
| | `outcome` | Independent `success`, `status`, reward, termination reason and source metadata. `null` success is unknown, never failure. | | |
| | `verification` | Method, whether the source supplied executable verification, and its evidence. Independent reproduction is a separate evidence flag. | | |
| | `completeness` | `complete`, `incomplete` or `truncated`. A final submit call may terminate through an externally recorded outcome without a fabricated tool result. | | |
| | `missing_fields` | Explicit omissions such as unavailable tool definitions or a missing intermediate result. | | |
| | `transformations` | Ordered, versioned adapter operations. | | |
| | `raw_record` | Lossless original row/document. Non-JSON bytes are base64 tagged. | | |
| | `metadata` | Environment/version, trial, timing, cost and other non-causal attributes. | | |
| Each event has a stable `event_id`, role, text content, zero or more structured | |
| tool calls, an optional tool-result link, source metadata, missing fields and a | |
| `supervised` flag. Only assistant events may be supervised. Tool results must | |
| refer to an earlier call. Call IDs reused by an upstream source are namespaced | |
| deterministically while retaining the original ID. | |
| Canonical validation enforces non-empty identifiers, unique event/call IDs, | |
| causal tool-result linkage, assistant-only supervision, declared omissions for | |
| incomplete records and preservation of the raw source. It does not manufacture | |
| observations or reinterpret a missing outcome as failure. | |
| ## Independent quality and ranking record | |
| `rankings.jsonl.gz` is a derived index, kept separate so importing another | |
| attempt does not alter canonical records. Every row has separate fields for: | |
| - `demonstration_provenance`: expert/reference demonstration or recorded agent completion; | |
| - `outcome_category`: success, failure or unknown; | |
| - `verification_strength`: independently reproduced, source evaluator, source reported or unverified; | |
| - `completeness`, `source_confidence`, `quality_tier`, numeric tie-break score and `within_task_rank`; | |
| - SFT eligibility, an interaction hash, duplicate provenance and human-readable ranking reasons. | |
| The five tiers are: independently reproduced successful expert; independently | |
| reproduced successful agent; complete demonstration/rollout with credible | |
| source evidence; complete rollout with unknown outcome; failed, partial or | |
| inadequately observed. “Expert” does not mean optimal. No imported trajectory | |
| is called optimal. | |
| Ranks compare only identical `task_key` plus compatible `environment_key`. | |
| Tier dominates; action-observation coverage, verdict reliability, source | |
| confidence and (only for comparable successful attempts) a small efficiency | |
| tie-break follow. Identical interactions receive one interaction hash and list | |
| all contributing trajectory IDs. | |
| The final library collapses records only when causal interaction, outcome, | |
| reward, completeness and verification evidence agree. The retained ranking row | |
| lists every contributing ID; `duplicate_provenance.jsonl.gz` preserves each | |
| collapsed source revision and locator. Action-identical rows with conflicting | |
| outcome evidence remain separate. | |
| ## Full-trajectory SFT view | |
| `full_trajectory(record)` emits one sample: | |
| ```json | |
| { | |
| "view": "full-trajectory", | |
| "sample_id": "full:...", | |
| "trajectory_id": "trajectory:...", | |
| "task_id": "...", | |
| "task_key": "...", | |
| "events": ["complete causal event sequence"], | |
| "target_event_ids": ["every supervised assistant event ID"], | |
| "model_input": { | |
| "events": ["complete causal event sequence"], | |
| "tool_definitions": ["source-published tools"] | |
| }, | |
| "loss_mask": [false, false, true, false, true], | |
| "supervised_targets": ["assistant events selected by the mask"], | |
| "metadata": {"provenance and outcome for filtering/scoring, not model input"} | |
| } | |
| ``` | |
| System/user text and returned observations provide context. Loss applies only | |
| to assistant events whose mask value is true. A downstream tokenizer maps that | |
| event mask to token positions; this library does not impose a tokenizer, chat | |
| template, truncation or packing policy. | |
| ## Assistant-turn SFT view | |
| `assistant_turns(record)` yields one sample per supervised assistant decision: | |
| ```json | |
| { | |
| "view": "assistant-turn", | |
| "sample_id": "turn:...", | |
| "trajectory_id": "trajectory:...", | |
| "target_event_id": "event:...", | |
| "target_index": 4, | |
| "context": ["events 0 through 3 only"], | |
| "target": {"the recorded assistant event at index 4"}, | |
| "model_input": { | |
| "events": ["events 0 through 3 only"], | |
| "tool_definitions": ["source-published tools"] | |
| }, | |
| "supervised_target": {"the recorded assistant event at index 4"}, | |
| "metadata": {"parent/provenance/outcome; excluded from model_input"} | |
| } | |
| ``` | |
| For an assistant event at index `i`, context is exactly `events[:i]`. It cannot | |
| contain the target, its returned observation, later decisions, outcomes, | |
| reference answers or evaluator explanations. Tests assert this invariant. | |
| Consumers may shorten or mask the prefix after projection; canonical events | |
| remain untouched. | |
| ## Real example | |
| The successful SWE-Gym attempt | |
| `trajectory:10b50eb527ccd481a86cc00f` targets | |
| `swe:python__mypy-10308` and has 27 events / 12 assistant decisions: | |
| 1. OpenHands system instructions. | |
| 2. User task and repository context. | |
| 3. Assistant tool call. | |
| 4. Returned repository listing. | |
| 5. Next assistant tool call. | |
| 6. Returned observation, continuing until submission and the source test verdict. | |
| Its full view has one record, 27 event-level mask values and 12 targets. Its | |
| turn view has 12 records: turn zero sees events `[:2]`; turn one sees the first | |
| tool result as well; no turn sees a future result. | |
| Concrete outcome cases in the canonical shards are: | |
| - success: `trajectory:10b50eb527ccd481a86cc00f` (SWE-Gym execution result); | |
| - failure: `trajectory:d16d34d7b0acbbd878923aba` (same source, failed tests); | |
| - unknown: `trajectory:bcf4161ed7c363f7e3e03e1c` (TerminalTraj has action/output pairs but no task verdict). | |
| Render any of them with `scripts/inspect_library.py --trajectory-id ...`. The | |
| deterministic gallery independently selects compact representatives for every | |
| available source/outcome/tier combination and exposes each full interaction, | |
| every causal turn sample, the exact model-input object, supervised target, | |
| verification evidence, missing fields and side-by-side alternatives. | |
| ## Consumer selections | |
| ```python | |
| dataset.alternatives("swe:python__mypy-10308") # task-ranked alternatives | |
| dataset.best_verified("swe:python__mypy-10308") | |
| dataset.by_quality_tier(1, 2, 3) | |
| ``` | |
| For the large persisted library, use `scripts/export_sft_views.py` with | |
| `--selection best`, `successful` or `all`, plus optional benchmark, source, | |
| source-version, model, scaffold, split, quality-tier and quality-rank filters. | |
| Deterministic random, task-level and source-balanced sampling use the same | |
| `CanonicalDatasetAdapter` contract documented in | |
| [dataset_adapter.md](dataset_adapter.md). Expert-only means filtering | |
| `demonstration_provenance` in the ranking index; successful-completion-only | |
| means `outcome_category=success` plus the recorded-agent provenance. | |
| `task_splits.jsonl.gz` assigns one split per `task_key` across every source and | |
| both derived views. | |
| ## Persistent library layout | |
| The default library is manifest-backed: `manifest.json` lists every lossless | |
| pinned canonical shard with its path, SHA-256 and record count. Passing | |
| `--materialize-all` can additionally create `all.jsonl.gz`. To avoid duplicating | |
| very large raw records, outcome and eligibility partitions are compact | |
| trajectory-ID indexes: | |
| - `successful.index.jsonl.gz`, `unsuccessful.index.jsonl.gz`, and | |
| `unknown.index.jsonl.gz`; | |
| - `structurally_eligible.index.jsonl.gz` for records passing the causal | |
| action-observation gate; | |
| - `training_eligible.index.jsonl.gz` for structurally suitable records whose | |
| source is not protected/evaluation-only. | |
| `index.sqlite` joins those concepts without loading canonical JSONL and adds | |
| source, model, scaffold, task, rank, outcome and quality fields. | |
| `rankings.jsonl.gz` and `task_splits.jsonl.gz` are portable derived indexes. | |
| `duplicate_provenance.jsonl.gz` records exact rows collapsed into each retained | |
| canonical interaction. Partition membership never changes or copies canonical | |
| content. | |