창의적 글쓰기의 다양성을 위한 LLM Post-Training 수정 방법
Modifying Large Language Model Post-Training for Diverse Creative Writing
TL;DR Highlight
DPO/ORPO 학습 시 '희귀한 고품질 샘플'에 더 높은 가중치를 줘서, 품질은 GPT-4o급 유지하면서 출력 다양성을 인간 수준으로 끌어올린 기법
Who Should Read
LLM을 창의적 글쓰기, 스토리 생성, 콘텐츠 제작에 파인튜닝하면서 출력이 너무 획일적이라는 문제를 겪고 있는 ML 엔지니어. 특히 DPO/ORPO 기반 학습 파이프라인을 운영 중인 팀.
Core Mechanics
- GPT-4o, Claude-3.5-Sonnet, DeepSeek-R1 같은 최신 instruction-tuned 모델들은 품질은 높지만 출력 다양성이 인간 작성 데이터보다 훨씬 낮다는 걸 정량적으로 확인
- 핵심 아이디어: 같은 프롬프트에 대한 다른 응답들과 얼마나 다른지를 나타내는 'deviation(편차)' 점수를 DPO/ORPO 손실 함수의 가중치로 활용
- 희귀하지만 품질 좋은 응답일수록 학습 시 더 높은 가중치를 받아 모델이 '흔한 패턴'에만 수렴하지 않도록 유도
- Llama-3.1-8B 기반 DDPO-both 모델이 semantic/style 다양성 모두에서 인간 작성 데이터(Gold)와 유사한 수준 달성, 품질은 GPT-4o와 동등
- 프롬프트당 응답 수가 너무 적을 때(4개 이하)는 품질이 떨어지지만, 최소 deviation 임계값 설정이나 고품질 응답만 사용하면 해결 가능
- 기존 다양성 증진 기법인 DivPO보다 다양성은 높고 데이터 효율성도 좋음 (DivPO는 필터링으로 데이터를 낭비하지만 이 방법은 전체 데이터 활용)
Evidence
- 인간 평가에서 DDPO-both vs GPT-4o: 다양성 win rate 100% vs 0% (p < 0.001), 품질 win rate 68% vs 24% (p < 0.001)
- DDPO-both vs DPO: 다양성 win rate 62% vs 26% (p < 0.001), 품질은 통계적 유의미한 차이 없음 (p > 0.1)
- Llama-3.1-8B DDPO-both의 semantic diversity가 인간 작성 Gold 데이터와 거의 동일한 수준에 도달하면서 reddit-reward는 GPT-4o-iter보다 약간 낮은 수준 유지
- 프롬프트당 응답 6개 이상에서는 DDPO-both가 DPO/DivPO 대비 다양성 높고 품질은 동등, 4개 이하에서만 품질 저하 발생
How to Apply
- 기존 DPO 학습 파이프라인에서, 같은 프롬프트에 대한 여러 응답을 임베딩(jinaai/jina-embeddings-v3 등)한 뒤 각 응답의 평균 코사인 거리를 deviation으로 계산해서 loss 가중치로 곱해주면 됨. 코드 변경은 손실 함수 한 줄 수정 수준.
- 창의적 글쓰기 데이터셋을 구축할 때 프롬프트당 최소 6~8개 이상의 응답을 수집하는 게 중요. r/writingPrompts 같은 UGC(사용자 생성 콘텐츠) 플랫폼 데이터가 이 조건에 잘 맞음.
- semantic diversity와 style diversity를 둘 다 잡으려면 DDPO-both처럼 두 임베딩 모델의 deviation을 기하평균으로 결합해서 사용. 어느 한 쪽만 원하면 해당 임베딩 모델만 쓰면 됨.
Code Example
# DDPO 핵심 아이디어: deviation으로 DPO loss에 가중치 부여
import torch
from sentence_transformers import SentenceTransformer
import numpy as np
def compute_deviation(responses: list[str], embedder) -> np.ndarray:
"""
같은 프롬프트에 대한 응답들의 deviation 계산
deviation = 다른 응답들과의 평균 코사인 거리
"""
embeddings = embedder.encode(responses, normalize_embeddings=True)
n = len(embeddings)
deviations = []
for i in range(n):
dists = []
for j in range(n):
if i != j:
cos_dist = 1 - np.dot(embeddings[i], embeddings[j])
dists.append(cos_dist)
deviations.append(np.mean(dists))
deviations = np.array(deviations)
# 정규화: min=0, sum=count
d_min = deviations.min()
d_max = deviations.max()
if d_max > d_min:
deviations = (deviations - d_min) / (d_max - d_min)
else:
deviations = np.full(n, 0.5)
deviations = deviations / deviations.sum() * n
return deviations
def ddpo_loss(policy_logps_w, policy_logps_l, ref_logps_w, ref_logps_l,
deviation_w, beta=0.1):
"""
Diversified DPO loss
deviation_w: winning 응답의 deviation 가중치 (희귀할수록 높음)
"""
log_ratios_w = policy_logps_w - ref_logps_w
log_ratios_l = policy_logps_l - ref_logps_l
logits = beta * (log_ratios_w - log_ratios_l)
# deviation으로 loss에 가중치 부여 (핵심!)
loss = -deviation_w * torch.nn.functional.logsigmoid(logits)
return loss.mean()
# 사용 예시
embedder = SentenceTransformer('jinaai/jina-embeddings-v3', trust_remote_code=True)
responses = ["story A...", "story B...", "story C...", "story D..."]
deviations = compute_deviation(responses, embedder)
print(f"Deviations: {deviations}") # 희귀한 스타일일수록 높은 값Terminology
Related Resources
Original Abstract (Expand)
As creative writing tasks do not have singular correct answers, large language models (LLMs) trained to perform these tasks should be able to generate diverse valid outputs. However, LLM post-training often focuses on improving generation quality but neglects to facilitate output diversity. Hence, in creative writing generation, we investigate post-training approaches to promote both output diversity and quality. Our core idea is to include deviation -- the degree of difference between a training sample and all other samples with the same prompt -- in the training objective to facilitate learning from rare high-quality instances. By adopting our approach to direct preference optimization (DPO) and odds ratio preference optimization (ORPO), we demonstrate that we can promote the output diversity of trained models while minimally decreasing quality. Our best model with 8B parameters could achieve on-par diversity as a human-created dataset while having output quality similar to the best instruction-tuned models we examined, GPT-4o and DeepSeek-R1. We further validate our approaches with a human evaluation, an ablation, and a comparison to an existing diversification approach, DivPO.