Skip to content

Commit

Permalink
Minor fixes to poincare nb - change in variable name, relative path, …
Browse files Browse the repository at this point in the history
…misaligned header
  • Loading branch information
jayantj committed Oct 23, 2017
1 parent 0a23030 commit 58fc15e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 73 deletions.
118 changes: 45 additions & 73 deletions docs/notebooks/Poincare Evaluation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Set this to the path of the directory that is to contain the poincare-embedding directory\n",
"parent_directory = '/home/jayant/projects/'"
"# The poincare datasets, models and c++ source code are downloaded to this directory\n",
"parent_directory = './poincare/'\n",
"! mkdir -p {parent_directory}"
]
},
{
Expand All @@ -60,13 +61,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"/home/jayant/projects\n",
"/home/jayant/projects/gensim/docs/notebooks/poincare\n",
"Cloning into 'poincare-embedding'...\n",
"remote: Counting objects: 96, done.\u001b[K\n",
"remote: Total 96 (delta 0), reused 0 (delta 0), pack-reused 96\u001b[K\n",
"Unpacking objects: 100% (96/96), done.\n",
"Checking connectivity... done.\n",
"/home/jayant/projects/poincare-embedding\n"
"/home/jayant/projects/gensim/docs/notebooks/poincare/poincare-embedding\n"
]
}
],
Expand All @@ -82,37 +83,6 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2017-10-18 20:37:11-- https://raw.githubusercontent.com/RaRe-Technologies/gensim/poincare_eval/docs/notebooks/poincare_data/poincare_burn_in_eps.patch\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.112.133\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.112.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 7999 (7.8K) [text/plain]\n",
"Saving to: ‘./poincare_burn_in_eps.patch’\n",
"\n",
"./poincare_burn_in_ 100%[===================>] 7.81K --.-KB/s in 0s \n",
"\n",
"2017-10-18 20:37:11 (59.5 MB/s) - ‘./poincare_burn_in_eps.patch’ saved [7999/7999]\n",
"\n"
]
}
],
"source": [
"# Download and apply patch\n",
"patch_url = \"https://raw.githubusercontent.com/RaRe-Technologies/gensim/poincare_eval/docs/notebooks/poincare_data/poincare_burn_in_eps.patch\"\n",
"! wget {patch_url} -O ./poincare_burn_in_eps.patch\n",
"! git apply poincare_burn_in_eps.patch\n",
"! rm poincare_burn_in_eps.patch"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -123,14 +93,16 @@
}
],
"source": [
"# Apply patch\n",
"! git apply ../poincare_burn_in_eps.patch\n",
"% cd {current_directory}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Follow the instructions in the README to compile the sources and create the binaries."
"Follow the instructions in the [README](https://github.com/TatsuyaShirakawa/poincare-embedding/blob/master/README.md) to compile the sources in the poincare directory and create the binaries."
]
},
{
Expand All @@ -144,22 +116,22 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# These directories are auto created in the current directory for storing poincare datasets and models\n",
"data_directory = 'poincare_data'\n",
"models_directory = os.path.join(data_directory, 'models')\n",
"data_directory = os.path.join(parent_directory, 'data')\n",
"models_directory = os.path.join(parent_directory, 'models')\n",
"\n",
"# Create directories\n",
"! mkdir {data_directory}\n",
"! mkdir {models_directory}"
"! mkdir -p {data_directory}\n",
"! mkdir -p {models_directory}"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -179,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 8,
"metadata": {
"scrolled": true
},
Expand All @@ -188,32 +160,32 @@
"name": "stdout",
"output_type": "stream",
"text": [
"--2017-10-18 20:44:13-- http://people.ds.cam.ac.uk/iv250/paper/hyperlex/hyperlex-data.zip\n",
"--2017-10-23 12:50:28-- http://people.ds.cam.ac.uk/iv250/paper/hyperlex/hyperlex-data.zip\n",
"Resolving people.ds.cam.ac.uk (people.ds.cam.ac.uk)... 131.111.3.47\n",
"Connecting to people.ds.cam.ac.uk (people.ds.cam.ac.uk)|131.111.3.47|:80... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 183900 (180K) [application/zip]\n",
"Saving to: ‘poincare_data/hyperlex-data.zip’\n",
"Saving to: ‘./poincare/data/hyperlex-data.zip’\n",
"\n",
"poincare_data/hyper 100%[===================>] 179.59K --.-KB/s in 0.06s \n",
"./poincare/data/hyp 100%[===================>] 179.59K --.-KB/s in 0.06s \n",
"\n",
"2017-10-18 20:44:13 (2.75 MB/s) - ‘poincare_data/hyperlex-data.zip’ saved [183900/183900]\n",
"2017-10-23 12:50:28 (2.93 MB/s) - ‘./poincare/data/hyperlex-data.zip’ saved [183900/183900]\n",
"\n",
"Archive: poincare_data/hyperlex-data.zip\n",
" creating: poincare_data/nouns-verbs/\n",
" inflating: poincare_data/nouns-verbs/hyperlex-verbs.txt \n",
" inflating: poincare_data/nouns-verbs/hyperlex-nouns.txt \n",
" creating: poincare_data/splits/\n",
" creating: poincare_data/splits/random/\n",
" inflating: poincare_data/splits/random/hyperlex_training_all_random.txt \n",
" inflating: poincare_data/splits/random/hyperlex_test_all_random.txt \n",
" inflating: poincare_data/splits/random/hyperlex_dev_all_random.txt \n",
" creating: poincare_data/splits/lexical/\n",
" inflating: poincare_data/splits/lexical/hyperlex_dev_all_lexical.txt \n",
" inflating: poincare_data/splits/lexical/hyperlex_test_all_lexical.txt \n",
" inflating: poincare_data/splits/lexical/hyperlex_training_all_lexical.txt \n",
" inflating: poincare_data/hyperlex-all.txt \n",
" inflating: poincare_data/README.txt \n"
"Archive: ./poincare/data/hyperlex-data.zip\n",
" creating: ./poincare/data/nouns-verbs/\n",
" inflating: ./poincare/data/nouns-verbs/hyperlex-verbs.txt \n",
" inflating: ./poincare/data/nouns-verbs/hyperlex-nouns.txt \n",
" creating: ./poincare/data/splits/\n",
" creating: ./poincare/data/splits/random/\n",
" inflating: ./poincare/data/splits/random/hyperlex_training_all_random.txt \n",
" inflating: ./poincare/data/splits/random/hyperlex_test_all_random.txt \n",
" inflating: ./poincare/data/splits/random/hyperlex_dev_all_random.txt \n",
" creating: ./poincare/data/splits/lexical/\n",
" inflating: ./poincare/data/splits/lexical/hyperlex_dev_all_lexical.txt \n",
" inflating: ./poincare/data/splits/lexical/hyperlex_test_all_lexical.txt \n",
" inflating: ./poincare/data/splits/lexical/hyperlex_training_all_lexical.txt \n",
" inflating: ./poincare/data/hyperlex-all.txt \n",
" inflating: ./poincare/data/README.txt \n"
]
}
],
Expand All @@ -234,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -276,7 +248,7 @@
" for option, value in args.items():\n",
" cmd.append(\"--%s\" % option)\n",
" cmd.append(str(value))\n",
"\n",
" \n",
" return check_output(args=cmd)"
]
},
Expand Down Expand Up @@ -324,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 118,
"metadata": {
"scrolled": true
},
Expand Down Expand Up @@ -571,7 +543,7 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -663,7 +635,7 @@
" \n",
" \n",
" @staticmethod\n",
" def get_positive_relation_ranks(distances, positive_relations):\n",
" def get_positive_relation_ranks(all_distances, positive_relations):\n",
" \"\"\"\n",
" Given a numpy array of all distances from an item and indices of its positive relations,\n",
" compute ranks of positive relations\n",
Expand All @@ -675,8 +647,8 @@
" Returns:\n",
" list of ranks of positive items in the same order as `positive_indices`\n",
" \"\"\"\n",
" positive_relation_distances = distances[positive_relations]\n",
" negative_relation_distances = np.ma.array(distances, mask=False)\n",
" positive_relation_distances = all_distances[positive_relations]\n",
" negative_relation_distances = np.ma.array(all_distances, mask=False)\n",
" negative_relation_distances.mask[positive_relations] = True\n",
" # Compute how many negative relation distances are less than each positive relation distance, plus 1 for rank\n",
" ranks = (negative_relation_distances < positive_relation_distances[:, np.newaxis]).sum(axis=1) + 1\n",
Expand Down Expand Up @@ -812,7 +784,7 @@
},
{
"cell_type": "code",
"execution_count": 83,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -933,7 +905,7 @@
},
{
"cell_type": "code",
"execution_count": 86,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1143,8 +1115,8 @@
"output_type": "stream",
"text": [
"Results for WordNet Link Prediction task\n",
"+--------------------------------------------+---------------------------------+\n",
"| | Model Dimensions |\n",
"+--------------------------------------------+------------------------------------------+\n",
"| | Model Dimensions |\n",
"+---------------------------------+-----------+--------+--------+-------+-------+-------+\n",
"| Model Description | Metric | 5 | 10 | 20 | 50 | 100 |\n",
"+---------------------------------+-----------+--------+--------+-------+-------+-------+\n",
Expand Down

0 comments on commit 58fc15e

Please sign in to comment.