(self, sentences, sentence_length,
                          input_conversation_length, input_sentences, target_sentences)
Generate output of decoder (single batch)
Generate output of decoder (single batch)
Generate output of decoder ( single batch )
def generate_sentence(self, sentences, sentence_length,
                          input_conversation_length, input_sentences, target_sentences):
        """Generate output of decoder (single batch)"""
        self.model.eval()

        # [batch_size, max_seq_len, vocab_size]
        generated_sentences, _, _, _ = self.model(
            sentences,
            sentence_length,
            input_conversation_length,
            target_sentences,
            decode=True)

        # write output to file
        with open(os.path.join(self.config.save_path, 'samples.txt'), 'a') as f:
            f.write(f'<Epoch {self.epoch_i}>\n\n')

            tqdm.write('\n<Samples>')
            for input_sent, target_sent, output_sent in zip(input_sentences, target_sentences, generated_sentences):
                input_sent = self.vocab.decode(input_sent)
                target_sent = self.vocab.decode(target_sent)
                output_sent = '\n'.join([self.vocab.decode(sent) for sent in output_sent])
                s = '\n'.join(['Input sentence: ' + input_sent,
                               'Ground truth: ' + target_sent,
                               'Generated response: ' + output_sent + '\n'])
                f.write(s + '\n')
                print(s)
            print('')
def generate_sentence ( self , sentences , sentence_length , input_conversation_length , input_sentences , target_sentences ) : self . model . eval ( ) # [batch_size, max_seq_len, vocab_size] generated_sentences , _ , _ , _ = self . model ( sentences , sentence_length , input_conversation_length , target_sentences , decode = True ) # write output to file with open ( os . path . join ( self . config . save_path , 'samples.txt' ) , 'a' ) as f : f . write ( f'<Epoch {self.epoch_i}>\n\n' ) tqdm . write ( '\n<Samples>' ) for input_sent , target_sent , output_sent in zip ( input_sentences , target_sentences , generated_sentences ) : input_sent = self . vocab . decode ( input_sent ) target_sent = self . vocab . decode ( target_sent ) output_sent = '\n' . join ( [ self . vocab . decode ( sent ) for sent in output_sent ] ) s = '\n' . join ( [ 'Input sentence: ' + input_sent , 'Ground truth: ' + target_sent , 'Generated response: ' + output_sent + '\n' ] ) f . write ( s + '\n' ) print ( s ) print ( '' )