Providing Services that take you ahead of your competition.
Work that matters!
Advance Technology Stack just right for your needs!
Serving excellence since 1998.
Subclass Concatenate and override the compute_mask method:
from tensorflow.keras.layers import Concatenate
class MaskedConcatenate(Concatenate):
def compute_mask(self, inputs, mask=None):
if mask is None:
return None
# Assume masks are identical in time dimension
return mask[0] if isinstance(mask, (list, tuple)) else mask
Use MaskedConcatenate() instead of the standard Concatenate.
After concatenating, you can apply a Masking layer or tf.sequence_mask to recreate the mask if needed.
from tensorflow.keras.layers import Masking
# After concatenate
x = Concatenate()([x1, x2])
x = Masking(mask_value=0.0)(x) # Reapply mask
If you’re combining sequences, consider whether Add, Multiply, or attention layers (which support masks) are better suited than raw concatenation.
©2025 Samyak Infotech Pvt Ltd. | All trademarks, images and logos are the property of their respective owners.