def validate(self, dw, dt, qw, qt, c, a, m_dw, m_qw, tt, tm, m_c, cl,
              match_feat, use_char, use_char_q):
     f = prepare_input(dw, qw)
     if self.subsample != -1: m_dw = sub_sample(m_dw, m_c, self.subsample)
     return self.validate_fn(dw, dt, qw, qt, c, a, m_dw.astype('int8'),
                             m_qw.astype('int8'), tt, tm.astype('int8'),
                             m_c.astype('int8'), f, cl, match_feat,
                             use_char, use_char_q)
 def train(self, dw, dt, qw, qt, c, a, m_dw, m_qw, tt, tm, m_c, cl):
     f = prepare_input(dw, qw)
     if self.subsample != -1: m_dw = sub_sample(m_dw, m_c, self.subsample)
     return self.train_fn(dw, dt, qw, qt, c, a, m_dw.astype('int8'),
                          m_qw.astype('int8'), tt, tm.astype('int8'),
                          m_c.astype('int8'), f, cl)
        dv = L.get_output(l_doc, deterministic=True)  # B x N x 2D
        p = T.batched_dot(dv, q)  # B x N
        pm = T.nnet.softmax(p) * self.inps[10]
        pm = pm / pm.sum(axis=1)[:, np.newaxis]
        final_v = T.batched_dot(pm, self.inps[4])

        return final, final_v, l_doc, l_qs, l_docembed.W

    def load_model(self, load_path):
        with open(load_path, 'r') as f:
            data = pickle.load(f)
        L.set_all_param_values([self.doc_net] + self.q_net, data)

    def save_model(self, save_path):
        data = L.get_all_param_values([self.doc_net] + self.q_net)
        with open(save_path, 'w') as f:
            pickle.dump(data, f)


if __name__ == "__main__":
    m_d = np.asarray([[1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1,
                                                 0]]).astype('int32')
    m_c = np.asarray([[1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 1,
                                                 0]]).astype('int32')
    print 'doc mask', m_d
    print 'cand mask', m_c
    print 'new mask (N=1)', sub_sample(m_d, m_c, 1)
    print 'new mask (N=2)', sub_sample(m_d, m_c, 2)
    print 'new mask (N=3)', sub_sample(m_d, m_c, 3)
Beispiel #4
0
 def validate(self, d, q, c, a, m_d, m_q, m_c):
     if self.subsample != -1: m_d = sub_sample(m_d, m_c, self.subsample)
     return self.validate_fn(d, q, c, a, m_d.astype('int8'),
                             m_q.astype('int8'), m_c.astype('int8'))
Beispiel #5
0
 def train(self, d, q, c, a, m_d, m_q, m_c):
     if self.subsample != -1: m_d = sub_sample(m_d, m_c, self.subsample)
     return self.train_fn(d, q, c, a, m_d.astype('int8'),
                          m_q.astype('int8'), m_c.astype('int8'))