# Datasets

Source: https://docs.surogate.ai/engine/guides/datasets/

You point Surogate at your data under `datasets` (and optionally `validation_datasets`) and tell it which format each dataset is in. Surogate then applies the chat template, tokenizes and masks the data for you.

Dataset `type` can be:
- `text` (pretraining / raw text)
- `instruction` (instruction/output)
- `conversation` (chat messages)
- `preference` (`{prompt, chosen, rejected}` pairs for offline DPO)
- `auto` (auto-detect)

Every type loads through the same pipeline: `path` may be a local JSONL/JSON/parquet/CSV
file, a dataset directory, or a HuggingFace hub repo, and `subset`/`split`/`samples`
work the same way for all of them. If your column names differ from the defaults, map them
with the per-type field options (e.g. `text_field`, `messages_field`, `chosen_field`).

The examples below show one row of each format and the matching config. The full list of
options for each type is in the [config reference](/engine/reference/config/#dataset-configuration-options).

## Text

For pretraining or continued pretraining on raw text. Each row has one text column, `text` by default (`text_field`).

```json
{"text": "The mitochondria is the powerhouse of the cell. ..."}
```

```yaml
datasets:
  - path: "HuggingFaceFW/fineweb-edu"
    type: text
    text_field: text
    split: train
    samples: 100000
```

## Instruction

For instruction-following data. `instruction_field` and `output_field` are required; `input_field` adds optional extra context. You can add a system prompt from a column (`system_prompt_type: field`) or the same one for every row (`system_prompt_type: fixed`).

```json
{"instruction": "Translate to French.", "input": "Good morning", "output": "Bonjour"}
```

```yaml
datasets:
  - path: "yahma/alpaca-cleaned"
    type: instruction
    instruction_field: instruction
    input_field: input
    output_field: output
    system_prompt_type: fixed
    system_prompt: "You are a helpful AI assistant."
```

## Conversation

For multi-turn chat data. Each row has a list of messages, in the `messages` column by default (`messages_field`). `system_field` and `tools_field` point at optional system-prompt and tool-definition columns, and `message_property_mappings` handles messages that don't use `role`/`content`.

```json
{"messages": [{"role": "user", "content": "Hi!"}, {"role": "assistant", "content": "Hello! How can I help?"}]}
```

```yaml
datasets:
  - path: "HuggingFaceH4/ultrachat_200k"
    type: conversation
    messages_field: messages
    split: train_sft
```

## Preference

For offline DPO with [`surogate dpo`](/engine/reference/cli/#dpo). Each row has a `prompt` (a string or a chat messages list) and two competing responses, `chosen` and `rejected`. The loss applies only to the response tokens.

```json
{"prompt": "...", "chosen": "preferred response", "rejected": "dispreferred response"}
```

```yaml
datasets:
  - path: ./pairs.jsonl
    type: preference
```

## Auto

With `type: auto`, Surogate looks at the columns: a `conversation`, `conversations` or `messages` column is read as chat data, `instruction` plus `input` columns as instruction data, and anything else as a plain response dataset. Set the type explicitly when you know it.

```yaml
datasets:
  - path: ./data.jsonl
    type: auto
```

## See also

- [Config reference: datasets](/engine/reference/config/): every dataset option, plus packing and validation splits
- [Quickstart: SFT](/engine/getting-started/quickstart-sft/): your first fine-tuning run, from a ready-made config
- [Quickstart: DPO](/engine/getting-started/quickstart-dpo/): train on preference pairs
- [Back to docs index](/engine/)
