Natural Language Processing in TensorFlow week4

han811·2020년 11월 14일
0
post-thumbnail

Sequence models and literature

만약 poetry같은 경우 학습은 어떻게 할 것인가?

코드는 딱히 안봐도 될 것같고 concept만 잡고 가자.
'in the town of athy one jeremy'라는 문장이 있을 때 이를 다음과 같이 데이터 셋을 구성한다.
'in the'
'in the town'
...
'in the town of athy one jeremy'
이렇게 구성하고 마지막 단어들을 label로 준채 앞의 단어들로만 가지고 맞추게 학습시키다.
그래서 loss가 categorical_crossentropy가 되며 output수가 전체 단어 수와 같은 모델을 만든다.

tf.keras.utils.to_categorical(labels, num_classes=total_words)

하나 건진다면 categorical로 쉽게 바꿀 수 있는 util모듈이 있다.

마지막으로 character-based RNN을 보여주는데 이것은 단어가 아닌 각 글자기준으로 토크나이징 및 학습이 진행되는 방법입니다.

tensorflow character-based text generation in RNN official docu
https://www.tensorflow.org/tutorials/text/text_generation

my github repo - https://github.com/han811/tensorflow

profile
han811

0개의 댓글