migrating from keras to pytorch
i'm newly in pytorch
it is the model with bidirectional lstm, is there any body to tel me what is the equivalent of this two different lstm &amp; bi-lstm model?
i try some torch codes but it do not worked.because this code has suitable acc in keras,i want the exact model in torch and i unfortunately can't find it:(
fist_one:
def lstm_model(embedding_size, vocab_size):

    title = layers.Input(shape=(None,), dtype='int32', name='title')
    body = layers.Input(shape=(None,), dtype='int32', name='body')

    embedding = layers.Embedding(
        mask_zero=True,
        input_dim=vocab_size,
        output_dim=embedding_size,
        weights=[w2v_weights],
        trainable=True
    )

    lstm_1 = layers.LSTM(units=80, return_sequences=True)
    lstm_2 = layers.LSTM(units=80, return_sequences=False)
    emb_title = embedding(title)
    print(&quot;question embedding shape&quot;, emb_title.shape)
    sum_a = lstm_2(lstm_1(emb_title))
    print(&quot;q_output shape&quot;, sum_a.shape)

    emb_body = embedding(body)
    print(&quot;answer embedding shape&quot;, emb_body.shape)

    sum_b = lstm_2(lstm_1(emb_body))
    print(&quot;a_output shape&quot;, sum_a.shape)

    sim = layers.dot([sum_a, sum_b], axes=1, normalize=True)
    print(&quot;qa_similarity shape&quot;, sim.shape)

    #     sim = layers.Activation(activation='sigmoid')(sim)
    sim_model = models.Model(
        inputs=[title, body],
        outputs=[sim],
    )
    sim_model.compile(loss='mean_squared_error', optimizer='nadam', metrics=['accuracy'])

    embedding_model = models.Model(
        inputs=[title],
        outputs=[sum_a]
    )
    return sim_model, embedding_model

second one:


def bilstm_model(embedding_size, vocab_size):
    title = layers.Input(shape=(None,), dtype='int32', name='title')
    body = layers.Input(shape=(None,), dtype='int32', name='body')

    embedding = layers.Embedding(
        mask_zero=True,
        input_dim=vocab_size,
        output_dim=embedding_size,
        weights=[w2v_weights],
        trainable=True
    )

    lstm_1 = layers.Bidirectional(LSTM(activation='tanh', dropout=0.2, units=100, return_sequences=True))
    lstm_2 = layers.Bidirectional(LSTM(activation='tanh', dropout=0.2, units=100, return_sequences=False))
    sum_a = lstm_2(lstm_1(embedding(title)))
    sum_b = lstm_2(lstm_1(embedding(body)))

    sim = layers.dot([sum_a, sum_b], axes=1, normalize=True)
    #     sim = layers.Activation(activation='sigmoid')(sim)
    sim_model = models.Model(
        inputs=[title, body],
        outputs=[sim],
    )
    sim_model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])

    embedding_model = models.Model(
        inputs=[title],
        outputs=[sum_a]
    )
    return sim_model, embedding_model

i;m llokingo for true answer in weeks:(

class Model(nn.Module):
    def __init__(self, **kwargs):
        super().__init__()

        self.embeddings = nn.Embedding(num_embeddings=kwargs[&quot;vocab_size&quot;],
                                      embedding_dim=kwargs[&quot;embedding_dim&quot;],
                                      padding_idx=kwargs[&quot;pad_idx&quot;])
        self.embeddings.weight.requires_grad = True  # to not refine-tune

        if kwargs[&quot;model&quot;] == &quot;lstm&quot;:
            self.lstm = nn.LSTM(input_size=kwargs[&quot;embedding_dim&quot;],  # input
                                hidden_size=kwargs[&quot;lstm_units&quot;],  # output
                                num_layers=kwargs[&quot;lstm_layers&quot;],
                                bidirectional=False,
                                batch_first=True)
        if kwargs[&quot;model&quot;] == &quot;BiLSTM&quot;:
            self.lstm = nn.LSTM(input_size=kwargs[&quot;embedding_dim&quot;],  # input
                                hidden_size=kwargs[&quot;bilstm_units&quot;],  # output
                                num_layers=kwargs[&quot;bilstm_layers&quot;],
                                bidirectional=True,
                                batch_first=True)

        self.dropout = nn.Dropout(kwargs[&quot;dropout&quot;])
        self.tanh = F.tanh
        self.dropout = nn.Dropout(kwargs[&quot;dropout&quot;])

    def forward(self):
        pass


class LSTM_Model(Model):
    &quot;&quot;&quot;
    a class to define multiple models
    &quot;&quot;&quot;
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def forward(self, question, answer):
        question_embedding = self.embeddings(question)
        # print(&quot;question embedding shape:&quot;, question_embedding.shape)
        answer_embedding = self.embeddings(answer)
        # print(&quot;answer embedding shape:&quot;, answer_embedding.shape)
        q_output, (qhidden, qcell) = self.lstm(question_embedding)
        print(&quot;q_output shape:&quot;, q_output.shape)
        # print(&quot;qhidden shape:&quot;, qhidden.shape)
        # print(&quot;qcell shape:&quot;, qcell.shape)
        a_output, (ahidden, acell) = self.lstm(answer_embedding)
        print(&quot;a_output shape:&quot;, a_output.shape)
        # print(&quot;ahidden shape:&quot;, ahidden.shape)
        # print(&quot;acell shape:&quot;, acell.shape)
        # qa_similary = torch.mm(qhidden[-1], ahidden[-1])
        # qa_similary =torch.matmul((qhidden[-1]), torc.th(ahidden[-1]))
        q_output = q_output[-1]
        q_output = q_output.squeeze()
        a_output = a_output[-1]
        a_output = a_output.squeeze()
        mm = torch.mul((q_output), (a_output))
        mm -= mm.min(1, keepdim=True)[0]
        mm /= mm.max(1, keepdim=True)[0]
        qa_similary =torch.mean(mm, dim=1)
        # print(&quot;qa_similary shape:&quot;, qa_similary.shape)
        return qa_similary, qhidden

    print(&quot;**************************MODEL DEFINE &amp; CREATED!****************************&quot;)

is this a true and completely exact implemetation of that keras code for two layer lstm?
