1055 lines (1055 with data), 67.1 kB
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "FaissEvalTopKColab.ipynb",
"version": "0.3.2",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "TPU"
},
"cells": [
{
"metadata": {
"id": "JcrrSVNi8S5-",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"#May have a memory crash in CPU or GPU mode. If so, run in TPU mode. \n",
"\n",
"#The way I set it up was mounting it from my drive. If you wish to do the same you'll need the FFNNEmbed CSV files found here\n",
"# https://drive.google.com/open?id=1ee6I9OHrCiN-wv5BtZX75nyOiWuWTnfs\n",
"# and put them in your drive in a folder named 'FFNNEmbeds'\n",
"\n",
"#run all cells. And then go to the one at the bottom to play around with different questions and answers using the `topKTesting` function "
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "odozicZsVrMZ",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 121
},
"outputId": "35ce1e67-6280-4b57-d275-b10d9edb0cd0"
},
"cell_type": "code",
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import os\n",
"from google.colab import drive\n",
"drive.mount('/content/gdrive')\n",
"files = os.listdir(\"/content/gdrive/My Drive/FFNNEmbeds\")"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
"\n",
"Enter your authorization code:\n",
"··········\n",
"Mounted at /content/gdrive\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "ftB3GRCJo_dh",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 101
},
"outputId": "a513cf3e-9de4-471b-d7d6-ce58ada6f773"
},
"cell_type": "code",
"source": [
"files"
],
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['iClinicFFNNEmbeddings.csv',\n",
" 'webMDFFNNEmbeddings.csv',\n",
" 'askDocsFFNNEmbeddings.csv',\n",
" 'healthTapFFNNEmbeddings.csv',\n",
" 'eHealthForums.csv']"
]
},
"metadata": {
"tags": []
},
"execution_count": 2
}
]
},
{
"metadata": {
"id": "JW0C5N-UWtwT",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"def fix_array(x):\n",
" x = np.fromstring(\n",
" x.replace('\\n','')\n",
" .replace('[','')\n",
" .replace(']','')\n",
" .replace(' ',' '), sep=' ')\n",
" return x.reshape((1, 768))"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "niyPY7RMz40j",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "2d1dc314-4b9f-4926-9e26-1f42dcda7ad5"
},
"cell_type": "code",
"source": [
"pd.options.display.max_rows = 700\n",
"pd.set_option('expand_frame_repr', True)\n",
"pd.set_option('max_colwidth', 250)\n",
"pd.get_option(\"display.max_rows\")"
],
"execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"700"
]
},
"metadata": {
"tags": []
},
"execution_count": 23
}
]
},
{
"metadata": {
"id": "WqlnLnWnWvqi",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 84
},
"outputId": "ad4cca4f-d312-470c-8940-122e56f21833"
},
"cell_type": "code",
"source": [
"qa = pd.read_csv(\"/content/gdrive/My Drive/FFNNEmbeds/\" + files[0])\n",
"for file in files[1:]:\n",
" print(file)\n",
" qa = pd.concat([qa, pd.read_csv(\"/content/gdrive/My Drive/FFNNEmbeds/\" + file)], axis = 0)"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"webMDFFNNEmbeddings.csv\n",
"askDocsFFNNEmbeddings.csv\n",
"healthTapFFNNEmbeddings.csv\n",
"eHealthForums.csv\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "y_poyGE4Wy2C",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 296
},
"outputId": "50d3cecd-ee96-4078-a7f9-c4ab41619da8"
},
"cell_type": "code",
"source": [
"qa.head()"
],
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>question</th>\n",
" <th>answer</th>\n",
" <th>Q_FFNN_embeds</th>\n",
" <th>A_FFNN_embeds</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>is it fine to exercise with knee pain?</td>\n",
" <td>from your description it appears that you may ...</td>\n",
" <td>[[-2.36410219e-02 1.28144488e-01 3.01777810e...</td>\n",
" <td>[[-1.15900427e-01 1.82273567e-01 -9.92501155e...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>suffering from anxiety restlessness and taking...</td>\n",
" <td>depression anxiety restlessness and panic atta...</td>\n",
" <td>[[-1.14040159e-01 1.40852138e-01 9.99100953e...</td>\n",
" <td>[[-1.55445561e-01 9.41457227e-02 4.11367081e...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>can a thyroid patient eat soybean and fenugreek?</td>\n",
" <td>patients with hypothyroidism usually gain weig...</td>\n",
" <td>[[-9.45982337e-02 4.44081500e-02 -2.19836012e...</td>\n",
" <td>[[-2.67755091e-01 4.96627122e-01 -1.05934270e...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>i am not getting my periods after taking fenug...</td>\n",
" <td>fenugreek seed cannot affect your fertility do...</td>\n",
" <td>[[-7.72762671e-02 -5.46492599e-02 -2.90007412e...</td>\n",
" <td>[[-1.16682649e-01 2.29011983e-01 7.17253983e...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>kindly suggest me a therapy to overcome heat a...</td>\n",
" <td>your problem is a characteristic of cholinergi...</td>\n",
" <td>[[ 1.90717205e-01 -1.09118752e-01 2.25994617e...</td>\n",
" <td>[[-4.69765291e-02 1.59166887e-01 -2.05679953e...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 question \\\n",
"0 0 is it fine to exercise with knee pain? \n",
"1 1 suffering from anxiety restlessness and taking... \n",
"2 2 can a thyroid patient eat soybean and fenugreek? \n",
"3 3 i am not getting my periods after taking fenug... \n",
"4 4 kindly suggest me a therapy to overcome heat a... \n",
"\n",
" answer \\\n",
"0 from your description it appears that you may ... \n",
"1 depression anxiety restlessness and panic atta... \n",
"2 patients with hypothyroidism usually gain weig... \n",
"3 fenugreek seed cannot affect your fertility do... \n",
"4 your problem is a characteristic of cholinergi... \n",
"\n",
" Q_FFNN_embeds \\\n",
"0 [[-2.36410219e-02 1.28144488e-01 3.01777810e... \n",
"1 [[-1.14040159e-01 1.40852138e-01 9.99100953e... \n",
"2 [[-9.45982337e-02 4.44081500e-02 -2.19836012e... \n",
"3 [[-7.72762671e-02 -5.46492599e-02 -2.90007412e... \n",
"4 [[ 1.90717205e-01 -1.09118752e-01 2.25994617e... \n",
"\n",
" A_FFNN_embeds \n",
"0 [[-1.15900427e-01 1.82273567e-01 -9.92501155e... \n",
"1 [[-1.55445561e-01 9.41457227e-02 4.11367081e... \n",
"2 [[-2.67755091e-01 4.96627122e-01 -1.05934270e... \n",
"3 [[-1.16682649e-01 2.29011983e-01 7.17253983e... \n",
"4 [[-4.69765291e-02 1.59166887e-01 -2.05679953e... "
]
},
"metadata": {
"tags": []
},
"execution_count": 5
}
]
},
{
"metadata": {
"id": "wGh5zlJs1eOE",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"del qa['Unnamed: 0']"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "hsJKRYwCWyzS",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"qa[\"Q_FFNN_embeds\"] = qa[\"Q_FFNN_embeds\"].apply(fix_array)\n",
"qa[\"A_FFNN_embeds\"] = qa[\"A_FFNN_embeds\"].apply(fix_array)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "JoSZ5ImRW1-T",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"# qa = qa.sample(frac = 1)\n",
"# qa.reset_index(inplace = True, drop = True)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "DteXdlBh2jBl",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"qa = qa.reset_index(drop=True)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "erQwDeii1Jns",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 615
},
"outputId": "854ff994-6030-4901-cf2c-f84623b861a9"
},
"cell_type": "code",
"source": [
"qa.head()"
],
"execution_count": 31,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>question</th>\n",
" <th>answer</th>\n",
" <th>Q_FFNN_embeds</th>\n",
" <th>A_FFNN_embeds</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>is it fine to exercise with knee pain?</td>\n",
" <td>from your description it appears that you may have anterior knee pain which sometimes presents as pain at the back of the knee. the second possibility is that you have over done your exercise and hamstrings are sore and the lower end of the knee ...</td>\n",
" <td>[[-0.0236410219, 0.128144488, 0.30177781, 0.430800796, 0.0534969121, 1.24597561, 0.908191383, -0.0682020858, 1.49799263, 0.0182549823, 0.159414783, -0.000211991704, 0.000532273552, -0.0226245634, -0.0949951187, -0.0198594704, 1.25414896, 0.360615...</td>\n",
" <td>[[-0.115900427, 0.182273567, -0.0992501155, -0.0385564938, 0.740532875, 0.167836308, 0.0228974223, -0.23636511, -0.172942773, 0.25693363, -0.24061957, -0.0263501219, 0.0366276056, -0.126324296, -0.00830298476, 0.158679247, 0.0368386209, -0.393908...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>suffering from anxiety restlessness and taking clonazepam & mirtazapine. i had depression & panic attacks for the last 7 years. need a second opinion.</td>\n",
" <td>depression anxiety restlessness and panic attacks are best respond to a combination of a selective serotonin reuptake inhibitors (ssris) and benzodiazepines. mirtazapine is not the most efficient ant depressant and it is not a true ssri as fluoxe...</td>\n",
" <td>[[-0.114040159, 0.140852138, 0.0999100953, 0.208959475, 0.445060819, -0.403621316, 0.0552569143, -0.0890201628, 0.380254924, 0.108175397, 0.191386163, 0.198272184, -0.133397803, 0.212966055, 0.352456003, -0.07531479, 0.341809332, 0.151971966, 0.2...</td>\n",
" <td>[[-0.155445561, 0.0941457227, 0.0411367081, 0.255660385, 0.30229032, -0.253930658, -0.176501781, 0.917308688, -0.183687523, 0.209650502, -0.0855835676, 0.239034563, 0.762762547, 0.259996265, 0.34940359, -0.0778813362, -0.315282226, -0.212972909, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>can a thyroid patient eat soybean and fenugreek?</td>\n",
" <td>patients with hypothyroidism usually gain weight. your issue is weight loss which is seen in hyperthyroidism. as your thyroid tsh is in the normal range you can continue the same treatment. for gaining weight you need to take food which is adequa...</td>\n",
" <td>[[-0.0945982337, 0.04440815, -0.219836012, 0.196798429, 0.402243942, -0.0414064191, 1.45660985, 0.214540154, 0.410930932, -0.0685333759, 1.27774835, 0.206304967, -0.320117086, 0.0697160363, 0.302823365, -0.181685016, 1.5156101, 0.679543853, -0.08...</td>\n",
" <td>[[-0.267755091, 0.496627122, -0.10593427, 0.103044294, 0.482136637, 0.210582703, -0.194033623, 0.417719126, -0.306303591, 0.23062554, -0.251927078, -0.0518328063, 0.22350128, 0.335046589, -0.0103447549, 0.497870088, 0.153194278, -0.197104171, 0.4...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>i am not getting my periods after taking fenugreek seeds. why?</td>\n",
" <td>fenugreek seed cannot affect your fertility do not worry. a delayed period could be because of stress or hormonal imbalance so please get a urine pregnancy test to rule out pregnancy first. for further queries consult an infertility specialist on...</td>\n",
" <td>[[-0.0772762671, -0.0546492599, -0.290007412, 0.234665141, -0.0717474371, 0.210957736, 0.501454949, -0.33825165, 0.535232365, 0.141104475, 0.105892427, 0.167244852, -0.226345539, 0.0772434399, 0.36760062, -0.121957906, 0.0198328495, 1.51193035, 0...</td>\n",
" <td>[[-0.116682649, 0.229011983, 0.0717253983, 0.0508261435, 0.188567623, 0.305067122, -0.131368637, -0.294420958, -0.202981532, 0.0689166486, -0.0496700145, 0.0921775177, 0.522677302, 0.173455626, 0.19158718, -0.0330378525, -0.165551513, -0.17966866...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>kindly suggest me a therapy to overcome heat allergy.</td>\n",
" <td>your problem is a characteristic of cholinergic urticaria. it is a type of urticaria where patients are allergic to their own sweat. so whenever a patient sweats for example due to heat sun stress exercise. etc. the patient develops hives. levoce...</td>\n",
" <td>[[0.190717205, -0.109118752, 0.225994617, 0.448829651, -0.368060827, 1.09241807, 0.22018972, 0.1560826, -0.269190162, 0.220193535, 1.38247335, 0.249987021, -0.202662915, -0.0893628523, 0.185544237, -0.270314127, 0.238500059, -0.357885599, 0.36902...</td>\n",
" <td>[[-0.0469765291, 0.159166887, -0.205679953, -0.120664336, 0.337732494, -0.0699605793, -0.248624474, 0.400170565, -0.30279389, 0.209822923, -0.101327896, -0.0589761622, 0.456502318, 0.149086922, -0.0414450914, -0.176266044, -0.028876394, -0.345402...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" question \\\n",
"0 is it fine to exercise with knee pain? \n",
"1 suffering from anxiety restlessness and taking clonazepam & mirtazapine. i had depression & panic attacks for the last 7 years. need a second opinion. \n",
"2 can a thyroid patient eat soybean and fenugreek? \n",
"3 i am not getting my periods after taking fenugreek seeds. why? \n",
"4 kindly suggest me a therapy to overcome heat allergy. \n",
"\n",
" answer \\\n",
"0 from your description it appears that you may have anterior knee pain which sometimes presents as pain at the back of the knee. the second possibility is that you have over done your exercise and hamstrings are sore and the lower end of the knee ... \n",
"1 depression anxiety restlessness and panic attacks are best respond to a combination of a selective serotonin reuptake inhibitors (ssris) and benzodiazepines. mirtazapine is not the most efficient ant depressant and it is not a true ssri as fluoxe... \n",
"2 patients with hypothyroidism usually gain weight. your issue is weight loss which is seen in hyperthyroidism. as your thyroid tsh is in the normal range you can continue the same treatment. for gaining weight you need to take food which is adequa... \n",
"3 fenugreek seed cannot affect your fertility do not worry. a delayed period could be because of stress or hormonal imbalance so please get a urine pregnancy test to rule out pregnancy first. for further queries consult an infertility specialist on... \n",
"4 your problem is a characteristic of cholinergic urticaria. it is a type of urticaria where patients are allergic to their own sweat. so whenever a patient sweats for example due to heat sun stress exercise. etc. the patient develops hives. levoce... \n",
"\n",
" Q_FFNN_embeds \\\n",
"0 [[-0.0236410219, 0.128144488, 0.30177781, 0.430800796, 0.0534969121, 1.24597561, 0.908191383, -0.0682020858, 1.49799263, 0.0182549823, 0.159414783, -0.000211991704, 0.000532273552, -0.0226245634, -0.0949951187, -0.0198594704, 1.25414896, 0.360615... \n",
"1 [[-0.114040159, 0.140852138, 0.0999100953, 0.208959475, 0.445060819, -0.403621316, 0.0552569143, -0.0890201628, 0.380254924, 0.108175397, 0.191386163, 0.198272184, -0.133397803, 0.212966055, 0.352456003, -0.07531479, 0.341809332, 0.151971966, 0.2... \n",
"2 [[-0.0945982337, 0.04440815, -0.219836012, 0.196798429, 0.402243942, -0.0414064191, 1.45660985, 0.214540154, 0.410930932, -0.0685333759, 1.27774835, 0.206304967, -0.320117086, 0.0697160363, 0.302823365, -0.181685016, 1.5156101, 0.679543853, -0.08... \n",
"3 [[-0.0772762671, -0.0546492599, -0.290007412, 0.234665141, -0.0717474371, 0.210957736, 0.501454949, -0.33825165, 0.535232365, 0.141104475, 0.105892427, 0.167244852, -0.226345539, 0.0772434399, 0.36760062, -0.121957906, 0.0198328495, 1.51193035, 0... \n",
"4 [[0.190717205, -0.109118752, 0.225994617, 0.448829651, -0.368060827, 1.09241807, 0.22018972, 0.1560826, -0.269190162, 0.220193535, 1.38247335, 0.249987021, -0.202662915, -0.0893628523, 0.185544237, -0.270314127, 0.238500059, -0.357885599, 0.36902... \n",
"\n",
" A_FFNN_embeds \n",
"0 [[-0.115900427, 0.182273567, -0.0992501155, -0.0385564938, 0.740532875, 0.167836308, 0.0228974223, -0.23636511, -0.172942773, 0.25693363, -0.24061957, -0.0263501219, 0.0366276056, -0.126324296, -0.00830298476, 0.158679247, 0.0368386209, -0.393908... \n",
"1 [[-0.155445561, 0.0941457227, 0.0411367081, 0.255660385, 0.30229032, -0.253930658, -0.176501781, 0.917308688, -0.183687523, 0.209650502, -0.0855835676, 0.239034563, 0.762762547, 0.259996265, 0.34940359, -0.0778813362, -0.315282226, -0.212972909, ... \n",
"2 [[-0.267755091, 0.496627122, -0.10593427, 0.103044294, 0.482136637, 0.210582703, -0.194033623, 0.417719126, -0.306303591, 0.23062554, -0.251927078, -0.0518328063, 0.22350128, 0.335046589, -0.0103447549, 0.497870088, 0.153194278, -0.197104171, 0.4... \n",
"3 [[-0.116682649, 0.229011983, 0.0717253983, 0.0508261435, 0.188567623, 0.305067122, -0.131368637, -0.294420958, -0.202981532, 0.0689166486, -0.0496700145, 0.0921775177, 0.522677302, 0.173455626, 0.19158718, -0.0330378525, -0.165551513, -0.17966866... \n",
"4 [[-0.0469765291, 0.159166887, -0.205679953, -0.120664336, 0.337732494, -0.0699605793, -0.248624474, 0.400170565, -0.30279389, 0.209822923, -0.101327896, -0.0589761622, 0.456502318, 0.149086922, -0.0414450914, -0.176266044, -0.028876394, -0.345402... "
]
},
"metadata": {
"tags": []
},
"execution_count": 31
}
]
},
{
"metadata": {
"id": "vnjuTC7LW4Jv",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"question_bert = np.concatenate(qa[\"Q_FFNN_embeds\"].values, axis=0)\n",
"answer_bert = np.concatenate(qa[\"A_FFNN_embeds\"].values, axis=0)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "ODTXaWyDW6SK",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "7ccf7b46-6e4d-45cf-a09e-755f77373611"
},
"cell_type": "code",
"source": [
"answer_bert.shape\n"
],
"execution_count": 33,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(239402, 768)"
]
},
"metadata": {
"tags": []
},
"execution_count": 33
}
]
},
{
"metadata": {
"id": "8_ank7uIW8Nb",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"question_bert = question_bert.astype('float32')\n",
"answer_bert = answer_bert.astype('float32')"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "Q1DnMFKlx6As",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1045
},
"outputId": "69ac5192-1e97-4273-c4bf-e5b495aa74c8"
},
"cell_type": "code",
"source": [
"#just the CPU version of FAISS, will have to look deeper on how to get GPU version, but works fast enough for now \n",
"\n",
"!wget https://anaconda.org/pytorch/faiss-cpu/1.2.1/download/linux-64/faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2\n",
"!tar xvjf faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2\n",
"!cp -r lib/python3.6/site-packages/* /usr/local/lib/python3.6/dist-packages/\n",
"!pip install mkl"
],
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"text": [
"--2019-04-27 21:50:59-- https://anaconda.org/pytorch/faiss-cpu/1.2.1/download/linux-64/faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2\n",
"Resolving anaconda.org (anaconda.org)... 104.17.92.24, 104.17.93.24, 2606:4700::6811:5c18, ...\n",
"Connecting to anaconda.org (anaconda.org)|104.17.92.24|:443... connected.\n",
"HTTP request sent, awaiting response... 302 FOUND\n",
"Location: https://binstar-cio-packages-prod.s3.amazonaws.com/5a15c9c5c376961204909d87/5aa7f0a65571b411e5c259be?response-content-disposition=attachment%3B%20filename%3D%22faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2%22%3B%20filename%2A%3DUTF-8%27%27faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2&response-content-type=application%2Fx-tar&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=60&X-Amz-Date=20190427T215059Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=AgoJb3JpZ2luX2VjEEwaCXVzLWVhc3QtMSJHMEUCIQCCdA3Clq4GTCjW83ABPZ0zleZpxsS%2BG0aYdavPCTFmHgIgVBBVYJHgz5EKQPLxsXBJRha%2BgFBuFmPXImqzS1PUPW0q2gMINRAAGgw0NTU4NjQwOTgzNzgiDKbFCD71q557hyI6niq3A1izBuAjfBiBG%2F3h4gDsHcIyRJc%2BhlBIUM35ZBGocT1zjTv5ZXmCJy%2FkpTZXRj9o1t1joflr7btusR%2FLsaHOKVqdaUXLk9THTTUXEEj0S9FKPWyEV90LEPTs%2BWnH%2FvDRPM6%2Bq6AmdHSPhTxSGE7smlQIhuMHMLlk2X9hzDk8b0uOT%2FG0TTK3N1%2FN2LaZLPc9sekNkYa2TbCh8n2mzqF4pslusyYP0doGAk2vDeSQMLpMQAy9IaTRuC0n%2FKXzBSd0TR7ScCp5lBW4pc3F5PTqWrAiQe6XeURJwKg7i8cU2of8xn%2FSpBYab%2FSjqJJH7y%2B5oXDNRkRldlvwhet3q70wfzRLEI77qk9bG7u6%2F9VWA3jid1%2BlIR0R3D3ujKSVMaMvhn%2FJ%2BJoHAH2n7aMUb9%2BDHAgRMQ2cpUSrpYq5ZtP5rqMGq6nokqYUpX6erPDYZ0OIJTi1CxuzxM9wvFgd6jXrfqdVwgIBSy9VPjngmvIO1CEF%2FHAxBkwjhzcVM2zcXsRwhYJu5dcMMqddmtNtHx5IQi6%2BjBRHiyy70sXHOQERMXW%2BFx1nG8aiXZ7bnoNjXlbRc82U1t5GVBEw%2FOCS5gU6tAENsczsCAmmmOfaYuNeduMlGACO4kuGMuDwXNNpoBlUxKgajcymSS%2B4hlLT4BG3EwYaAiC5HYaOqjJEPzW6oYaje1%2BkYQ%2B4MUpzLB8yF1UQvWm8dr2YZtXbf3nNYU8NBnzZRVROuaVZFrRDMBLXaSJCnpI0%2FPc8QkvEsgi8%2Bt2RafM7J4wrokLQhCI9jmY8rGlISSh5OFO67fW19EOQo7A3ISABE25X07DXQHLyFV4uSZzuMhM%3D&X-Amz-Credential=ASIAWUI46DZFJAQBPJM2%2F20190427%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=30d75e69c15c1ecc849658d4ec2ecc1e6fb75434cedcdf99919b4ad222213ae7 [following]\n",
"--2019-04-27 21:50:59-- https://binstar-cio-packages-prod.s3.amazonaws.com/5a15c9c5c376961204909d87/5aa7f0a65571b411e5c259be?response-content-disposition=attachment%3B%20filename%3D%22faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2%22%3B%20filename%2A%3DUTF-8%27%27faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2&response-content-type=application%2Fx-tar&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=60&X-Amz-Date=20190427T215059Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=AgoJb3JpZ2luX2VjEEwaCXVzLWVhc3QtMSJHMEUCIQCCdA3Clq4GTCjW83ABPZ0zleZpxsS%2BG0aYdavPCTFmHgIgVBBVYJHgz5EKQPLxsXBJRha%2BgFBuFmPXImqzS1PUPW0q2gMINRAAGgw0NTU4NjQwOTgzNzgiDKbFCD71q557hyI6niq3A1izBuAjfBiBG%2F3h4gDsHcIyRJc%2BhlBIUM35ZBGocT1zjTv5ZXmCJy%2FkpTZXRj9o1t1joflr7btusR%2FLsaHOKVqdaUXLk9THTTUXEEj0S9FKPWyEV90LEPTs%2BWnH%2FvDRPM6%2Bq6AmdHSPhTxSGE7smlQIhuMHMLlk2X9hzDk8b0uOT%2FG0TTK3N1%2FN2LaZLPc9sekNkYa2TbCh8n2mzqF4pslusyYP0doGAk2vDeSQMLpMQAy9IaTRuC0n%2FKXzBSd0TR7ScCp5lBW4pc3F5PTqWrAiQe6XeURJwKg7i8cU2of8xn%2FSpBYab%2FSjqJJH7y%2B5oXDNRkRldlvwhet3q70wfzRLEI77qk9bG7u6%2F9VWA3jid1%2BlIR0R3D3ujKSVMaMvhn%2FJ%2BJoHAH2n7aMUb9%2BDHAgRMQ2cpUSrpYq5ZtP5rqMGq6nokqYUpX6erPDYZ0OIJTi1CxuzxM9wvFgd6jXrfqdVwgIBSy9VPjngmvIO1CEF%2FHAxBkwjhzcVM2zcXsRwhYJu5dcMMqddmtNtHx5IQi6%2BjBRHiyy70sXHOQERMXW%2BFx1nG8aiXZ7bnoNjXlbRc82U1t5GVBEw%2FOCS5gU6tAENsczsCAmmmOfaYuNeduMlGACO4kuGMuDwXNNpoBlUxKgajcymSS%2B4hlLT4BG3EwYaAiC5HYaOqjJEPzW6oYaje1%2BkYQ%2B4MUpzLB8yF1UQvWm8dr2YZtXbf3nNYU8NBnzZRVROuaVZFrRDMBLXaSJCnpI0%2FPc8QkvEsgi8%2Bt2RafM7J4wrokLQhCI9jmY8rGlISSh5OFO67fW19EOQo7A3ISABE25X07DXQHLyFV4uSZzuMhM%3D&X-Amz-Credential=ASIAWUI46DZFJAQBPJM2%2F20190427%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=30d75e69c15c1ecc849658d4ec2ecc1e6fb75434cedcdf99919b4ad222213ae7\n",
"Resolving binstar-cio-packages-prod.s3.amazonaws.com (binstar-cio-packages-prod.s3.amazonaws.com)... 52.216.8.243\n",
"Connecting to binstar-cio-packages-prod.s3.amazonaws.com (binstar-cio-packages-prod.s3.amazonaws.com)|52.216.8.243|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 4106816 (3.9M) [application/x-tar]\n",
"Saving to: ‘faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2’\n",
"\n",
"faiss-cpu-1.2.1-py3 100%[===================>] 3.92M 18.9MB/s in 0.2s \n",
"\n",
"2019-04-27 21:50:59 (18.9 MB/s) - ‘faiss-cpu-1.2.1-py36_cuda9.0.176_1.tar.bz2’ saved [4106816/4106816]\n",
"\n",
"info/hash_input.json\n",
"info/has_prefix\n",
"info/index.json\n",
"info/git\n",
"info/files\n",
"info/LICENSE.txt\n",
"info/about.json\n",
"info/paths.json\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/dependency_links.txt\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/not-zip-safe\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/requires.txt\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/top_level.txt\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/native_libs.txt\n",
"info/test/run_test.py\n",
"info/test/run_test.sh\n",
"info/test/tests/run_tests.sh\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/SOURCES.txt\n",
"info/recipe/conda_build_config.yaml\n",
"info/recipe/build.sh\n",
"info/test/tests/CMakeLists.txt\n",
"info/test/tests/Makefile\n",
"info/recipe/meta.yaml.template\n",
"lib/python3.6/site-packages/faiss-0.1-py3.6.egg-info/PKG-INFO\n",
"info/test/tests/test_factory.py\n",
"info/test/tests/test_ivfpq_codec.cpp\n",
"info/recipe/meta.yaml\n",
"info/recipe/setup.py\n",
"info/test/tests/test_blas.cpp\n",
"info/recipe/makefile.inc\n",
"info/test/tests/test_ivfpq_indexing.cpp\n",
"info/test/tests/test_ondisk_ivf.cpp\n",
"info/test/tests/test_build_blocks.py\n",
"info/test/tests/test_merge.cpp\n",
"info/test/tests/test_pairs_decoding.cpp\n",
"info/test/tests/test_index_composite.py\n",
"lib/python3.6/site-packages/faiss/__init__.py\n",
"lib/python3.6/site-packages/faiss/__pycache__/__init__.cpython-36.pyc\n",
"info/test/tests/test_index.py\n",
"info/test/tests/test_blas\n",
"lib/python3.6/site-packages/faiss/__pycache__/swigfaiss.cpython-36.pyc\n",
"lib/python3.6/site-packages/faiss/swigfaiss.py\n",
"lib/python3.6/site-packages/faiss/_swigfaiss.so\n",
"Requirement already satisfied: mkl in /usr/local/lib/python3.6/dist-packages (2019.0)\n",
"Requirement already satisfied: intel-openmp in /usr/local/lib/python3.6/dist-packages (from mkl) (2019.0)\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "oMnnEA8tyA5r",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 50
},
"outputId": "1bb37710-54ed-4049-fee4-38c1a725339f"
},
"cell_type": "code",
"source": [
"import faiss"
],
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"text": [
"Failed to load GPU Faiss: No module named 'faiss.swigfaiss_gpu'\n",
"Faiss falling back to CPU-only.\n"
],
"name": "stderr"
}
]
},
{
"metadata": {
"id": "AO6Tp_IuW-YC",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"\n",
"answer_index = faiss.IndexFlatIP(answer_bert.shape[-1])\n",
"answer_index.add(answer_bert)\n",
"\n",
"question_index = faiss.IndexFlatIP(question_bert.shape[-1])\n",
"question_index.add(question_bert)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "WmS4qp0dXARy",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 286
},
"outputId": "5ff43506-ebc2-43b8-de83-5e5770fa7dc8"
},
"cell_type": "code",
"source": [
"k = 30\n",
"#Ds are the similarity measure, I has the index for most similar results \n",
"D1, I1 = answer_index.search(question_bert[0:1].astype('float32'), k)\n",
"D2, I2 = question_index.search(question_bert[0:1].astype('float32'), k)\n",
"print(I1)\n",
"print(D1)\n",
"print(I2)\n",
"print(D2)"
],
"execution_count": 40,
"outputs": [
{
"output_type": "stream",
"text": [
"[[128615 143957 222840 121379 117150 112091 129940 37561 141478 110320\n",
" 126174 160561 21328 91230 25738 155089 156980 183619 170790 94097\n",
" 161793 136356 207851 195835 117149 222838 64077 223485 119392 168245]]\n",
"[[405.85333 405.82928 405.46613 405.45767 405.16296 404.1385 403.4854\n",
" 403.4804 403.43344 403.32248 403.2827 403.2272 403.19385 403.02863\n",
" 402.93143 402.93143 402.82086 402.76416 402.6483 402.63184 402.62112\n",
" 402.62112 402.57986 402.5463 402.49426 402.3978 402.31146 402.2641\n",
" 402.26385 402.22153]]\n",
"[[199751 16061 8448 16062 138683 138682 207968 207900 134725 134727\n",
" 134726 134728 204163 85377 157089 207771 181769 195148 195147 197974\n",
" 207378 138590 204550 204549 95940 40757 53512 21501 164640 164641]]\n",
"[[509.72015 508.36224 508.36224 508.36224 499.45764 499.45764 499.07867\n",
" 498.8585 498.66592 498.66592 498.66592 498.66592 498.58594 496.55\n",
" 494.847 494.18304 494.17285 494.07904 494.07904 493.6217 492.95193\n",
" 492.90863 492.3601 492.3601 491.7894 491.33768 491.16754 490.5197\n",
" 489.92807 489.92807]]\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "FwropD7WXCDq",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "dd79799d-8f44-4de7-d56f-c23a0452eb1d"
},
"cell_type": "code",
"source": [
"qa[\"question\"][0]\n"
],
"execution_count": 37,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'is it fine to exercise with knee pain?'"
]
},
"metadata": {
"tags": []
},
"execution_count": 37
}
]
},
{
"metadata": {
"id": "pbo7eqC_XERK",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 54
},
"outputId": "38f522f6-856b-4bd4-cb35-1a1b8f466ba9"
},
"cell_type": "code",
"source": [
"qa[\"answer\"][0]\n"
],
"execution_count": 38,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'from your description it appears that you may have anterior knee pain which sometimes presents as pain at the back of the knee. the second possibility is that you have over done your exercise and hamstrings are sore and the lower end of the knee cap is inflamed. either way you should rest and ice the area of pain and give it time. i suggest you add nsaids (nonsteroidal anti-inflammatory drugs) for a week for an additional anti-inflammatory action. for further information consult an orthopaedician and traumatologist online --> <link>'"
]
},
"metadata": {
"tags": []
},
"execution_count": 38
}
]
},
{
"metadata": {
"id": "tAXoyCB3cqCe",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 521
},
"outputId": "0efac1fe-3eb5-4f51-946d-4af2b452677d"
},
"cell_type": "code",
"source": [
"list(I1[0])"
],
"execution_count": 20,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[128615,\n",
" 143957,\n",
" 222840,\n",
" 121379,\n",
" 117150,\n",
" 112091,\n",
" 129940,\n",
" 37561,\n",
" 141478,\n",
" 110320,\n",
" 126174,\n",
" 160561,\n",
" 21328,\n",
" 91230,\n",
" 25738,\n",
" 155089,\n",
" 156980,\n",
" 183619,\n",
" 170790,\n",
" 94097,\n",
" 161793,\n",
" 136356,\n",
" 207851,\n",
" 195835,\n",
" 117149,\n",
" 222838,\n",
" 64077,\n",
" 223485,\n",
" 119392,\n",
" 168245]"
]
},
"metadata": {
"tags": []
},
"execution_count": 20
}
]
},
{
"metadata": {
"id": "lIeZSuIOdESE",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 558
},
"outputId": "bd4fcb79-acac-44db-afaf-18cf4afecdbe"
},
"cell_type": "code",
"source": [
"qa.loc[list(I1[0]), :]['answer']"
],
"execution_count": 43,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"128615 water exercises meaning exercising in a pool is a great way for people with back hip knee or foot problems to exercise.\n",
"143957 it is important to diet do some form of cardiac exercise such as treadmill or elliptical trainer and do resistant exercises such as free weights machines or pully's.\n",
"222840 pain with walking a certain distance that causes you to rest pain is usually in the calf and is result of inadequate blood flow needed to perform activity\n",
"121379 first you need to see your doctor to be sure exercise will be ok. water exercise like swimming is easy on the joints if you are a good swimmer.\n",
"117150 exercise bicycling water aerobics or swimming allows you to work out without putting much stress on your knees.\n",
"112091 can't lose it safely without exercise.\n",
"129940 walking running or other day burning activity for 20min or more 2-3 times per week with targeted strength training exercises will slim the thighs. also remember to eat well.\n",
"37561 Your doctor will give you this advice: Take a few weeks off from sports, ice any swelling and play it by ear. When there's no pain from stretching it, you can return to basketball. \n",
"141478 only if it prevents overall exercise and movement because of pain. . some good activities for chronic back issues - swimming lower impact walking core strengthening with trainer or therapist.\n",
"110320 you can alter your exercise program by swimming or bicycling stationary.\n",
"126174 unless the knee pain is significant ignore the issue. mild oa often means little or nothing. if the knee pain is a problem get a 2nd opinion with an orthopedist.\n",
"160561 -on core strengthening jumping jacks r more 4 cardio. once u have a strong core then try some jumping jacks still painful back 2 more vigorous core strengthening.\n",
"21328 yes this can happen due long standing. make a point to move around to improve blood circulation to your legs. do some calf muscle exercise leg stretching exercise to keep your muscles toned.\n",
"91230 Depends on the amount of pain. If extremely pain, then yes go to the ER. If the pain is tolerable and you can take Tylenol or Motrin, then do that.,I'd avoid strenuous exercise until you have an official diagnosis. Light exercise should be fine.\n",
"25738 You probably compressed a nerve while exercising and now you're in pain. Minimize your activities for a few days and take it slow, the pain should subside. If it does not go to your physician to get checked out. \\n\\n(Ease up at the gym. Take is e...\n",
"155089 exercise including ab exercises (crunches ).\n",
"156980 i would recommend a graduated walking plan. start out with 5 minutes average pace twice a day. move up 5 minutes every 5-7 days. ultimately 40-60 minutes of moderate pace would be ideal. once you are able to do that easily move into some strength...\n",
"183619 it is generally fine to do a moderate cardiovascular (not weight lifting) exercise of walking or cycling for 30 - 40 minutes. however it is best to consult with your doctor on whether or not one can exercise as hshe knows you best and can look at...\n",
"170790 one of the key elements is exercise. when we are dealing with pain in paget's disease keep in mind supervised exercise plan by your doctor avoid weight gain to decrease pressure on weight bearing joints and bones keep the joints active and pain f...\n",
"94097 You probably strained a muscle. Rest (don't do anything that hurts), apply heat, massage the area (you can roll on a tennis ball), and take NSAIDs as directed; it should get better in a few days. If you notice pain shooting down a leg, or weaknes...\n",
"161793 one can try running or jogging. jogging is a good way to lose weight as long as one doesn't eat a lot of snacks energy bars nor drink sugared drinks while jogging. weight will only be lost if the calories burned during jogging exceeds the calorie...\n",
"136356 one can try running or jogging. jogging is a good way to lose weight as long as one doesn't eat a lot of snacks energy bars nor drink sugared drinks while jogging. weight will only be lost if the calories burned during jogging exceeds the calorie...\n",
"207851 avoid strenuous exercise until you get evaluated for exercise intolerance consider a treadmill.\n",
"195835 i'd recommend taking a break from cycling until the stiffness and swelling improves. naproxen (aleve) twice daily can help and wrapping it. not being in pain is a good sign that its not surgical but a strain from instant overuse. when better inch...\n",
"117149 swimming is a great way to exercise without putting a lot of pressure on the knee. it provides a great aerobic exercise and in combination with modifications in your diet you should be able to lose the weight.\n",
"222838 the major symptom of leg clarification is calf pain while walking that relieves itself after stopping walking or exercising.\n",
"64077 Stretching, look up golfers elbow exercises. ,Do as much as you can tolerate.\n",
"223485 in patients with very severe pad there can sometimes be pain at rest most often in the last place to get blood the toes.\n",
"119392 possibly related to early osteoarthritis. weight loss will slow progression of oa of knees and help with pain. would recommend switching to exercises that spare the knee such as bicycling swimming etc till knee symptoms improve.\n",
"168245 breast pain is not a typical side effect of exercise. make sure you are wearing a good supportive sports bra but a woman's breast health is serious business. do not ignore it!\n",
"Name: answer, dtype: object"
]
},
"metadata": {
"tags": []
},
"execution_count": 43
}
]
},
{
"metadata": {
"id": "jhagwEU8dG08",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 558
},
"outputId": "6df6550c-d721-4276-f825-349848d4999e"
},
"cell_type": "code",
"source": [
"qa.loc[list(I2[0]), :]['question']"
],
"execution_count": 44,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"199751 heart pounds significantly harder (around rate of 180) during exercise than b4 even during mild physical exertions. mild chest discomfort.\n",
"16061 how do i exercise with osteoarthritis and patellar tendonitis in both knees and falling arches in both feet?\n",
"8448 how do i exercise with osteoarthritis and patellar tendonitis in both knees and falling arches in both feet?\n",
"16062 how do i exercise with osteoarthritis and patellar tendonitis in both knees and falling arches in both feet?\n",
"138683 obese high bp age 32/female. achy calves in am itchy near ankles. oa: hip knee foot ankle. explain daytime fatigue? sleep study toss & turn/apnea.\n",
"138682 obese high bp age 32/female. achy calves in am itchy near ankles. oa: hip knee foot ankle. explain daytime fatigue? sleep study toss & turn/apnea.\n",
"207968 pvcs during late stage exercise but only when doing bending exercises. none during jogging/running/biking. echo/holter/event/ekg normal. is this vagus?\n",
"207900 normal nuclear stress echo holter 2011. normal exercise test 7/12 12 recent ekgs normal. worth the risk of cath to deal with ongoing chest pain?\n",
"134725 my ortho recommended the synvisc (hylan g-f 20) shot for my arthritic knee. dose this shot really work? i am overweight and walk slow.\n",
"134727 my ortho recommended the synvisc (hylan g-f 20) shot for my arthritic knee. dose this shot really work? i am overweight and walk slow.\n",
"134726 my ortho recommended the synvisc (hylan g-f 20) shot for my arthritic knee. dose this shot really work? i am overweight and walk slow.\n",
"134728 my ortho recommended the synvisc (hylan g-f 20) shot for my arthritic knee. dose this shot really work? i am overweight and walk slow.\n",
"204163 intermittent rapid heart rate at rest and after warm bath/showers? ! 2 week event/holter negative even during intense exercise. not anxious.\n",
"85377 Feet swelling. Paranoid its heart failure. F/304/5”11. No known illnesses. No on meds.[deleted]\n",
"157089 does being on a cereal and wheat free high protein diet help wiith tendon issues in knee and chronic pain in feet ankle all long standing conditions?\n",
"207771 my heart rate is elevated during exercise and after? athlete should be harder to reach 190's than it is. pounding sob. hr at 135 13 min after finish.\n",
"181769 need prognosis for woman 75 stage 4 breast cancer mets to (hip/knee bone): otherwise very healthful. refuses treatment. planning long rv trip soon!\n",
"195148 i was going to a pain mangement in monroe mi i when to a pain management in toledo ohio and they can do nothing for it hurt to walk sit sleep i cry?\n",
"195147 i was going to a pain mangement in monroe mi i when to a pain management in toledo ohio and they can do nothing for it hurt to walk sit sleep i cry?\n",
"197974 issue: throbbing headache increased pulse upon standing from seating. / regular bp @rest 110/76. studying in cold room-- feet/hands often cold.\n",
"207378 what are appropriate heart rates for a 6yo resting to sitting to standing. 48lbs. 44in. resting heart rate typically 100. goes to 145 with dancing. ?\n",
"138590 nausea and muscle weakness lasting hours after short exercise (~10mins). i am obese and just started today after months of inactivity. is this normal?\n",
"204550 went to cardiologist for skip beats did ekg said (extra electricity) prescribed betab but potassium seem to help i get random twitch everywhere (calf/thigh mainly) tightened leg feel headache\n",
"204549 went to cardiologist for skip beats did ekg said (extra electricity) prescribed betab but potassium seem to help i get random twitch everywhere (calf/thigh mainly) tightened leg feel headache\n",
"95940 Tibial plateau fracture Sept 10; surgery Sept. 13. Lots of hardware. Slipped on driveway this afternoon. Question...[deleted]\n",
"40757 Upper Outside Right Knee Chronic Pain - 1.5T MRI Dual Knees for Comparison\n",
"53512 Shoulder pain when lifting arm overheadYesterday I did some heavy benching at the gym, and during one of my sets I felt a pop, following by searing pain. Fast-foward to today, I now cant lift my arm straight up over my head without having massive...\n",
"21501 i am not feeling chest workouts in my chest. my chest is not building up like the rest of my body. how can i fix this? . if i am working biceps/triceps i will feel it in that area so i know i am doing the exercise right to get results. however ev...\n",
"164640 from 3 month my rt calf muscle compresses pains n makes foot numb. am not overweight. pls advise if its atherosclerosis or peripheral artery disease.\n",
"164641 from 3 month my rt calf muscle compresses pains n makes foot numb. am not overweight. pls advise if its atherosclerosis or peripheral artery disease.\n",
"Name: question, dtype: object"
]
},
"metadata": {
"tags": []
},
"execution_count": 44
}
]
},
{
"metadata": {
"id": "wK9kloZ3dKQ8",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"def topKTesting(xf, kf):\n",
" D1, I1 = answer_index.search(question_bert[xf:xf+1].astype('float32'), kf)\n",
" D2, I2 = question_index.search(question_bert[xf:xf+1].astype('float32'), kf)\n",
" print(\"Question is : \", qa[\"question\"][xf])\n",
" print(\"Ground Truth Answer is : \", qa[\"answer\"][xf] )\n",
" print(\" \")\n",
" print(\"Top k Answers are : \")\n",
" print(qa.loc[list(I1[0]), :]['answer'])\n",
" print(\" \")\n",
" print(\"Top k Questions are : \")\n",
" print(qa.loc[list(I1[0]), :]['question'])\n",
" "
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "JYPet7Wh7Pqz",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 440
},
"outputId": "1168c724-d372-48cf-dfe0-eedc16fd2c25"
},
"cell_type": "code",
"source": [
"#First number is the index from the pandas database where you want to extract the question and ground truth answer\n",
"#Second number is the k, as in top k results you want returned. \n",
"\n",
"topKTesting(23568, 8)"
],
"execution_count": 55,
"outputs": [
{
"output_type": "stream",
"text": [
"Question is : at the age of 40 is it common to \"fall apart\"? . the chief medical officer in the army told me i had been born with a condition in which my sarcral joint was made of cartlage instead of bone. i herniated l3/l4. for months i have had knee pain and dismissed it as possible arthritis however recently i started having neck pain that radiates down over the left shoulder preventing me from full neck motion. after about a week the pain subsided and now i'm having knee pain again on the interior side of the right leg.\n",
"Ground Truth Answer is : we recommend you to visit orthopedic for thorough check up of your spine. better to have specialist opinion for your condition.\n",
" \n",
"Top k Answers are : \n",
"197878 need to rule out cervical spondylosis.\n",
"15860 can pneumonia cause an osteoarthritis flair up?\n",
"77489 This is not an emergency. See your PCP.,MRI would be the imaging modality of choice for slipped discs. You have much more likely just irritated a nerve, possibly from muscle spasm? As to if its an emergency- only if the pain is severe enough to n...\n",
"47080 I would see your doctor and get an exam and xrays. unlikely to have significant osteoarthritis at 26 years old, but other common things like femoroacetabular impingement can cause the symptoms you describe in your age group\n",
"40240 What direction did your lower leg bone move? To test for an ACL tear have someone perform an anterior drawer test on you.\n",
"47881 Bursitis, quad pain or patellofemoral syndrome\n",
"30558 Well, osteoarthritis ( which is what I assume they meant) is just wear and tear of the joints and bones. So there's not really much in the way of reversing the damage that has been done, unfortunately.\\ncortisone injections lessen the inflammati...\n",
"65266 Is there any pain or did you do anything to injure it? In your age range a solitary clicking knee is more often than not a meniscus tear or a similar injury. \n",
"Name: answer, dtype: object\n",
" \n",
"Top k Questions are : \n",
"197878 headaches back pain neck pain tingling in right foot and pain in leg weak tired not eating or drinking. blood work ecg holter echo stress test-normal?\n",
"15860 what are the treatments for pneumonia?\n",
"77489 Neck pain and electric sensation in right arm and right side of chest - do I need to go to the ER?[deleted]\n",
"47080 Should I be worried about hip pain?I'm a 26 year old female. 5'9\", 130 lbs. Beginning a little over a year ago, I've noticed that when I walk for long periods of time, my right hip aches. It feels like it is coming from the joint, not the surroun...\n",
"40240 Twisted kneeToday I was stepping down from a step ladder and I twisted my leg the wrong way. I think my lower leg bone popped out and popped back in. The initial pain was intense, but after a couple of minutes of icing, my knee was fine. As the d...\n",
"47881 Going to see my regular doctor on Friday for knee pain. Would like your opinion as well.28, M, 6'2\", 170 lb, white, California.\\n\\nFor many years I've had pain that comes and goes in my left knee. I believe I first messed it up as a teenager but ...\n",
"30558 19yo College athlete with arthritis in foot.I suffered from a Lysfrank dislocation about a year and a half ago, all 5 metatarsals dislocated. i had a surgery to re-position them and put 4 screws and a pin in, another to remove all of them. I was ...\n",
"65266 Clicky Knee[deleted]\n",
"Name: question, dtype: object\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "JnR5W70A7UCz",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}