Created
September 9, 2021 10:17
-
-
Save cjnghn/b607ae6cc1c843fca3f7bed36283009d to your computer and use it in GitHub Desktop.
keras - 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Embedding() | |
Embedding()은 단어를 밀집 벡터(dense vector)로 만드는 역할을 합니다. | |
인공 신경망 용어로는 임베딩 층(embedding layer)을 만드는 역할을 합니다. | |
Embedding()은 정수 인코딩이 된 단어들을 입력을 받아서 임베딩을 수행합니다. | |
Embedding()은 (number of samples, input_length)인 2D 정수 텐서를 입력받습니다. | |
이 때 각 sample은 정수 인코딩이 된 결과로, 정수의 시퀀스입니다. | |
Embedding()은 워드 임베딩 작업을 수행하고 | |
(number of samples, input_length, embedding word dimensionality)인 3D 텐서를 리턴합니다. | |
pseudo | |
------ | |
# 문장 토큰화와 단어 토큰화 | |
text=[['Hope', 'to', 'see', 'you', 'soon'],['Nice', 'to', 'see', 'you', 'again']] | |
# 각 단어에 대한 정수 인코딩 | |
text=[[0, 1, 2, 3, 4],[5, 1, 2, 3, 6]] | |
# 위 데이터가 아래의 임베딩 층의 입력이 된다. | |
Embedding(7, 2, input_length=5) | |
# 7은 단어의 개수. 즉, 단어 집합(vocabulary)의 크기이다. | |
# 2는 임베딩한 후의 벡터의 크기이다. | |
# 5는 각 입력 시퀀스의 길이. 즉, input_length이다. | |
# 각 정수는 아래의 테이블의 인덱스로 사용되며 Embeddig()은 각 단어에 대해 임베딩 벡터를 리턴한다. | |
+------------+------------+ | |
| index | embedding | | |
+------------+------------+ | |
| 0 | [1.2, 3.1] | | |
| 1 | [0.1, 4.2] | | |
| 2 | [1.0, 3.1] | | |
| 3 | [0.3, 2.1] | | |
| 4 | [2.2, 1.4] | | |
| 5 | [0.7, 1.7] | | |
| 6 | [4.1, 2.0] | | |
+------------+------------+ | |
# 위의 표는 임베딩 벡터가 된 결과를 예로서 정리한 것이고 Embedding()의 출력인 3D 텐서를 보여주는 것이 아님. | |
Embedding()에 넣어야하는 대표적인 인자는 다음과 같습니다. | |
첫번째 인자 = 단어 집합의 크기. 즉, 총 단어의 개수 | |
두번째 인자 = 임베딩 벡터의 출력 차원. 결과로서 나오는 임베딩 벡터의 크기 | |
input_length = 입력 시퀀스의 길이 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment