Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)
David Cecchini
Data Scientist
다양한 모델
softmax로 계산됩니다RNN에는 언어 모델이 곳곳에 있습니다!


# 고유 단어 가져오기
unique_words = list(set(text.split(' ')))
# 사전 생성: 단어→키, 인덱스→값
word_to_index = {k:v for (v,k) in enumerate(unique_words)}
# 사전 생성: 인덱스→키, 단어→값
index_to_word = {k:v for (k,v) in enumerate(unique_words)}
# 변수 X와 y 초기화 X = [] y = []# 텍스트를 `step` 간격으로, 길이 `sentence_size`씩 순회 for i in range(0, len(text) - sentence_size, step):X.append(text[i:i + sentence_size]) y.append(text[i + sentence_size])
# 예시(숫자는 어휘의 인덱스):
# 문장: "i loved this movie" -> (["i", "loved", "this"], "movie")
X[0],y[0] = ([10, 444, 11], 17)
# 인덱스 문장 목록 생성 new_text_split = []# 반복하며 사전에서 인덱스 추출 for sentence in new_text:sent_split = []for wd in sentence.split(' '):ix = wd_to_index[wd]sent_split.append(ix)new_text_split.append(sent_split)
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)