본문 바로가기
C.W.K.
Stream
Lesson 03 of 07 · published

다중 입력·다중 출력

~8 min · functional

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

문제 자체가 여러 입구와 출구를 가질 때

실전 데이터는 한 종류로만 이루어지지 않는 경우가 많아. 고객 지원 티켓만 해도 제목, 본문, 태그가 서로 다른 특징 공간에 있고, 모델은 우선순위와 담당 부서를 동시에 예측해야 할 수 있어. 이를 하나의 벡터로 억지로 펼치면 데이터의 구조를 잃고, 모델을 따로 만들면 공유해서 배울 정보를 놓쳐.

표준 구조는 입력마다 경로를 하나씩 두고 알맞은 레이어로 처리한 뒤 layers.concatenate로 합치는 거야. 합쳐진 표현에서는 출력마다 헤드를 하나씩 나눠. 모든 입력과 출력에 name=을 붙이면 위치에 의존하는 목록 대신 딕셔너리로 데이터와 손실 함수를 연결할 수 있어 구조가 커져도 안전해.

다중 과제 학습에는 손실 균형이 필요해

여러 헤드가 공통 몸통을 사용하면 각 출력의 기울기가 같은 특징 표현을 함께 다듬어. 이것이 과제별 모델을 따로 학습할 때보다 일반화가 좋아질 수 있는 이유야. 하지만 손실값의 크기가 서로 다르면 한 헤드가 학습을 독차지할 수도 있어. compileloss_weights로 손실 크기를 조절하는 이유가 여기 있어. 같은 가중치로 시작하고 출력별 손실 곡선을 관찰한 뒤 한 과제가 뒤처질 때만 조정해.

Code

입력 세 개와 출력 헤드 두 개를 가진 지원 티켓 분류기·python
# Multi-input, multi-output ticket classification
title_input = keras.Input(shape=(100,), name="title")
body_input = keras.Input(shape=(500,), name="body")
tags_input = keras.Input(shape=(12,), name="tags")

# Process each branch
title_features = layers.Dense(64, activation="relu")(title_input)
body_features = layers.Dense(128, activation="relu")(body_input)
tags_features = layers.Dense(32, activation="relu")(tags_input)

# Merge branches
x = layers.concatenate([title_features, body_features, tags_features])
x = layers.Dense(128, activation="relu")(x)

# Multiple outputs
priority = layers.Dense(3, activation="softmax", name="priority")(x)
department = layers.Dense(5, activation="softmax", name="department")(x)

model = keras.Model(
    inputs=[title_input, body_input, tags_input],
    outputs=[priority, department],
)

External links

Exercise

(image, age)를 받아 (class_logits, regression_score)를 내는 모델을 만들어. 입력과 출력에 이름을 붙이고 두 손실 함수로 compile한 뒤 합성 데이터로 한 에포크 학습해.

Progress

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

댓글 0

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

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