텍스트 생성 예시
이 연습 문제에서는 텍스트 생성을 위해 미리 학습된 두 개의 모델을 실험해 보세요.
첫 번째 모델은 TV 쇼 The Big Bang Theory의 캐릭터 Sheldon의 말투를 바탕으로 문장 하나를 생성하고, 두 번째 모델은 Shakespeare의 시를 최대 400자까지 생성해요.
모델은 각각 sheldon_model과 poem_model 변수에 로드되어 있어요. 또한 텍스트 생성을 도와주는 사용자 정의 함수 두 개도 제공됩니다: generate_sheldon_phrase()와 generate_poem(). 두 함수 모두 미리 학습된 모델과 컨텍스트 문자열을 매개변수로 받아요.
이 연습은 강의의 일부입니다
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)
연습 안내
- 미리 정의된 함수
generate_sheldon_phrase()에sheldon_model과sheldon_context를 인자로 넣어 호출하고, 결과를sheldon_phrase변수에 저장하세요. - 생성된 문장을 출력하세요.
- 제공된 텍스트를
poem_context변수에 저장하세요. poem_model과poem_context를 인자로 하여generate_poem()함수를 적용해 생성된 시를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Context for Sheldon phrase
sheldon_context = "I’m not insane, my mother had me tested. "
# Generate one Sheldon phrase
sheldon_phrase = ____(sheldon_model, sheldon_context)
# Print the phrase
print(____)
# Context for poem
____ = "May thy beauty forever remain"
# Print the poem
print(generate_poem(____, poem_context))