def predict(self, questions, search_by='answer', topk=5, answer_only=False): embedding = self.qa_embed.predict( questions=questions, dataset=False).eval(session=self.embed_sess) if answer_only: topk_answer = self.faiss_topk.predict(embedding, search_by, topk, answer_only) else: topk_question, topk_answer = self.faiss_topk.predict( embedding, search_by, topk, answer_only) gpt2_input = self._get_gpt2_inputs(questions, topk_question, topk_answer) raw_output = gpt2.generate(self.sess, prefix=gpt2_input, return_as_list=True, include_prefix=False) original_line = '`QUESTION: %s `ANSWER: ' % questions output_list = [] for output_ind, output_chunk in enumerate( raw_output[0].split(original_line)): if output_ind == 0: pass else: output_list.append(output_chunk.split('`QUESTION')[0]) # clipped_output = raw_output[0].split( # '`QUESTION')[1].split('`ANSWER:')[1] return output_list
import tensorflow.compat.v1 as tf from gpt_2 import gpt2 tf.disable_eager_execution() csv_path = 'data/GPT2_data_FFNN.csv' sess = gpt2.start_tf_sess() gpt2.load_gpt2(sess) gpt2.generate( sess, prefix="`QUESTION: What is the best treatment for the flu? `ANSWER:")