Upload 2 files
Browse filesAdd VideoDemo folder with tutorial notebook and video
VideoDemo/WorkingWithTheDataWalkThrough.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e8d3b6c2deb3e52c87cff7705a826916484891fc480927f3555fdf89209092c
|
| 3 |
+
size 1131724031
|
VideoDemo/demoDatset.ipynb
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 48,
|
| 6 |
+
"id": "43220e88",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from datasets import load_dataset\n",
|
| 11 |
+
"from huggingface_hub import HfApi\n",
|
| 12 |
+
"from huggingface_hub.utils import HfHubHTTPError\n",
|
| 13 |
+
"import pandas as pd\n",
|
| 14 |
+
"import json,ast\n",
|
| 15 |
+
"from itertools import islice\n",
|
| 16 |
+
"import pprint\n",
|
| 17 |
+
"pd.set_option('display.max_rows', None)\n",
|
| 18 |
+
"pd.set_option('display.max_columns', None)\n",
|
| 19 |
+
"# Don’t truncate column contents\n",
|
| 20 |
+
"pd.set_option('display.max_colwidth', None)\n",
|
| 21 |
+
"# Don’t wrap wide DataFrames\n",
|
| 22 |
+
"pd.set_option('display.expand_frame_repr', False)\n",
|
| 23 |
+
"pp = pprint.PrettyPrinter(width=200, compact=False)\n",
|
| 24 |
+
"pp = pprint.PrettyPrinter(width=200, compact=False)\n",
|
| 25 |
+
"#pip install \"datasets>=2.20\" \"huggingface_hub>=0.24\" \"pandas>=2.0\" jupyter\n",
|
| 26 |
+
"#paper When No Paths Lead to Rome: Benchmarking Systematic Neural Relational Reasoning. 39th Conference on Neural Information Processing Systems (NeurIPS 2025)."
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"execution_count": 49,
|
| 32 |
+
"id": "32ac5a59",
|
| 33 |
+
"metadata": {},
|
| 34 |
+
"outputs": [
|
| 35 |
+
{
|
| 36 |
+
"name": "stdout",
|
| 37 |
+
"output_type": "stream",
|
| 38 |
+
"text": [
|
| 39 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 40 |
+
"Index(['Unnamed: 0', 'edge_types', 'story_edges', 'query_edge', 'query_label',\n",
|
| 41 |
+
" 'query_relation', 'derivation_chain', 'BL', 'OPEC', 'ReasoningDepth',\n",
|
| 42 |
+
" 'derivations_for_other_implied_relationships',\n",
|
| 43 |
+
" 'metric_for_other_implied_relationships', 'source_file',\n",
|
| 44 |
+
" 'original_row_index', 'alternate_labels_true'],\n",
|
| 45 |
+
" dtype='object')\n",
|
| 46 |
+
"(10589, 15)\n"
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
],
|
| 50 |
+
"source": [
|
| 51 |
+
"##importing training data\n",
|
| 52 |
+
"repo_name = f'NoRA-1.1'\n",
|
| 53 |
+
"ds_train = load_dataset(f\"axd353/{repo_name}\", split=\"train\")\n",
|
| 54 |
+
"df_train = ds_train.to_pandas()\n",
|
| 55 |
+
"print(type(df_train))\n",
|
| 56 |
+
"print(df_train.columns)\n",
|
| 57 |
+
"print(df_train.shape)"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"cell_type": "code",
|
| 62 |
+
"execution_count": 52,
|
| 63 |
+
"id": "2135e566",
|
| 64 |
+
"metadata": {},
|
| 65 |
+
"outputs": [],
|
| 66 |
+
"source": [
|
| 67 |
+
"##helper methods to explain and visualize\n",
|
| 68 |
+
"def dataframe_to_string_with_gaps(df: pd.DataFrame, output_file: str, column_list=None):\n",
|
| 69 |
+
" \"\"\"\n",
|
| 70 |
+
" Takes a Pandas DataFrame and writes each row to a text file as a string,\n",
|
| 71 |
+
" with three line gaps between rows and one line gap between columns within a row.\n",
|
| 72 |
+
" Does not truncate any content.\n",
|
| 73 |
+
"\n",
|
| 74 |
+
" Args:\n",
|
| 75 |
+
" df (pd.DataFrame): The input DataFrame.\n",
|
| 76 |
+
" output_file (str): The name of the output text file.\n",
|
| 77 |
+
" \"\"\"\n",
|
| 78 |
+
" if column_list != None:\n",
|
| 79 |
+
" df =df[column_list]\n",
|
| 80 |
+
" with open(output_file, 'w', encoding='utf-8') as f:\n",
|
| 81 |
+
" for index, row in df.iterrows():\n",
|
| 82 |
+
" row_str = \"\"\n",
|
| 83 |
+
" for col_name, value in row.items():\n",
|
| 84 |
+
" row_str += f'{col_name}: '+str(value)\n",
|
| 85 |
+
" row_str += \"\\n\" # One line gap between columns\n",
|
| 86 |
+
" f.write(row_str)\n",
|
| 87 |
+
" f.write(\"\\n\\n\\n\") # Three line gaps between rows\n",
|
| 88 |
+
"\n",
|
| 89 |
+
"def print_zipped_edges(row_df: pd.DataFrame, M: int = 6, sep: str = \" \", blank_lines: int = 1) -> None:\n",
|
| 90 |
+
" \"\"\"\n",
|
| 91 |
+
" Print zipped (edge_types, story_edges) from a single row in chunks of M.\n",
|
| 92 |
+
"\n",
|
| 93 |
+
" Parameters\n",
|
| 94 |
+
" ----------\n",
|
| 95 |
+
" row_df : pd.DataFrame or pd.Series\n",
|
| 96 |
+
" Single-row DataFrame or Series with 'edge_types' and 'story_edges' as lists.\n",
|
| 97 |
+
" M : int, default=6\n",
|
| 98 |
+
" Tuples per line.\n",
|
| 99 |
+
" sep : str, default=\" \"\n",
|
| 100 |
+
" Separator between tuples on the same line.\n",
|
| 101 |
+
" blank_lines : int, default=1\n",
|
| 102 |
+
" Number of blank lines inserted between printed lines.\n",
|
| 103 |
+
" \"\"\"\n",
|
| 104 |
+
" r = row_df.iloc[0] if isinstance(row_df, pd.DataFrame) else row_df\n",
|
| 105 |
+
" et = r['edge_types']\n",
|
| 106 |
+
" se = r['story_edges']\n",
|
| 107 |
+
"\n",
|
| 108 |
+
" zipped = list(zip(et, se))\n",
|
| 109 |
+
"\n",
|
| 110 |
+
" for start in range(0, len(zipped), M):\n",
|
| 111 |
+
" chunk = zipped[start:start+M]\n",
|
| 112 |
+
" # build one line without the list brackets, with custom separation between tuples\n",
|
| 113 |
+
" line = sep.join(str(t) for t in chunk)\n",
|
| 114 |
+
" print(line)\n",
|
| 115 |
+
" if blank_lines > 0:\n",
|
| 116 |
+
" print(\"\\n\" * blank_lines, end=\"\")\n",
|
| 117 |
+
"\n",
|
| 118 |
+
"\n",
|
| 119 |
+
"def _to_list(x):\n",
|
| 120 |
+
" # minimal + robust: try JSON, then Python literal, then comma-split\n",
|
| 121 |
+
" if isinstance(x, (list, tuple)): \n",
|
| 122 |
+
" return list(x)\n",
|
| 123 |
+
" if pd.isna(x):\n",
|
| 124 |
+
" return []\n",
|
| 125 |
+
" if isinstance(x, str):\n",
|
| 126 |
+
" s = x.strip()\n",
|
| 127 |
+
" for parser in (json.loads, ast.literal_eval):\n",
|
| 128 |
+
" try:\n",
|
| 129 |
+
" v = parser(s)\n",
|
| 130 |
+
" return list(v) if isinstance(v, (list, tuple)) else [v]\n",
|
| 131 |
+
" except Exception:\n",
|
| 132 |
+
" pass\n",
|
| 133 |
+
" # fallback: comma-separated\n",
|
| 134 |
+
" return [p.strip() for p in s.split(\",\") if p.strip()]\n",
|
| 135 |
+
" return [x]\n"
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"cell_type": "code",
|
| 140 |
+
"execution_count": 53,
|
| 141 |
+
"id": "f608ac19",
|
| 142 |
+
"metadata": {},
|
| 143 |
+
"outputs": [],
|
| 144 |
+
"source": [
|
| 145 |
+
"##some columns have bene turned into string getting them back to list\n",
|
| 146 |
+
"for col in ['edge_types', 'story_edges', 'query_label']:\n",
|
| 147 |
+
" df_train[col] = df_train[col].apply(_to_list)"
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"cell_type": "code",
|
| 152 |
+
"execution_count": 57,
|
| 153 |
+
"id": "05650457",
|
| 154 |
+
"metadata": {},
|
| 155 |
+
"outputs": [
|
| 156 |
+
{
|
| 157 |
+
"name": "stdout",
|
| 158 |
+
"output_type": "stream",
|
| 159 |
+
"text": [
|
| 160 |
+
"('is_person', (0, 0)) ('is_male', (0, 0)) ('is_person', (1, 1)) ('is_female', (1, 1)) ('is_person', (2, 2)) ('is_male', (2, 2)) ('is_place', (3, 3)) ('is_person', (4, 4))\n",
|
| 161 |
+
"\n",
|
| 162 |
+
"('is_female', (4, 4)) ('is_person', (5, 5)) ('is_female', (5, 5)) ('is_person', (6, 6)) ('is_female', (6, 6)) ('is_place', (7, 7)) ('is_place', (8, 8)) ('is_person', (9, 9))\n",
|
| 163 |
+
"\n",
|
| 164 |
+
"('is_person', (10, 10)) ('is_male', (10, 10)) ('is_person', (11, 11)) ('is_male', (11, 11)) ('is_person', (12, 12)) ('is_male', (12, 12)) ('is_person', (13, 13)) ('is_male', (13, 13))\n",
|
| 165 |
+
"\n",
|
| 166 |
+
"('is_person', (14, 14)) ('is_male', (14, 14)) ('is_person', (15, 15)) ('is_male', (15, 15)) ('is_place', (16, 16)) ('is_person', (17, 17)) ('is_male', (17, 17)) ('is_place', (18, 18))\n",
|
| 167 |
+
"\n",
|
| 168 |
+
"('is_person', (19, 19)) ('is_female', (19, 19)) ('is_underage', (19, 19)) ('is_person', (20, 20)) ('is_female', (20, 20)) ('is_place', (21, 21)) ('is_person', (22, 22)) ('is_male', (22, 22))\n",
|
| 169 |
+
"\n",
|
| 170 |
+
"('is_place', (23, 23)) ('no_sisters', (0, 0)) ('no_brothers', (1, 1)) ('no_sons', (15, 15)) ('living_in', (6, 3)) ('father_of', (11, 19)) ('living_in_same_place', (1, 15)) ('grandson_of', (22, 1))\n",
|
| 171 |
+
"\n",
|
| 172 |
+
"('living_in', (2, 23)) ('living_in', (20, 16)) ('school_mates_with', (17, 0)) ('living_in_same_place', (17, 11)) ('living_in', (19, 21)) ('nephew_of', (14, 6)) ('living_in', (1, 16)) ('grandparent_of', (13, 9))\n",
|
| 173 |
+
"\n",
|
| 174 |
+
"('school_mates_with', (20, 12)) ('living_in_same_place', (0, 5)) ('grandparent_of', (15, 5)) ('sibling_in_law_of', (19, 17)) ('grandparent_of', (14, 20)) ('living_in_same_place', (5, 13)) ('paternal_aunt_or_uncle_of', (12, 1)) ('paternal_grandparent_of', (22, 17))\n",
|
| 175 |
+
"\n",
|
| 176 |
+
"('living_in', (4, 8)) ('living_in', (14, 16)) ('aunt_or_uncle_of', (2, 0)) ('sister_in_law_of', (1, 11)) ('living_in', (9, 8)) ('parent_of', (4, 11)) ('aunt_of', (9, 15)) ('school_mates_with', (17, 10))\n",
|
| 177 |
+
"\n",
|
| 178 |
+
"('paternal_aunt_of', (4, 9)) ('brother_of', (10, 20)) ('living_in', (10, 21)) ('grandparent_of', (22, 20)) ('wife_of', (5, 6)) ('maternal_aunt_of', (19, 14)) ('uncle_of', (11, 22)) ('grandparent_of', (4, 12))\n",
|
| 179 |
+
"\n",
|
| 180 |
+
"('maternal_grandparent_of', (13, 1)) ('sibling_of', (15, 19)) ('living_in', (0, 21)) ('living_in', (22, 18)) ('maternal_grandparent_of', (13, 2)) ('living_in', (17, 21)) ('maternal_aunt_or_uncle_of', (4, 6)) ('aunt_or_uncle_of', (11, 5))\n",
|
| 181 |
+
"\n",
|
| 182 |
+
"('nibling_of', (5, 0)) ('father_in_law_of', (13, 0)) ('paternal_grandparent_of', (14, 10))\n",
|
| 183 |
+
"\n",
|
| 184 |
+
"5597 (15, 5)\n",
|
| 185 |
+
"Name: query_edge, dtype: object\n",
|
| 186 |
+
"5597 [grandfather_of, grandparent_of, maternal_grandparent_of, maternal_grandfather_of]\n",
|
| 187 |
+
"Name: query_label, dtype: object\n"
|
| 188 |
+
]
|
| 189 |
+
}
|
| 190 |
+
],
|
| 191 |
+
"source": [
|
| 192 |
+
"##description of task \n",
|
| 193 |
+
"row = df_train[(df_train['source_file']=='result_59519031_8_seed244.csv') & (df_train['original_row_index']==21116)]\n",
|
| 194 |
+
"print_zipped_edges(row, M=8)\n",
|
| 195 |
+
"print(row['query_edge'])\n",
|
| 196 |
+
"print(row['query_label'])"
|
| 197 |
+
]
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"cell_type": "code",
|
| 201 |
+
"execution_count": 58,
|
| 202 |
+
"id": "b6d92ae3",
|
| 203 |
+
"metadata": {},
|
| 204 |
+
"outputs": [],
|
| 205 |
+
"source": [
|
| 206 |
+
"explore_df2 = df_train[(df_train['source_file'] == 'result_59519031_8_seed244.csv') & (df_train['original_row_index']==21116)]\n",
|
| 207 |
+
"dataframe_to_string_with_gaps(explore_df2, '/home/anirban/CameraReadyVersionForNeurIPS/MakingVideos/stories2.txt')"
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"cell_type": "code",
|
| 212 |
+
"execution_count": null,
|
| 213 |
+
"id": "578b1225",
|
| 214 |
+
"metadata": {},
|
| 215 |
+
"outputs": [],
|
| 216 |
+
"source": [
|
| 217 |
+
"##visualize story\n",
|
| 218 |
+
"row = df_train[(df_train['source_file']=='result_59526051_6_seed296.csv') & (df_train['original_row_index']==483)]\n",
|
| 219 |
+
"print_zipped_edges(row, M=8)\n",
|
| 220 |
+
"print(row['query_edge'])\n",
|
| 221 |
+
"print(row['query_label'])"
|
| 222 |
+
]
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
"cell_type": "code",
|
| 226 |
+
"execution_count": null,
|
| 227 |
+
"id": "aff4091e",
|
| 228 |
+
"metadata": {},
|
| 229 |
+
"outputs": [],
|
| 230 |
+
"source": [
|
| 231 |
+
"##visualizing the derivation of labels in a story \n",
|
| 232 |
+
"explore_df = df_train[(df_train['source_file']=='result_59526051_6_seed296.csv') & (df_train['original_row_index']==483)]\n",
|
| 233 |
+
"dataframe_to_string_with_gaps(explore_df, '/home/anirban/CameraReadyVersionForNeurIPS/MakingVideos/stories1.txt')"
|
| 234 |
+
]
|
| 235 |
+
}
|
| 236 |
+
],
|
| 237 |
+
"metadata": {
|
| 238 |
+
"kernelspec": {
|
| 239 |
+
"display_name": "Edge Transformer Env",
|
| 240 |
+
"language": "python",
|
| 241 |
+
"name": "edge_transformer"
|
| 242 |
+
},
|
| 243 |
+
"language_info": {
|
| 244 |
+
"codemirror_mode": {
|
| 245 |
+
"name": "ipython",
|
| 246 |
+
"version": 3
|
| 247 |
+
},
|
| 248 |
+
"file_extension": ".py",
|
| 249 |
+
"mimetype": "text/x-python",
|
| 250 |
+
"name": "python",
|
| 251 |
+
"nbconvert_exporter": "python",
|
| 252 |
+
"pygments_lexer": "ipython3",
|
| 253 |
+
"version": "3.12.3"
|
| 254 |
+
}
|
| 255 |
+
},
|
| 256 |
+
"nbformat": 4,
|
| 257 |
+
"nbformat_minor": 5
|
| 258 |
+
}
|