matchzoo.layers package

Submodules

matchzoo.layers.dynamic_pooling_layer module

An implementation of Dynamic Pooling Layer.

class matchzoo.layers.dynamic_pooling_layer.DynamicPoolingLayer(psize1, psize2, **kwargs)

Bases: keras.engine.base_layer.Layer

Layer that computes dynamic pooling of one tensor.

Parameters:
  • psize1 (int) – pooling size of dimension 1
  • psize2 (int) – pooling size of dimension 2
  • kwargs – Standard layer keyword arguments.

Examples

>>> import matchzoo as mz
>>> layer = mz.layers.DynamicPoolingLayer(3, 2)
>>> num_batch, left_len, right_len, num_dim = 5, 3, 2, 10
>>> layer.build([[num_batch, left_len, right_len, num_dim],
...              [num_batch, left_len, right_len, 3]])
build(input_shape)

Build the layer.

Parameters:input_shape (List[int]) – the shapes of the input tensors, for DynamicPoolingLayer we need tow input tensors.
call(inputs, **kwargs)

The computation logic of DynamicPoolingLayer.

Parameters:inputs (list) – two input tensors.
Return type:Any
compute_output_shape(input_shape)

Calculate the layer output shape.

Parameters:input_shape (list) – the shapes of the input tensors, for DynamicPoolingLayer we need tow input tensors.
Return type:tuple
get_config()

Get the config dict of DynamicPoolingLayer.

Return type:dict

matchzoo.layers.matching_layer module

An implementation of Matching Layer.

class matchzoo.layers.matching_layer.MatchingLayer(normalize=False, matching_type='dot', **kwargs)

Bases: keras.engine.base_layer.Layer

Layer that computes a matching matrix between samples in two tensors.

Parameters:
  • normalize (bool) – Whether to L2-normalize samples along the dot product axis before taking the dot product. If set to True, then the output of the dot product is the cosine proximity between the two samples.
  • matching_type (str) – the similarity function for matching
  • kwargs – Standard layer keyword arguments.

Examples

>>> import matchzoo as mz
>>> layer = mz.layers.MatchingLayer(matching_type='dot',
...                                 normalize=True)
>>> num_batch, left_len, right_len, num_dim = 5, 3, 2, 10
>>> layer.build([[num_batch, left_len, num_dim],
...              [num_batch, right_len, num_dim]])
build(input_shape)

Build the layer.

Parameters:input_shape (list) – the shapes of the input tensors, for MatchingLayer we need tow input tensors.
call(inputs, **kwargs)

The computation logic of MatchingLayer.

Parameters:inputs (list) – two input tensors.
Return type:Any
compute_output_shape(input_shape)

Calculate the layer output shape.

Parameters:input_shape (list) – the shapes of the input tensors, for MatchingLayer we need tow input tensors.
Return type:tuple
get_config()

Get the config dict of MatchingLayer.

Return type:dict

Module contents