相关疑难解决方法(0)

Keras嵌入层中的mask_zero如何工作?

我以为mask_zero=True当输入值为0时将输出0,因此以下各层可能会跳过计算或其他操作。

如何mask_zero运作?

例:

data_in = np.array([
  [1, 2, 0, 0]
])
data_in.shape
>>> (1, 4)

# model
x = Input(shape=(4,))
e = Embedding(5, 5, mask_zero=True)(x)

m = Model(inputs=x, outputs=e)
p = m.predict(data_in)
print(p.shape)
print(p)
Run Code Online (Sandbox Code Playgroud)

实际输出为:(数字是随机的)

(1, 4, 5)
[[[ 0.02499047  0.04617121  0.01586803  0.0338897   0.009652  ]
  [ 0.04782704 -0.04035913 -0.0341589   0.03020919 -0.01157228]
  [ 0.00451764 -0.01433611  0.02606953  0.00328832  0.02650392]
  [ 0.00451764 -0.01433611  0.02606953  0.00328832  0.02650392]]]
Run Code Online (Sandbox Code Playgroud)

但是,我认为输出将是:

[[[ 0.02499047  0.04617121  0.01586803  0.0338897   0.009652  ]
  [ 0.04782704 -0.04035913 -0.0341589   0.03020919 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras word-embedding

12
推荐指数
2
解决办法
3725
查看次数

标签 统计

keras ×1

machine-learning ×1

python ×1

word-embedding ×1