matchzoo.models.bimpm

An implementation of BiMPM Model.

Module Contents

Classes

BiMPM

BiMPM Model.

Functions

mp_matching_func(v1, v2, w)

Basic mp_matching_func.

mp_matching_func_pairwise(v1, v2, w)

Basic mp_matching_func_pairwise.

attention(v1, v2)

Attention.

div_with_small_value(n, d, eps=1e-08)

Small values are replaced by 1e-8 to prevent it from exploding.

class matchzoo.models.bimpm.BiMPM(params: typing.Optional[ParamTable] = None)

Bases: matchzoo.engine.base_model.BaseModel

BiMPM Model.

Reference: - https://github.com/galsang/BIMPM-pytorch/blob/master/model/BIMPM.py

Examples

>>> model = BiMPM()
>>> model.params['num_perspective'] = 4
>>> model.guess_and_fill_missing_params(verbose=0)
>>> model.build()
classmethod get_default_params(cls) → ParamTable
Returns

model default parameters.

build(self)

Make function layers.

forward(self, inputs)

Forward.

reset_parameters(self)

Init Parameters.

dropout(self, v)

Dropout Layer.

matchzoo.models.bimpm.mp_matching_func(v1, v2, w)

Basic mp_matching_func.

Parameters
  • v1 – (batch, seq_len, hidden_size)

  • v2 – (batch, seq_len, hidden_size) or (batch, hidden_size)

  • w – (num_psp, hidden_size)

Returns

(batch, num_psp)

matchzoo.models.bimpm.mp_matching_func_pairwise(v1, v2, w)

Basic mp_matching_func_pairwise.

Parameters
  • v1 – (batch, seq_len1, hidden_size)

  • v2 – (batch, seq_len2, hidden_size)

  • w – (num_psp, hidden_size)

:param num_psp :return: (batch, num_psp, seq_len1, seq_len2)

matchzoo.models.bimpm.attention(v1, v2)

Attention.

Parameters
  • v1 – (batch, seq_len1, hidden_size)

  • v2 – (batch, seq_len2, hidden_size)

Returns

(batch, seq_len1, seq_len2)

matchzoo.models.bimpm.div_with_small_value(n, d, eps=1e-08)

Small values are replaced by 1e-8 to prevent it from exploding.

Parameters
  • n – tensor

  • d – tensor

Returns

n/d: tensor