Embedding이란?
임베딩은 dense vector 표현을 사용하여 단어와 문서를 나타내는 접근 방식이다.
Embedding Layers
keras.layers.Embedding(input_dim, output_dim, embeddings_initializer='uniform', embeddings_regularizer=None, activity_regularizer=None, embeddings_constraint=None, mask_zero=False, input_length=None)
양수들을 고정된 사이즈의 밀도 벡터로 바꾼다.
ex) [[4],[20]] --> [[0.25, 0.1],[0.6, -0.2]]
임베딩 레이어는 임의 가중치로 초기화되며 training dataset의 모든 단어에 대한 임베딩을 학습할 수 있다.
또한 이 레이어는 모델에서 첫번째 레이어로서 오직 사용될 수 있다.
Example
model = Sequential()
model.add(Embedding(1000, 64, input_length=10))
# the model will take as input an integer matrix of size (batch, input_length).
# the largest integer (i.e. word index) in the input should be
# no larger than 999 (vocabulary size).
# now model.output_shape == (None, 10, 64), where None is the batch dimension.
input_array = np.random.randint(1000, size=(32, 10))
model.compile('rmsprop', 'mse')
output_array = model.predict(input_array)
assert output_array.shape == (32, 10, 64)
Arguments
- input_dim = int> 0.
- output_dim = int >= 0.
- embeddings_initializer = embedding matrix의 초기값
- embeddings_regularizer = embedding matrix에 적용되는 regularizer 함수
- activity_regularizer = 레이어의 아웃풋에 적요되는 regularizer 함수
- embeddings_constraint = embeddings matrix에 적용되는 constraint 함수
- mask_zero = 입력값 0이 마스킹되어야 하는 특수한 padding 값인지의 여부
- mask_zero: 입력값 0이 마스킹되어야 하는 특수한 '패딩'값인지에 대한 여부
가변 길이 입력이 필요할 수 있는 반복 레이어를 사용할 때 유용하다.
- input_length: 입력 시퀀스의 길이가 일정할 때이다. 이 인수는 Flatten 및 Dense 레이어를 업스트림에 연결할 때 필요하다. (이게 없다면 dense 출력의 shape을 알 수 없다.)
Input shape
2D tensor with shape
2D tensor with shape: (batch_size, sequence_length).
Output shape
3D tensor with shape: (batch_size, sequence_length, output_dim).
reference
'Computer Vision > Segmentation' 카테고리의 다른 글
RLE (Run-Length-Encoding), Mask R-CNN (0) | 2020.04.17 |
---|
댓글