C.W.K.
Stream
Lesson 02 of 04 · published

데이터 준비 & 업로드

~22 min · openai, jsonl, upload, validation

Level 0관찰자
0 XP0/43 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

OpenAI의 데이터 요구사항

OpenAI는 chat-messages 포맷의 JSONL을 요구. 최소 10개 예제(50~100+ 추천), 최대 파일 크기 1GB. 시스템 메시지는 예제 가로질러 일관되거나 완전히 생략.

업로드 전 validator

업로드 전에 파일 검증해. OpenAI API가 잘못된 파일은 거절하지만, 로컬 검증이 더 빠르고 읽기 쉬운 에러 메시지 줘.

Code

Validate locally, then upload·python
from openai import OpenAI
import json

client = OpenAI()

def validate_openai_data(filepath: str) -> int:
    """Returns number of valid examples; raises on hard errors."""
    with open(filepath) as f:
        data = [json.loads(line) for line in f]
    print(f"Number of examples: {len(data)}")
    if len(data) < 10:
        raise ValueError(f"Too few examples: {len(data)} < 10")

    for i, ex in enumerate(data):
        msgs = ex.get("messages", [])
        if not msgs:
            raise ValueError(f"Example {i}: missing 'messages'")
        if msgs[-1]["role"] != "assistant":
            raise ValueError(f"Example {i}: last message must be assistant")
        for j, m in enumerate(msgs):
            if not (m.get("content") or "").strip():
                raise ValueError(f"Example {i} msg {j}: empty content")

    chars = sum(len(json.dumps(ex)) for ex in data)
    tokens = chars // 4
    print(f"Estimated tokens: ~{tokens:,}")
    print(f"Estimated training cost on gpt-4.1-mini @ 3 epochs: "
          f"~${tokens * 3 / 1_000_000 * 0.80:.2f}")
    return len(data)

validate_openai_data("training_data.jsonl")

# Upload after local validation passes
training_file = client.files.create(
    file=open("training_data.jsonl", "rb"),
    purpose="fine-tune",
)
print(f"File ID: {training_file.id}")

# Optional but recommended: validation file for monitoring
validation_file = client.files.create(
    file=open("validation_data.jsonl", "rb"),
    purpose="fine-tune",
)
print(f"Validation File ID: {validation_file.id}")

External links

Exercise

OpenAI chat 포맷으로 50예제 학습 파일 + 10예제 validation 파일 준비. 위 validator 돌려. Files API로 둘 다 업로드. 파일 ID 기록 — 다음 레슨에서 쓸 거야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.