matchzoo.models
¶
Submodules¶
Package Contents¶
-
class
matchzoo.models.
DenseBaseline
¶ Bases:
matchzoo.engine.base_model.BaseModel
A simple densely connected baseline model.
Examples
>>> model = DenseBaseline() >>> model.params['mlp_num_layers'] = 2 >>> model.params['mlp_num_units'] = 300 >>> model.params['mlp_num_fan_out'] = 128 >>> model.params['mlp_activation_func'] = 'relu' >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
build
(self)¶ Build.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
DSSM
¶ Bases:
matchzoo.engine.base_model.BaseModel
Deep structured semantic model.
Examples
>>> model = DSSM() >>> model.params['mlp_num_layers'] = 3 >>> model.params['mlp_num_units'] = 300 >>> model.params['mlp_num_fan_out'] = 128 >>> model.params['mlp_activation_func'] = 'relu' >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_preprocessor
(cls)¶ Returns: Default preprocessor.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Build model structure.
DSSM use Siamese arthitecture.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
CDSSM
¶ Bases:
matchzoo.engine.base_model.BaseModel
CDSSM Model implementation.
Learning Semantic Representations Using Convolutional Neural Networks for Web Search. (2014a) A Latent Semantic Model with Convolutional-Pooling Structure for Information Retrieval. (2014b)
Examples
>>> import matchzoo as mz >>> model = CDSSM() >>> model.params['task'] = mz.tasks.Ranking() >>> model.params['vocab_size'] = 4 >>> model.params['filters'] = 32 >>> model.params['kernel_size'] = 3 >>> model.params['conv_activation_func'] = 'relu' >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_preprocessor
(cls)¶ Returns: Default preprocessor.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
_create_base_network
(self)¶ Apply conv and maxpooling operation towards to each letter-ngram.
The input shape is fixed_text_length`*`number of letter-ngram, as described in the paper, n is 3, number of letter-trigram is about 30,000 according to their observation.
Returns: A nn.Module
of CDSSM network, tensor in tensor out.
-
build
(self)¶ Build model structure.
CDSSM use Siamese architecture.
-
forward
(self, inputs)¶ Forward.
-
guess_and_fill_missing_params
(self, verbose:int=1)¶ Guess and fill missing parameters in
params
.Use this method to automatically fill-in hyper parameters. This involves some guessing so the parameter it fills could be wrong. For example, the default task is Ranking, and if we do not set it to Classification manually for data packs prepared for classification, then the shape of the model output and the data will mismatch.
Parameters: verbose – Verbosity.
-
classmethod
-
class
matchzoo.models.
DRMM
¶ Bases:
matchzoo.engine.base_model.BaseModel
DRMM Model.
Examples
>>> model = DRMM() >>> model.params['mlp_num_layers'] = 1 >>> model.params['mlp_num_units'] = 5 >>> model.params['mlp_num_fan_out'] = 1 >>> model.params['mlp_activation_func'] = 'tanh' >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Build model structure.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
DRMMTKS
¶ Bases:
matchzoo.engine.base_model.BaseModel
DRMMTKS Model.
Examples
>>> model = DRMMTKS() >>> model.params['top_k'] = 10 >>> model.params['mlp_num_layers'] = 1 >>> model.params['mlp_num_units'] = 5 >>> model.params['mlp_num_fan_out'] = 1 >>> model.params['mlp_activation_func'] = 'tanh' >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
build
(self)¶ Build model structure.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
ESIM
¶ Bases:
matchzoo.engine.base_model.BaseModel
ESIM Model.
Examples
>>> model = ESIM() >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Instantiating layers.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
KNRM
¶ Bases:
matchzoo.engine.base_model.BaseModel
KNRM Model.
Examples
>>> model = KNRM() >>> model.params['kernel_num'] = 11 >>> model.params['sigma'] = 0.1 >>> model.params['exact_sigma'] = 0.001 >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
build
(self)¶ Build model structure.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
ConvKNRM
¶ Bases:
matchzoo.engine.base_model.BaseModel
ConvKNRM Model.
Examples
>>> model = ConvKNRM() >>> model.params['filters'] = 128 >>> model.params['conv_activation_func'] = 'tanh' >>> model.params['max_ngram'] = 3 >>> model.params['use_crossmatch'] = True >>> model.params['kernel_num'] = 11 >>> model.params['sigma'] = 0.1 >>> model.params['exact_sigma'] = 0.001 >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
build
(self)¶ Build model structure.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
BiMPM
¶ 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)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Make function layers.
-
forward
(self, inputs)¶ Forward.
-
reset_parameters
(self)¶ Init Parameters.
-
dropout
(self, v)¶ Dropout Layer.
-
classmethod
-
class
matchzoo.models.
MatchLSTM
¶ Bases:
matchzoo.engine.base_model.BaseModel
MatchLSTM Model.
https://github.com/shuohangwang/mprc/blob/master/qa/rankerReader.lua.
Examples
>>> model = MatchLSTM() >>> model.params['dropout'] = 0.2 >>> model.params['hidden_size'] = 200 >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Instantiating layers.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
class
matchzoo.models.
ArcI
¶ Bases:
matchzoo.engine.base_model.BaseModel
ArcI Model.
Examples
>>> model = ArcI() >>> model.params['left_filters'] = [32] >>> model.params['right_filters'] = [32] >>> model.params['left_kernel_sizes'] = [3] >>> model.params['right_kernel_sizes'] = [3] >>> model.params['left_pool_sizes'] = [2] >>> model.params['right_pool_sizes'] = [4] >>> model.params['conv_activation_func'] = 'relu' >>> model.params['mlp_num_layers'] = 1 >>> model.params['mlp_num_units'] = 64 >>> model.params['mlp_num_fan_out'] = 32 >>> model.params['mlp_activation_func'] = 'relu' >>> model.params['dropout_rate'] = 0.5 >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Build model structure.
ArcI use Siamese arthitecture.
-
forward
(self, inputs)¶ Forward.
-
classmethod
_make_conv_pool_block
(cls, in_channels:int, out_channels:int, kernel_size:int, activation:nn.Module, pool_size:int)¶ Make conv pool block.
-
classmethod
-
class
matchzoo.models.
ArcII
¶ Bases:
matchzoo.engine.base_model.BaseModel
ArcII Model.
Examples: >>> model = ArcII() >>> model.params[‘embedding_output_dim’] = 300 >>> model.params[‘kernel_1d_count’] = 32 >>> model.params[‘kernel_1d_size’] = 3 >>> model.params[‘kernel_2d_count’] = [16, 32] >>> model.params[‘kernel_2d_size’] = [[3, 3], [3, 3]] >>> model.params[‘pool_2d_size’] = [[2, 2], [2, 2]] >>> model.guess_and_fill_missing_params(verbose=0) >>> model.build()
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
classmethod
get_default_padding_callback
(cls)¶ Returns: Default padding callback.
-
build
(self)¶ Build model structure.
ArcII has the desirable property of letting two sentences meet before their own high-level representations mature.
-
forward
(self, inputs)¶ Forward.
-
classmethod
_make_conv_pool_block
(cls, in_channels:int, out_channels:int, kernel_size:tuple, activation:nn.Module, pool_size:tuple)¶ Make conv pool block.
-
classmethod
-
class
matchzoo.models.
Bert
¶ Bases:
matchzoo.engine.base_model.BaseModel
Bert Model.
-
classmethod
get_default_params
(cls)¶ Returns: model default parameters.
-
build
(self)¶ Build model structure.
-
forward
(self, inputs)¶ Forward.
-
classmethod
-
matchzoo.models.
list_available
() → list¶