code: def keras_knrm(
      text1_length,
      text2_length,
      vocab_size,
      embed_size,
      kernel_num=21,
      sigma=0.1,
      exact_sigma=0.001,
  ):
      def kernel_layer(mu, sigma):
          def kernel(x):
              return K.tf.exp(
                  -0.5 * (x - mu) * (x - mu) / sigma / sigma
              )
  
          return Activation(kernel)
  
      query = Input(name="query", shape=(text1_length,))
      doc = Input(name="doc", shape=(text2_length,))
      embedding = Embedding(vocab_size, embed_size, name="embedding")
      q_embed = embedding(query)
      d_embed = embedding(doc)
      mm = merge([q_embed, d_embed], mode="dot", dot_axes=[2, 2])
  
      KM = []
      for i in range(kernel_num):
          mu = (
              1.0 / (kernel_num - 1)
              + (2.0 * i) / (kernel_num - 1)
              - 1.0
          )
          sigma = sigma
          if mu > 1.0:
              sigma = exact_sigma
              mu = 1.0
          mm_exp = kernel_layer(mu, sigma)(mm)
          mm_doc_sum = Lambda(lambda x: K.tf.reduce_sum(x, 2))(mm_exp)
          mm_log = Activation(K.tf.log1p)(mm_doc_sum)
          mm_sum = Lambda(lambda x: K.tf.reduce_sum(x, 1))(mm_log)
          KM.append(mm_sum)
  
      Phi = Lambda(lambda x: K.tf.stack(x, 1))(KM)
      out_ = Dense(
          1, init="uniform", activation="sigmoid", name="dense"
      )(Phi)
  
      model = Model([query, doc], out_)
      return model
  
file_path: analytics-zoo/pyzoo/test/zoo/models/textmatching/test_knrm.py
imports: import os
  import pytest
  from keras.layers import *
  from keras.models import Model
  from zoo.models.textmatching import KNRM
  from test.zoo.pipeline.utils.test_utils import ZooTestCase
label_desc: Use image node_id 1 for calling the TestKNRM obj's underlying member method code with example usage: obj.keras_knrm(text1_length, text2_length, vocab_size, embed_size, kernel_num, sigma, exact_sigma) and returns: model, Activation, K