C.W.K.
Stream
Lesson 05 of 07 · published

Text generation

~8 min · keras-nlp

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

Decoder LLM (Gemma, Llama) 의 native task. model = GemmaCausalLM.from_preset('gemma_2b_en'); output = model.generate('Once upon a time', max_length=100). 한 줄로 텍스트 생성.

sampling 파라미터: temperature (0 = greedy, 1+ = creative), top_k (n 후보만 고려), top_p (cumulative 확률 cutoff). production 에선 보통 temperature=0.7, top_p=0.9. 0 으로 하면 deterministic 하지만 dull.

Code

# Load GPT-2 for text generation
gpt2 = keras_hub.models.GPT2CausalLM.from_preset("gpt2_base_en")

# Generate with various sampling strategies
output = gpt2.generate(
    "The future of AI is",
    max_length=100,
)
print(output)

# Control generation with temperature, top_k, top_p
gpt2.compile(sampler=keras_hub.samplers.TopKSampler(k=50, temperature=0.7))

External links

Exercise

Gemma-2b 로드. 같은 prompt 를 temperature=0, 0.5, 1.0 로 생성. 출력 차이 메모. top_p=0.5 vs 0.95 도 테스트.

Progress

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

댓글 0

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

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