When using masks, for examples with tf.keras.layers.Embedding(..., mask_zero=True)
, a mask is created automatically for each element which equals to 0.
(使用遮罩时,例如使用tf.keras.layers.Embedding(..., mask_zero=True)
,将自动为每个等于0的元素创建一个遮罩。)
Since once we moved through the layer, the mask is already computed, is there any way to access it?
(由于一旦我们移动了图层,就已经计算出了蒙版,是否有任何方法可以访问它?)
(without callingcompute_mask
again) ((无需再次调用compute_mask
))
For example, consider the following code
(例如,考虑以下代码)
inputs = np.random.randint(0,999, (10,10))
inputs[inputs < 100] = 0 # Create some 0 values
embedding_layer = tf.keras.layers.Embedding(1000, 64, input_length=10, mask_zero=True)
result = embedding_layer(inputs) # Mask is already calculated here
### How to access the mask here?
There is a private variable result._keras_mask
, but I assume since it is marked private I better not interact with it.
(有一个私有变量result._keras_mask
,但是我假设由于将其标记为私有,所以最好不要与之交互。)
embedding_layer.compute_mask
(since it was already called) I'm wondering how should I access the mask? (因为我不想调用embedding_layer.compute_mask
(因为它已经被调用),所以我想知道应该如何访问该掩码?)
I know it is passed automatically to sequential layers, but I want to access it anyway
(我知道它会自动传递到顺序图层,但无论如何我都想访问它)
ask by bluesummers translate from so