본문 바로가기
C.W.K.
Stream
Lesson 02 of 08 · published

Dataset vs DatasetDict, Features, 스키마

~24 min · datasets, schema

Level 0스카우트
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

클래스는 둘이지만 보는 방식은 하나야

Dataset는 이름 있는 열과 행으로 이루어진 단일 Arrow 테이블이야. DatasetDict{split_name: Dataset} 구조에 모든 split을 한꺼번에 다루는 편의 기능을 더한 객체고. 그래서 map, filter, select, shuffle을 DatasetDict에 호출하면 각 split에 같은 변환이 적용돼.

features를 데이터베이스 스키마처럼 읽어

ds.features에는 각 열의 Value, ClassLabel, Sequence, Audio, Image 또는 중첩 형식이 기록돼. ClassLabel은 정수와 이름의 대응도 보존하므로 int2str()로 실제 의미를 복원할 수 있어. 열 이름만 보고 짐작하지 말고, 타입과 의미의 기준은 features에서 확인해.

Code

스키마 inspect·python
from datasets import load_dataset

ds = load_dataset("stanfordnlp/imdb")
print(ds["train"].features)
# {'text': Value(dtype='string'), 'label': ClassLabel(names=['neg', 'pos'])}

# label int → name 변환
print(ds["train"].features["label"].int2str(1))  # 'pos'

# Slice 접근
sample = ds["train"][:3]  # dict of column → list
print(sample["label"])
DatasetDict 에서 op 가 broadcast·python
from datasets import load_dataset

ds = load_dataset("stanfordnlp/imdb")  # DatasetDict
small = ds.shuffle(seed=42).select(range(1000))  # NOTE: select 은 split 별, shuffle 은 DatasetDict 에서 동작
# ds.map / .filter / .remove_columns 모두 비슷하게 broadcast
small_filtered = ds.filter(lambda ex: len(ex["text"]) > 200)
print({k: len(v) for k, v in small_filtered.items()})

External links

Exercise

Hub 의 분류 데이터셋 아무거나 로드. features, split 별 num_rows, label 분포 출력. train_test_split(stratify_by_column='label') 로 stratified 80/20 train/dev split 만들고 클래스 균형 보존 검증.

Progress

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

댓글 0

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

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