Skip to content

Instantly share code, notes, and snippets.

@hans
Created November 26, 2019 22:32
Show Gist options
  • Save hans/068320bfacd1423928c9d18a0df671d1 to your computer and use it in GitHub Desktop.
Save hans/068320bfacd1423928c9d18a0df671d1 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"import itertools\n",
"import json\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline\n",
"from scipy.spatial import distance\n",
"import spacy\n",
"\n",
"from tqdm import tqdm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data prep"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with open(\"/om/data/public/jgauthie/visual-genome-1.4/objects.json\", \"r\") as obj_f:\n",
" vg_obj = json.load(obj_f)\n",
"with open(\"/om/data/public/jgauthie/visual-genome-1.4/relationships.json\", \"r\") as rel_f:\n",
" vg_rel = json.load(rel_f)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 108077/108077 [00:04<00:00, 26321.40it/s]\n"
]
}
],
"source": [
"verb_relations = []\n",
"for scene in tqdm(vg_rel):\n",
" for relationship in scene[\"relationships\"]:\n",
" try:\n",
" verb = next(syn for syn in relationship[\"synsets\"] if \".v.\" in syn)\n",
" except StopIteration: continue\n",
" \n",
" verb_relations.append((scene[\"image_id\"], verb, relationship[\"subject\"][\"object_id\"], relationship[\"object\"][\"object_id\"]))\n",
" \n",
"verb_relations = pd.DataFrame(verb_relations, columns=[\"scene_id\", \"verb_synset\", \"subject_id\", \"object_id\"])"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"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>scene_id</th>\n",
" <th>verb_synset</th>\n",
" <th>subject_id</th>\n",
" <th>object_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>wear.v.01</td>\n",
" <td>1058529</td>\n",
" <td>1058525</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>have.v.01</td>\n",
" <td>5049</td>\n",
" <td>5050</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1</td>\n",
" <td>have.v.01</td>\n",
" <td>1058529</td>\n",
" <td>1058511</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1</td>\n",
" <td>have.v.01</td>\n",
" <td>1058515</td>\n",
" <td>5060</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1</td>\n",
" <td>have.v.01</td>\n",
" <td>1058529</td>\n",
" <td>1058518</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" scene_id verb_synset subject_id object_id\n",
"0 1 wear.v.01 1058529 1058525\n",
"1 1 have.v.01 5049 5050\n",
"2 1 have.v.01 1058529 1058511\n",
"3 1 have.v.01 1058515 5060\n",
"4 1 have.v.01 1058529 1058518"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"verb_relations.head()"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [],
"source": [
"verb_relations_old = verb_relations.copy()"
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Length before: 782637 n verbs: 500\n",
"Length after: 175563 n verbs: 500\n"
]
}
],
"source": [
"# Drop scenes with few annotations.\n",
"scene_counts = verb_relations.groupby(\"scene_id\").verb_synset.count()\n",
"drop_scenes = scene_counts[scene_counts < 30].index\n",
"\n",
"print(\"Length before:\", len(verb_relations), \"n verbs:\", len(verb_counts))\n",
"verb_relations = verb_relations[~verb_relations.scene_id.isin(drop_scenes)]\n",
"print(\"Length after:\", len(verb_relations), \"n verbs:\", len(verb_relations.verb_synset.unique()))"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Length before: 175563 n verbs: 500\n",
"Length after: 173524 n verbs: 85\n"
]
}
],
"source": [
"# Drop infrequent verbs.\n",
"verb_counts = verb_relations.verb_synset.value_counts()\n",
"drop_verbs = verb_counts[verb_counts < 25].index\n",
"\n",
"print(\"Length before:\", len(verb_relations), \"n verbs:\", len(verb_counts))\n",
"verb_relations = verb_relations[~verb_relations.verb_synset.isin(drop_verbs)]\n",
"print(\"Length after:\", len(verb_relations), \"n verbs:\", len(verb_relations.verb_synset.unique()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Experiment design"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [],
"source": [
"def get_lemma_distances(matrix, lemma_order):\n",
" dists = distance.squareform(distance.pdist(matrix, metric=\"cosine\"))\n",
" ret = []\n",
" for (i1, l1), (i2, l2) in itertools.product(enumerate(lemma_order), repeat=2):\n",
" if i1 >= i2: continue\n",
" ret.append((dists[i1, i2], matrix[i1].sum(), matrix[i2].sum(), l1, l2))\n",
" \n",
" return pd.DataFrame(ret, columns=[\"dist\", \"l1_total\", \"l2_total\", \"l1\", \"l2\"]).set_index([\"l1\", \"l2\"])\n",
"\n",
"def get_conflations(sample):\n",
" cooccurrences = pd.get_dummies(sample.scene_id).groupby(sample.verb_synset).apply(max)\n",
" lemma_order = cooccurrences.index.tolist()\n",
" cooccurrences = np.array(cooccurrences)\n",
" \n",
" scene_distances = get_lemma_distances(cooccurrences, lemma_order=lemma_order)\n",
" conflated_in_scene = scene_distances.index[(scene_distances.dist < 0.2)]\n",
" \n",
" return conflated_in_scene.tolist()"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
"cooccurrences = pd.get_dummies(verb_relations.scene_id).groupby(verb_relations.verb_synset).apply(max)\n",
"lemma_order = cooccurrences.index.tolist()\n",
"cooccurrences_nd = np.array(cooccurrences)\n",
"\n",
"scene_distances = get_lemma_distances(cooccurrences_nd, lemma_order=lemma_order)"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"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></th>\n",
" <th>dist</th>\n",
" <th>l1_total</th>\n",
" <th>l2_total</th>\n",
" </tr>\n",
" <tr>\n",
" <th>l1</th>\n",
" <th>l2</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>have.v.01</th>\n",
" <td>0.142418</td>\n",
" <td>3289</td>\n",
" <td>3904</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.404525</td>\n",
" <td>3904</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.590752</td>\n",
" <td>3289</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>sit.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.637490</td>\n",
" <td>497</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stand.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.641239</td>\n",
" <td>485</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>transport.v.02</th>\n",
" <th>walk.v.01</th>\n",
" <td>0.659197</td>\n",
" <td>168</td>\n",
" <td>197</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">have.v.01</th>\n",
" <th>sit.v.01</th>\n",
" <td>0.668328</td>\n",
" <td>3904</td>\n",
" <td>497</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stand.v.01</th>\n",
" <td>0.677331</td>\n",
" <td>3904</td>\n",
" <td>485</td>\n",
" </tr>\n",
" <tr>\n",
" <th>reach.v.01</th>\n",
" <th>swing.v.01</th>\n",
" <td>0.678109</td>\n",
" <td>53</td>\n",
" <td>59</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.02</th>\n",
" <th>show.v.01</th>\n",
" <td>0.688579</td>\n",
" <td>16</td>\n",
" <td>145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>transport.v.02</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.709161</td>\n",
" <td>168</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>depend_on.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.719185</td>\n",
" <td>161</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>walk.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.720382</td>\n",
" <td>197</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>play.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.724620</td>\n",
" <td>165</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>look.v.02</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.741661</td>\n",
" <td>193</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>watch.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.753076</td>\n",
" <td>116</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>traverse.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.756874</td>\n",
" <td>278</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>traverse.v.01</th>\n",
" <td>0.760027</td>\n",
" <td>3904</td>\n",
" <td>278</td>\n",
" </tr>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>sit.v.01</th>\n",
" <td>0.768484</td>\n",
" <td>3289</td>\n",
" <td>497</td>\n",
" </tr>\n",
" <tr>\n",
" <th>belong_to.v.01</th>\n",
" <th>lie.v.01</th>\n",
" <td>0.769354</td>\n",
" <td>87</td>\n",
" <td>78</td>\n",
" </tr>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>stand.v.01</th>\n",
" <td>0.775930</td>\n",
" <td>3289</td>\n",
" <td>485</td>\n",
" </tr>\n",
" <tr>\n",
" <th>attach.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.780182</td>\n",
" <td>202</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>look.v.02</th>\n",
" <td>0.783417</td>\n",
" <td>3904</td>\n",
" <td>193</td>\n",
" </tr>\n",
" <tr>\n",
" <th>put.v.01</th>\n",
" <th>sit.v.01</th>\n",
" <td>0.787945</td>\n",
" <td>172</td>\n",
" <td>497</td>\n",
" </tr>\n",
" <tr>\n",
" <th>attach.v.01</th>\n",
" <th>have.v.01</th>\n",
" <td>0.788297</td>\n",
" <td>202</td>\n",
" <td>3904</td>\n",
" </tr>\n",
" <tr>\n",
" <th>use.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.790433</td>\n",
" <td>90</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>walk.v.01</th>\n",
" <td>0.791329</td>\n",
" <td>3904</td>\n",
" <td>197</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">stand.v.01</th>\n",
" <th>traverse.v.01</th>\n",
" <td>0.795747</td>\n",
" <td>485</td>\n",
" <td>278</td>\n",
" </tr>\n",
" <tr>\n",
" <th>walk.v.01</th>\n",
" <td>0.802655</td>\n",
" <td>485</td>\n",
" <td>197</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"3\" valign=\"top\">have.v.01</th>\n",
" <th>play.v.01</th>\n",
" <td>0.803139</td>\n",
" <td>3904</td>\n",
" <td>165</td>\n",
" </tr>\n",
" <tr>\n",
" <th>put.v.01</th>\n",
" <td>0.804746</td>\n",
" <td>3904</td>\n",
" <td>172</td>\n",
" </tr>\n",
" <tr>\n",
" <th>transport.v.02</th>\n",
" <td>0.807374</td>\n",
" <td>3904</td>\n",
" <td>168</td>\n",
" </tr>\n",
" <tr>\n",
" <th>swing.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.808397</td>\n",
" <td>59</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>float.v.01</th>\n",
" <th>fly.v.01</th>\n",
" <td>0.809542</td>\n",
" <td>29</td>\n",
" <td>77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>lie.v.01</th>\n",
" <th>put.v.01</th>\n",
" <td>0.810062</td>\n",
" <td>78</td>\n",
" <td>172</td>\n",
" </tr>\n",
" <tr>\n",
" <th>depend_on.v.01</th>\n",
" <th>have.v.01</th>\n",
" <td>0.812060</td>\n",
" <td>161</td>\n",
" <td>3904</td>\n",
" </tr>\n",
" <tr>\n",
" <th>play.v.01</th>\n",
" <th>watch.v.01</th>\n",
" <td>0.812067</td>\n",
" <td>165</td>\n",
" <td>116</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stand.v.01</th>\n",
" <th>turn.v.07</th>\n",
" <td>0.812118</td>\n",
" <td>485</td>\n",
" <td>108</td>\n",
" </tr>\n",
" <tr>\n",
" <th>belong_to.v.01</th>\n",
" <th>form.v.01</th>\n",
" <td>0.812380</td>\n",
" <td>87</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>construct.v.01</th>\n",
" <th>digest.v.03</th>\n",
" <td>0.812380</td>\n",
" <td>24</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>show.v.01</th>\n",
" <td>0.812595</td>\n",
" <td>3904</td>\n",
" <td>145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>sit.v.01</th>\n",
" <th>stand.v.01</th>\n",
" <td>0.812613</td>\n",
" <td>497</td>\n",
" <td>485</td>\n",
" </tr>\n",
" <tr>\n",
" <th>have.v.01</th>\n",
" <th>state.v.01</th>\n",
" <td>0.813312</td>\n",
" <td>3904</td>\n",
" <td>142</td>\n",
" </tr>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>state.v.01</th>\n",
" <td>0.817091</td>\n",
" <td>3289</td>\n",
" <td>142</td>\n",
" </tr>\n",
" <tr>\n",
" <th>put.v.01</th>\n",
" <th>wear.v.01</th>\n",
" <td>0.818875</td>\n",
" <td>172</td>\n",
" <td>1500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>hang.v.01</th>\n",
" <th>have.v.01</th>\n",
" <td>0.821828</td>\n",
" <td>165</td>\n",
" <td>3904</td>\n",
" </tr>\n",
" <tr>\n",
" <th>attach.v.01</th>\n",
" <th>depart.v.03</th>\n",
" <td>0.822002</td>\n",
" <td>202</td>\n",
" <td>40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>be.v.01</th>\n",
" <th>show.v.01</th>\n",
" <td>0.823338</td>\n",
" <td>3289</td>\n",
" <td>145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>attach.v.01</th>\n",
" <th>turn.v.07</th>\n",
" <td>0.823970</td>\n",
" <td>202</td>\n",
" <td>108</td>\n",
" </tr>\n",
" <tr>\n",
" <th>belong_to.v.01</th>\n",
" <th>construct.v.01</th>\n",
" <td>0.824925</td>\n",
" <td>87</td>\n",
" <td>24</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" dist l1_total l2_total\n",
"l1 l2 \n",
"be.v.01 have.v.01 0.142418 3289 3904\n",
"have.v.01 wear.v.01 0.404525 3904 1500\n",
"be.v.01 wear.v.01 0.590752 3289 1500\n",
"sit.v.01 wear.v.01 0.637490 497 1500\n",
"stand.v.01 wear.v.01 0.641239 485 1500\n",
"transport.v.02 walk.v.01 0.659197 168 197\n",
"have.v.01 sit.v.01 0.668328 3904 497\n",
" stand.v.01 0.677331 3904 485\n",
"reach.v.01 swing.v.01 0.678109 53 59\n",
"have.v.02 show.v.01 0.688579 16 145\n",
"transport.v.02 wear.v.01 0.709161 168 1500\n",
"depend_on.v.01 wear.v.01 0.719185 161 1500\n",
"walk.v.01 wear.v.01 0.720382 197 1500\n",
"play.v.01 wear.v.01 0.724620 165 1500\n",
"look.v.02 wear.v.01 0.741661 193 1500\n",
"watch.v.01 wear.v.01 0.753076 116 1500\n",
"traverse.v.01 wear.v.01 0.756874 278 1500\n",
"have.v.01 traverse.v.01 0.760027 3904 278\n",
"be.v.01 sit.v.01 0.768484 3289 497\n",
"belong_to.v.01 lie.v.01 0.769354 87 78\n",
"be.v.01 stand.v.01 0.775930 3289 485\n",
"attach.v.01 wear.v.01 0.780182 202 1500\n",
"have.v.01 look.v.02 0.783417 3904 193\n",
"put.v.01 sit.v.01 0.787945 172 497\n",
"attach.v.01 have.v.01 0.788297 202 3904\n",
"use.v.01 wear.v.01 0.790433 90 1500\n",
"have.v.01 walk.v.01 0.791329 3904 197\n",
"stand.v.01 traverse.v.01 0.795747 485 278\n",
" walk.v.01 0.802655 485 197\n",
"have.v.01 play.v.01 0.803139 3904 165\n",
" put.v.01 0.804746 3904 172\n",
" transport.v.02 0.807374 3904 168\n",
"swing.v.01 wear.v.01 0.808397 59 1500\n",
"float.v.01 fly.v.01 0.809542 29 77\n",
"lie.v.01 put.v.01 0.810062 78 172\n",
"depend_on.v.01 have.v.01 0.812060 161 3904\n",
"play.v.01 watch.v.01 0.812067 165 116\n",
"stand.v.01 turn.v.07 0.812118 485 108\n",
"belong_to.v.01 form.v.01 0.812380 87 16\n",
"construct.v.01 digest.v.03 0.812380 24 58\n",
"have.v.01 show.v.01 0.812595 3904 145\n",
"sit.v.01 stand.v.01 0.812613 497 485\n",
"have.v.01 state.v.01 0.813312 3904 142\n",
"be.v.01 state.v.01 0.817091 3289 142\n",
"put.v.01 wear.v.01 0.818875 172 1500\n",
"hang.v.01 have.v.01 0.821828 165 3904\n",
"attach.v.01 depart.v.03 0.822002 202 40\n",
"be.v.01 show.v.01 0.823338 3289 145\n",
"attach.v.01 turn.v.07 0.823970 202 108\n",
"belong_to.v.01 construct.v.01 0.824925 87 24"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scene_distances.sort_values(\"dist\").head(50)"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {},
"outputs": [],
"source": [
"def inspect_verbs(vbs):\n",
" vb_cooccurrences = cooccurrences.loc[vbs]\n",
" # Drop columns\n",
" drop_columns = vb_cooccurrences.columns[vb_cooccurrences.sum(axis=0) == 0]\n",
" return vb_cooccurrences.drop(columns=drop_columns)\n",
"\n",
"import requests\n",
"from IPython.display import display, HTML\n",
"\n",
"def plot_vg(scene_ids):\n",
" html = []\n",
" if len(scene_ids) > 10:\n",
" scene_ids = np.random.choice(scene_ids, size=7)\n",
" \n",
" for scene_id in scene_ids:\n",
" metadata = requests.get(f\"https://visualgenome.org/api/v0/images/{scene_id}?format=json\").json()\n",
" html.append(f\"<img src='{metadata['url']}' style='display: inline; width: 256px; margin: 1px' />\")\n",
" return display(HTML(\"\".join(html)))\n",
" \n",
"def plot_conflated(v1, v2):\n",
" vb_cooccurrences = cooccurrences.loc[[v1, v2]]\n",
" conflated = vb_cooccurrences.columns[vb_cooccurrences.sum(axis=0) > 1]\n",
" return plot_vg(conflated)"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src='https://cs.stanford.edu/people/rak248/VG_100K/2366005.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2400213.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2403021.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2411786.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K/2362269.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2403021.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2414581.jpg' style='display: inline; width: 256px; margin: 1px' />"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_conflated(\"play.v.01\", \"watch.v.01\")"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src='https://cs.stanford.edu/people/rak248/VG_100K/2358346.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2412119.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K/2335311.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2399848.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K/2377001.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2398597.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2412197.jpg' style='display: inline; width: 256px; margin: 1px' />"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_conflated(\"reach.v.01\", \"swing.v.01\")"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2408646.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2390376.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2405956.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K/2367422.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K/2343256.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2403097.jpg' style='display: inline; width: 256px; margin: 1px' /><img src='https://cs.stanford.edu/people/rak248/VG_100K_2/2380265.jpg' style='display: inline; width: 256px; margin: 1px' />"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_conflated(\"stand.v.01\", \"wear.v.01\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment