Ludwig로 첫 모델 학습하기 — YAML 설정 하나로
Ludwig로 첫 모델 학습하기 — YAML 설정 하나로
Ludwig에서 모델을 학습하려면 먼저 **Ludwig 설정(config)**을 만들어요. 설정은 입력 피처(input features), 출력 피처(output features), 전처리, 모델 아키텍처, 학습 루프, 하이퍼파라미터 탐색, 백엔드 인프라까지 — 모델을 만들고 평가하는 데 필요한 모든 것을 지정해요. 최소한 입력·출력 피처만 지정하면 나머지는 Ludwig가 합리적인 기본값으로 채워줘요.
기본 설정
minimal config로 시작해볼게요. 입력과 출력 피처만 지정하고 나머지는 기본값에 맡겨요.
# rotten_tomatoes.yaml
input_features:
- name: genres
type: set
preprocessing:
tokenizer: comma
- name: content_rating
type: category
- name: top_critic
type: binary
- name: runtime
type: number
- name: review_content
type: text
encoder:
type: embed
output_features:
- name: recommended
type: binary
학습 실행
준비된 CSV 데이터셋과 함께 ludwig train을 실행해요.
ludwig train --config rotten_tomatoes.yaml --dataset rotten_tomatoes.csv
Python API로도 같은 작업을 할 수 있어요.
from ludwig.api import LudwigModel
import pandas
df = pandas.read_csv('rotten_tomatoes.csv')
model = LudwigModel(config='rotten_tomatoes.yaml')
results = model.train(dataset=df)
인코더 바꾸기
텍스트 인코더를 바꾸는 건 설정의 encoder만 바꾸면 돼요. embed(단어 임베딩 합산) 대신 사전학습된 BERT 계열 모델을 쓰려면 bert 인코더를 지정해요.
input_features:
- name: review_content
type: text
encoder:
type: bert
pretrained_model_name_or_path: answerdotai/ModernBERT-base
CNN·RNN·Transformer·사전학습 모델(HuggingFace) 등 다양한 텍스트 인코더를 설정만으로 골라 쓸 수 있어요.
더 알아보기
학습 파라미터·전처리 옵션의 전체 목록은 Configuration 문서에서 확인할 수 있어요.