def rewrite(self, batch): unk = self.vocab.word2id['<unk>'] model = self.model h_ori, h_tsf = self.sess.run( [model.h_ori, model.h_tsf], feed_dict={ model.dropout: 1, model.batch_size: batch['size'], model.enc_inputs: batch['enc_inputs'], model.labels: batch['labels'] }) ori = self.decode(h_ori) ori = [[self.vocab.id2word[i] for i in sent] for sent in ori[0].sent] ori = strip_eos(ori) tsf_beam = self.decode(h_tsf) tsf = [] for idx1, sent in enumerate(tsf_beam[0].sent): t = [] for idx2, i in enumerate(sent): if i == unk: for j in range(self.beam_width): if tsf_beam[j].sent[idx1][idx2] != unk: t.append(self.vocab.id2word[tsf_beam[j].sent[idx1] [idx2]]) break else: t.append(self.vocab.id2word[i]) tsf.append(t) tsf = strip_eos(tsf) return ori, tsf
def rewrite(self, batch): model = self.model h_ori, h_tsf= self.sess.run([model.h_ori, model.h_tsf], feed_dict={model.dropout: 1, model.batch_size: batch['size'], model.enc_inputs: batch['enc_inputs'], model.labels: batch['labels']}) ori = self.decode(h_ori) ori = [[self.vocab.id2word[i] for i in sent] for sent in ori] ori = strip_eos(ori) tsf = self.decode(h_tsf) tsf = [[self.vocab.id2word[i] for i in sent] for sent in tsf] tsf = strip_eos(tsf) return ori, tsf
def rewrite(self, batch): model = self.model logits_ori, logits_tsf = self.sess.run( [model.hard_logits_ori, model.hard_logits_tsf], feed_dict={model.dropout: 1, model.batch_size: batch['size'], model.enc_inputs: batch['enc_inputs'], model.dec_inputs: batch['dec_inputs'], model.labels: batch['labels']}) ori = np.argmax(logits_ori, axis=2).tolist() ori = [[self.vocab.id2word[i] for i in sent] for sent in ori] ori = strip_eos(ori) tsf = np.argmax(logits_tsf, axis=2).tolist() tsf = [[self.vocab.id2word[i] for i in sent] for sent in tsf] tsf = strip_eos(tsf) return ori, tsf