def generateQADoc(pretrained_path=FS.PRE_TRAINED.PUB_MED, ffn_weight_file=None, bert_ffn_weight_file=FS.MODELS.BERT_FFN, embedding_file=FS.EMBEDDINGS.BERT_FFN_PKL): doc = GenerateQADoc(pretrained_path=pretrained_path, ffn_weight_file=None, bert_ffn_weight_file=bert_ffn_weight_file, embedding_file=embedding_file) Log.debug( doc.predict('my eyes hurts and i have a headache.', search_by='answer', topk=5, answer_only=False)) Log.debug( doc.predict('my eyes hurts and i have a headache.', search_by='question', topk=5, answer_only=False))
def explain(api: infermedica_api.API): # Prepare diagnosis request it need to have sufficient amount of evidences # The most appropriate way to get a request way for explain method is to # use the one which has been created while interacting with diagnosis. # For the example purpose a new one is created. request = infermedica_api.Diagnosis(sex='female', age=35) request.add_symptom('s_10', 'present') request.add_symptom('s_608', 'present') request.add_symptom('s_1394', 'absent') request.add_symptom('s_216', 'present') request.add_symptom('s_9', 'present') request.add_symptom('s_188', 'present') # call the explain method request = api.explain(request, target_id='c_62') # and see the results Log.pretty(request)
def diagnosis(api: infermedica_api.API): request = infermedica_api.Diagnosis(sex='female', age=35) request.add_symptom('s_21', 'present', initial=True) request.add_symptom('s_98', 'present', initial=True) request.add_symptom('s_107', 'absent') # call diagnosis request = api.diagnosis(request) Log.pretty(request) # ask patient the questions returned by diagnosis and update request with patient answers request.add_symptom('s_99', 'present') request.add_symptom('s_8', 'absent') request.add_symptom('s_25', 'present') # ... and so on until you decided that enough question have been asked # or you have sufficient results in request.conditions # call diagnosis again with updated request request = api.diagnosis(request) # repeat the process Log.pretty(request)
def conditions(api: infermedica_api.API): Log.info('Conditions list:') Log.pretty(api.conditions_list()) Log.info('Conditions details:') Log.pretty(api.condition_details('c_221')) Log.warn('Conditions details (Fail Test)') Log.pretty(api.condition_details('fail'))
}) api = infermedica_api.get_api() # resp = api.parse('I feel stomach pain but no coughing today.') # Log.debug(resp) if __name__ == '__main__': FLAGS = argparse.ArgumentParser( epilog='Infermedica diagnosis API.\n', formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Test infermedica API' ) FLAGS.add_argument('-id', '--id', type=str, default='', help='Your infermedica APP ID.') FLAGS.add_argument('-k', '--key', type=str, default='', help='Your infermedica API Key.') FLAGS.add_argument('-m', '--mode', type=bool, default=True, help='Make requests in development mode (Only during development).') args = FLAGS.parse_args() # Display command-line arguments & their values. Log.info('\n{0}\n{1:^55}\n{0}' .format('-' * 55, 'Command Line Arguments')) for k, v in vars(args).items(): Log.info('{:<20} = {!s:>20}'.format(k, v)) Log.info('\n{}\n'.format('-' * 55)) main()
gpt2_input = self._get_gpt2_inputs(questions[0], topk_question, topk_answer) gpt2_pred = self.estimator.predict( lambda: gpt2_estimator.predict_input_fn(inputs=gpt2_input, batch_size=self.batch_size, checkpoint_path=self. gpt2_weight_file)) raw_output = gpt2_estimator.predictions_parsing( gpt2_pred, self.encoder) # result_list = [re.search('`ANSWER:(.*)`QUESTION:', s) # for s in raw_output] # result_list = [s for s in result_list if s] # try: # r = result_list[0].group(1) # except (AttributeError, IndexError): # r = topk_answer[0] refine1 = re.sub('`QUESTION:.*?`ANSWER:', '', str(raw_output[0]), flags=re.DOTALL) refine2 = refine1.split('`QUESTION: ')[0] return refine2 if __name__ == "__main__": from config.util import Log gen = GenerateQADoc() Log.info(gen.predict('my eyes hurt'))