mask_zero = True的嵌入层的意外输出

时间:2018-11-23 19:30:05

标签: python tensorflow keras

我已经发布了一个类似的问题,并删除了它,因为它是独立存在的,所以更容易理解。

在嵌入层之后,我希望0输入被映射为0,因为它们被屏蔽了。但是,这与实际情况相去甚远。我将序列填充到100的长度。

我的序列长度是1,所以我又填充了99个值。

# create numerical input
numerical_input = tf.keras.layers.Input(shape=(100, NUMERICAL_INPUT_DIM), name='numerical_input')

# create embeddings
c = tf.keras.layers.Input(shape=(100,), name='categorical_input')
embed = tf.keras.layers.Embedding(20000, 6, mask_zero=True)(c)

# merge numerical and embeddings data
merged = tf.keras.layers.concatenate([numerical_input, embed])

# Create the mask
mask = tf.keras.layers.Masking(mask_value=0)(merged)

lstm_out = tf.keras.layers.LSTM(32, return_sequences=True)(mask)

dense = tf.keras.layers.Dense(1, activation='sigmoid', name='main_output')(lstm_out)

model = tf.keras.models.Model([numerical_input] + [c], dense)

这是我的嵌入层输出。请注意,我希望在第一个列表之后的任何地方都为0。相反,我得到了恒定的值。

[[[-0.4740393  -0.23054121 -0.09492718 ...  0.64286166  0.08887757
    0.7206384 ]
  [ 0.          0.          0.         ...  0.4725582   0.9929707
    0.28641897]
  [ 0.          0.          0.         ...  0.4725582   0.9929707
    0.28641897]
  ...
  [ 0.          0.          0.         ...  0.4725582   0.9929707
    0.28641897]
  [ 0.          0.          0.         ...  0.4725582   0.9929707
    0.28641897]
  [ 0.          0.          0.         ...  0.4725582   0.9929707
    0.28641897]]]

输入的数字部分和嵌入层的值是0,这不是我期望的。

0 个答案:

没有答案
相关问题