177 lines (176 with data), 7.4 kB
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from docproduct.predictor import GenerateQADoc"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"pretrained_path = 'pubmed_pmc_470k/'\n",
"ffn_weight_file = None\n",
"bert_ffn_weight_file = 'models/bertffn_crossentropy/bertffn'\n",
"embedding_file = 'qa_embeddings/bertffn_crossentropy.pkl'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: Logging before flag parsing goes to stderr.\n",
"W0507 03:56:04.781190 140213234759424 deprecation.py:323] From /root/MedicalQA/gpt_2/gpt2/src/sample.py:55: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use `tf.cast` instead.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"W0507 03:56:04.816710 140213234759424 deprecation.py:323] From /root/MedicalQA/gpt_2/gpt2/src/sample.py:58: multinomial (from tensorflow.python.ops.random_ops) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use `tf.random.categorical` instead.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"W0507 03:56:04.835365 140213234759424 deprecation.py:323] From /root/MedicalQA/gpt_2/gpt2/src/accumulate.py:14: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"W0507 03:56:12.428501 140213234759424 deprecation.py:506] From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/slot_creator.py:187: calling Zeros.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Call initializer instance with the dtype argument instead of passing it to the constructor\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"W0507 03:56:26.003483 140213234759424 deprecation.py:323] From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use standard file APIs to check for files with this prefix.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading checkpoint checkpoint/run1/model-100100\n"
]
}
],
"source": [
"doc = GenerateQADoc(pretrained_path=pretrained_path,\n",
" ffn_weight_file=None,\n",
" bert_ffn_weight_file=bert_ffn_weight_file,\n",
" embedding_file=embedding_file)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" How can I get rid of the excessive dryness? First, I'm going to be frank with you, I don't know where you live. I know there are a few options, among them a humidifier, a bed base soaked in something with DEET, or even just some water. But since all the research I've done has shown dryness, I don't think there's any need to see a doctor. Keep up, \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Stop sleeping, and then wake up and read a good article about sleep hygiene. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Here's a list of products that have been found to help improve the situation: Diamox (Lentyl) `QUEST for more info from \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Gently your eyes closed, then take a deep breath and exhale through your nose. Repeat on a regular basis until you relaxed with a closed eyelid. The dry, watery eye is due to the breakdown of oil in the eyelid, and it will go away within a few days. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" If you take diphenhydramine, you can use it to treat dry eyes. If you don't use it, your eyes will get better. An oral or ophthalmic steroid can help if you get this from sleeping in a dry room. \n"
]
}
],
"source": [
"#@markdown Type in your question (maximum of 512 words)\n",
"inputText = 'My eyes get super dry when I sleep. Any solutions?' #@param {type:\"string\"}\n",
"#@markdown Return top k results\n",
"k = 5 #@param {type:\"number\"}\n",
"#@markdown Perform similarity search by answers or questions? \n",
"search_byI = 'answer' #@param [\"answer\", \"question\"]\n",
"#@markdown Do you want only answers returned? \n",
"answerOnly = False #@param [\"False\", \"True\"] {type:\"raw\"}\n",
"\n",
"for _ in range(5):\n",
" advices = doc.predict( inputText , search_by=search_byI, topk=k, answer_only=answerOnly)\n",
"\n",
" for kj in advices:\n",
" print('')\n",
" print(kj)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:tf]",
"language": "python",
"name": "conda-env-tf-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}