-
[NLP-tensorflow] Long Short Term Memory for NLP자연어처리 2022. 6. 8. 15:34
https://www.youtube.com/watch?v=A9QVYOBjZdY&list=PLQY2H8rRoyvzDbLUZkbudP-MFQZwNmU4S&index=5
Today has a beautiful blue <..>
같은 문장이 있을 때 괄호 안의 단어를 예측한다고 하자. 우리는 쉽게 괄호 안에 "sky"라는 단어가 올것이라는 것을 알 수 있다.
I lived in Ireland, so at school they made me learn how to speak <..>
위의 문장과 같은 경우에는 어떨까?
정답은 'Gaelic'이다. 정답을 결정하는 키워드는 무엇일까? 바로 Ireland이다.
하지만 Ireland와 Gaelic은 서로 멀리 떨어져있기 때문에 RNN을 사용하는 경우 정답을 얻어내는 것이 어려워질 수 있다.
RNN의 경우 위와 같이 뉴런이 무언가를 학습하고 다음 timestamp로 context을 전달하지만 거리가 멀어지면 context는 진짜 의미와 상당히 멀어질 수 있다.
이럴 때 LSTM architecture를 사용할 수 있다. LSTM은 Cell state라는 것을 사용하는데 이것은 context가 유지될 수 있도록 해준다.
예를 들어, Ireland라는 단어가 Gaelic이라는 언어를 연상시킬 수 있도록 학습한다는 것이다.
또한 양방향이라는 특성이 있어 나중의 단어가 앞선 단어의 context를 제공할 수 있다는 특징도 있다.
model = tf.keras.Sequential([ tf.keras.layers.Embedding(tokenizer.vocab_size, 64), tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64)), tf.keras.layers.Dense(64, activation='relu'), tf.keras.layers.Dense(1, activation='sigmold') ])
'자연어처리' 카테고리의 다른 글
Attention Is All You Need (Transformer) 논문 설명 (0) 2024.03.06 [NLP-tensorflow] Training an AI to create poetry (NLP Zero to Hero - Part 6) (0) 2022.06.08 [NLP-tensorflow] ML with Recurrent Neural Networks (0) 2022.06.08 [NLP-tensorflow] Part 3 Training a model to recognize sentiment in text (0) 2022.06.06 [NLP-tensorflow] Part 2 Turning sentences into data (0) 2022.06.06