"""An implementation of MVLSTM Model."""
import typing

import keras
import keras.backend as K

from matchzoo import engine


class MVLSTM(engine.BaseModel):
    """
    MVLSTM Model.
    Examples:
        >>> model = matchzoo.models.MVLSTM()
        >>> model.params['mlp_num_layers'] = 2
        >>> model.params['top_k'] = 10
        >>> model.guess_and_fill_missing_params(verbose=0)
        >>> model.build() 
    """

    @classmethod
    def get_default_params(cls) -> engine.ParamTable:
        """:return: model default parameters."""
        params = super().get_default_params(
            with_embedding=True, with_multi_layer_perceptron=True)
        params['optimizer'] = 'adam'
        params.add(engine.Param('vocab_size', 100))
        params.add(engine.Param('hidden_size', 32))
        params.add(engine.Param('padding', 'same'))
        params.add(engine.Param('dropout_rate', 0.0))
        params.add(engine.Param(
            'top_k', value=10,
            hyper_space=engine.hyper_spaces.quniform(low=2, high=100)
        ))
        return params

    def build(self):
        """Build model structure."""

        query, doc = self._make_inputs()

        embedding = self._make_embedding_layer()
        embed_query = embedding(query)
        embed_doc = embedding(doc)
        # Process query & document input.
        bi_lstm = keras.layers.Bidirectional(keras.layers.LSTM(
            self._params['hidden_size'],
            return_sequences=True,dropout=self._params['dropout_rate']))

        rep_query = bi_lstm(embed_query)
        rep_doc = bi_lstm(embed_doc)

        matching_matrix = keras.layers.Dot(
            axes=[1, 1], normalize=False)([rep_query, rep_doc])
        matching_matrix = keras.layers.Reshape((-1, ))(matching_matrix)

        matching_topk = keras.layers.Lambda(
            lambda x: K.tf.nn.top_k(x, k=self._params['top_k'], sorted=True)[0]
        )(matching_matrix)
        mlp = self._make_multi_layer_perceptron_layer()(matching_topk)
        mlp = keras.layers.Dropout(
                    rate=self._params['dropout_rate'])(mlp)

        x_out = self._make_output_layer()(mlp)
        self._backend = keras.Model(inputs=[query, doc], outputs=x_out)

@@ -47,16 +47,31 @@
 t typing
+%0Aimport logging
 %0A%0Aimport
@@ -133,16 +133,54 @@
 engine%0A%0A
+logger = logging.getLogger(__name__)%0A%0A
 %0Aclass M
@@ -230,16 +230,17 @@
  Model.%0A
+%0A
     Exam
@@ -269,24 +269,8 @@
 l = 
-matchzoo.models.
 MVLS
@@ -316,19 +316,17 @@
 layers'%5D
- = 
+=
 2%0A      
@@ -442,17 +442,17 @@
 .build()
- 
+%0A
 %0A    %22%22%22
@@ -1505,16 +1505,17 @@
 es=True,
+ 
 dropout=
@@ -2065,24 +2065,16 @@
 ropout(%0A
-        
         

Make test for mvlstm.