-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
502005c
commit a802562
Showing
12 changed files
with
117,986 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,352 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"UsageError: Line magic function `%` not found.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"import h5py\n", | ||
"import json\n", | ||
"import numpy as np\n", | ||
"import sys\n", | ||
"import glob\n", | ||
"import typing\n", | ||
"import copy\n", | ||
"from typing import List, Dict, Union\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import pickle as pkl\n", | ||
"% matplotlib inline\n", | ||
"sys.path.append(\"../\") # Append visdialch path" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from collections import defaultdict\n", | ||
"unique_dialog_ques = defaultdict()\n", | ||
"unique_dialog_ans = defaultdict()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path_train_data = \"../../data/visdial_1.0_train.json\"\n", | ||
"dense_annotations_jsonpath = \"../../data/visdial_1.0_train_dense_annotations.json\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"data_train = json.load(open(path_train_data))\n", | ||
"\n", | ||
"questions = data_train['data']['questions']\n", | ||
"len(questions)\n", | ||
"\n", | ||
"answers = data_train['data']['answers']\n", | ||
"len(answers)\n", | ||
"\n", | ||
"dialogs = data_train['data']['dialogs']\n", | ||
"\n", | ||
"unique_dialog_ques = defaultdict()\n", | ||
"unique_dialog_ans = defaultdict()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"123287\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(len(dialogs))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for dial_index in range(len(dialogs)):\n", | ||
" dial_for_image = dialogs[dial_index]['dialog']\n", | ||
" for round_index in range(len(dial_for_image)):\n", | ||
" ques_key = questions[dial_for_image[round_index]['question']]\n", | ||
" ans_key = answers[dial_for_image[round_index]['answer']] \n", | ||
" unique_dialog_ques[ques_key] = unique_dialog_ques.get(ques_key, 0) + 1\n", | ||
" unique_dialog_ans[ans_key] = unique_dialog_ans.get(ans_key, 0) + 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"337527\n", | ||
"OrderedDict([('no', 262225), ('yes', 236115), ('white', 19680), ('black', 11818), ('brown', 8401), (\"can't tell\", 8195), (\"i can't tell\", 6519), ('2', 5012), ('yes it is', 4798), ('1', 4500), ('0', 4312), ('not that i can see', 3581), ('nope', 3514), ('blue', 3389), ('not really', 3336), ('3', 3274), ('red', 3216), ('day', 3152), ('i think so', 3046), ('green', 2946)])\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from collections import Counter, OrderedDict\n", | ||
"\n", | ||
"# unique_dialog_ans = dict(unique_dialog_ans)\n", | ||
"unique_ans = Counter(unique_dialog_ans)\n", | ||
"most_common_ans = OrderedDict(unique_ans.most_common(20))\n", | ||
"\n", | ||
"print(len(unique_ans))\n", | ||
"print(most_common_ans)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"376082\n", | ||
"is it sunny -- 13466\n", | ||
"is it daytime -- 10241\n", | ||
"is the photo in color -- 7279\n", | ||
"can you see the sky -- 5082\n", | ||
"are there any people -- 4894\n", | ||
"what color is it -- 4314\n", | ||
"any people -- 3914\n", | ||
"is it day or night -- 3654\n", | ||
"is it sunny out -- 3618\n", | ||
"is this in color -- 3049\n", | ||
"do you see any people -- 3035\n", | ||
"what color are the walls -- 2953\n", | ||
"can you see any people -- 2946\n", | ||
"is it a sunny day -- 2734\n", | ||
"any trees -- 2666\n", | ||
"how old is the man -- 2657\n", | ||
"are there trees -- 2655\n", | ||
"what is he wearing -- 2614\n", | ||
"what color is the table -- 2570\n", | ||
"what color is his hair -- 2560\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"unique_ques = Counter(unique_dialog_ques)\n", | ||
"most_common_ques = OrderedDict(unique_ques.most_common(20))\n", | ||
"\n", | ||
"print(len(unique_ques))\n", | ||
"# print(most_common_ques)\n", | ||
"\n", | ||
"for item in most_common_ques.items():\n", | ||
" print(item[0], \"--\", item[1])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting pandas\n", | ||
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/73/9b/52e228545d14f14bb2a1622e225f38463c8726645165e1cb7dde95bfe6d4/pandas-0.25.1-cp36-cp36m-manylinux1_x86_64.whl (10.5MB)\n", | ||
"\u001b[K 100% |████████████████████████████████| 10.5MB 2.2MB/s eta 0:00:01\n", | ||
"\u001b[?25hRequirement already satisfied: pytz>=2017.2 in /home/shubham/anaconda3/envs/visdialch/lib/python3.6/site-packages (from pandas) (2017.3)\n", | ||
"Requirement already satisfied: numpy>=1.13.3 in /home/shubham/anaconda3/envs/visdialch/lib/python3.6/site-packages (from pandas) (1.15.4)\n", | ||
"Requirement already satisfied: python-dateutil>=2.6.1 in /home/shubham/anaconda3/envs/visdialch/lib/python3.6/site-packages (from pandas) (2.8.0)\n", | ||
"Requirement already satisfied: six>=1.5 in /home/shubham/anaconda3/envs/visdialch/lib/python3.6/site-packages (from python-dateutil>=2.6.1->pandas) (1.12.0)\n", | ||
"Installing collected packages: pandas\n", | ||
"Successfully installed pandas-0.25.1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%!pip install pandas" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"ques_df = pd.DataFrame.from_dict(unique_ques, orient='index')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"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>0</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <td>is this a child or adult</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>male or female</td>\n", | ||
" <td>838</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>are they inside or outside</td>\n", | ||
" <td>381</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>are they laying on the floor</td>\n", | ||
" <td>3</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>is the floor carpeted or wooden</td>\n", | ||
" <td>2</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>how big is the gate</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>any of them have tusks</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>would you go in this building</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>is he doing a flip in the air</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <td>is he wearing any kind of gear</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"<p>376082 rows × 1 columns</p>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" 0\n", | ||
"is this a child or adult 1\n", | ||
"male or female 838\n", | ||
"are they inside or outside 381\n", | ||
"are they laying on the floor 3\n", | ||
"is the floor carpeted or wooden 2\n", | ||
"... ...\n", | ||
"how big is the gate 1\n", | ||
"any of them have tusks 1\n", | ||
"would you go in this building 1\n", | ||
"is he doing a flip in the air 1\n", | ||
"is he wearing any kind of gear 1\n", | ||
"\n", | ||
"[376082 rows x 1 columns]" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"ques_df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.9" | ||
}, | ||
"pycharm": { | ||
"stem_cell": { | ||
"cell_type": "raw", | ||
"source": [], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.