
80
에이전트 시대의 AI 시스템 설계
동물
호랑이
에 대해 영문자
N
으로 시작하는 구문을 작성하라고 요청하면 예를 들어 이런 문구
가 나올 것이다.
Nimbly navigating the
이제 이를 이용해서 시 생성을 초기화한다.
def initialize_poem(animal: str, allowed_start_words: [str]):
# 단어의 가중치는 길이에 반비례한다.
lengths = [1.0*len(w) for w in allowed_start_words]
max_len = np.max(lengths)
weights = (max_len - lengths)
weights = weights / np.sum(weights)
start_word = random.choices(population=allowed_start_words, weights=weights,
k=1)[0].lower()
start_letter = start_word[0].upper()
return start_word, [get_phrase_that_starts_with(animal, start_letter)]
이 메서드는 이합체시를 구성할 단어와 그 단어의 첫 글자로 생성한 첫 행을 돌려준다.
호랑이
의 경우 다음과 같은 결과를 얻을 수 있다.
('wild', ['Wrapped ...