| Large language model datasets utilize specific formats depending on the training stage—including single text fields for pre-training next-token prediction, instruction-input-output structures for single-turn fine-tuning, role and content message arrays for multi-turn chat fine-tuning, and prompt-chosen-rejected triplets for Direct Preference Optimization (DPO)—all of which must adhere to strict JSONL dataset creation rules requiring one single-line JSON object per row, properly escaped newlines within text strings, UTF-8 encoding, and a .jsonl file extension. 1. Pre-training / Continual Pre-trainingFor pre-training, the model simply learns to predict the next token from raw text. The standard format uses a single text field. {"text": "Large language models are trained on massive amounts of text data to understand and generate human language."}
{"text": "Python is a high-level, interpreted programming language known for its readability and versatile libraries."}
2. Instruction Fine-Tuning (SFT - Single Turn)Used to train models to follow specific user instructions. This format usually contains instruction, input (optional context), and output. {"instruction": "Translate the following English text to French.", "input": "Hello, how are you today?", "output": "Bonjour, comment allez-vous aujourd'hui ?"}
{"instruction": "Summarize the benefits of drinking water.", "input": "", "output": "Drinking water maintains hydration, improves digestion, supports kidney function, and boosts skin health."}
3. Multi-turn Chat Fine-Tuning (OpenAI / Hugging Face Format)This is the standard format used by OpenAI, Hugging Face trl, and modern open-source fine-tuning frameworks (like LLaMA-Factory). It structures data as a conversation array of messages with role and content. {"messages": [{"role": "system", "content": "You are a helpful and polite customer service assistant."}, {"role": "user", "content": "Where is my order #12345?"}, {"role": "assistant", "content": "Let me check that for you. Your order #12345 is currently in transit and expected to arrive tomorrow."}]}
{"messages": [{"role": "user", "content": "What is the capital of South Korea?"}, {"role": "assistant", "content": "The capital of South Korea is Seoul."}, {"role": "user", "content": "What is its population?"}, {"role": "assistant", "content": "As of recent estimates, the population of Seoul is approximately 9.5 million people."}]}
4. Direct Preference Optimization (DPO / RLHF)Used to align model outputs with human preferences. Each line contains a prompt, a preferred response (chosen), and a dispreferred response (rejected). {"prompt": "Explain quantum computing in one sentence.", "chosen": "Quantum computing is a type of computation that uses quantum mechanics principles, such as superposition and entanglement, to solve complex problems much faster than classical computers.", "rejected": "It is a super fast computer that uses quantum physics to do cool stuff."}
{"prompt": "Write a short Haiku about winter.", "chosen": "Cold wind softly blows,\nSilent snow falls from the sky,\nEarth lies fast asleep.", "rejected": "Winter is very cold and white.\nSnow is everywhere outside.\nI like warm cocoa."}
Key Rules for Creating JSONL Datasets- One JSON per Line: Do not pretty-print (indent) the JSON. The entire object must fit on a single line.
- Handle Newlines in Text: If your text contains line breaks (e.g., code or paragraphs), escape them as
\n inside the string instead of pressing Enter. - Encoding: Always save the file using UTF-8 encoding to support multiple languages and special characters.
- File Extension: Save the file with the
.jsonl or .jsonlines extension. |