{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# QASPER evaluation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/ag2435/anaconda3/envs/arxiv-agent/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import json\n", "import os\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "import dataset_reader\n", "from transformers.tokenization_utils_base import BatchEncoding" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# input_path = 'original_data/qasper-train-dev-v0.3/qasper-train-v0.3.json'\n", "input_path = 'original_data/qasper-test-and-evaluator-v0.3/qasper-test-v0.3.json'\n", "output_path = 'data'\n", "split = 'test'\n", "assert split in input_path" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "reader = dataset_reader.QasperReader(include_global_attention_mask=False)\n", "instances = list(reader._read(input_path))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "defaultdict(int,\n", " {'number of documents': 416,\n", " 'number of questions': 1451,\n", " 'number of answers': 3554,\n", " 'questions with multiple answers': 1427,\n", " 'extractive questions': 1817,\n", " 'extractive questions with multiple spans': 787,\n", " 'multiple_evidence_spans_count': 1063,\n", " 'freeform answers': 878,\n", " 'answers with table or figure as evidence': 391,\n", " 'answers with no evidence': 444,\n", " 'unanswerable questions': 366,\n", " 'yes/no questions': 493,\n", " 'number of truncated contexts': 2})" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reader._stats" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "variable=0
value=%{x}
count=%{y}", "legendgroup": "0", "marker": { "color": "#636efa", "pattern": { "shape": "" } }, "name": "0", "offsetgroup": "0", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 7574, 7569, 7574, 7577, 4103, 5491, 5489, 5489, 5491, 5492, 5489, 4802, 4802, 6355, 6358, 6363, 2632, 2638, 2633, 3556, 3557, 3557, 3954, 3948, 3947, 3948, 2593, 2592, 2589, 7232, 4374, 4379, 4375, 7679, 7679, 7680, 7680, 7679, 7681, 2631, 2629, 2627, 2627, 2627, 5644, 5644, 5641, 5642, 4153, 4153, 4152, 3628, 3627, 3626, 6481, 6471, 6477, 5854, 5851, 5855, 2812, 2814, 4355, 4355, 4352, 4355, 5766, 5763, 5767, 5764, 5758, 3341, 3339, 3360, 3341, 3345, 1649, 1651, 1650, 2317, 2315, 2314, 2893, 2891, 2895, 2664, 2668, 2668, 2663, 5552, 5559, 5557, 5555, 6438, 6443, 6438, 6437, 5294, 5290, 5291, 5291, 4229, 4224, 4224, 2715, 2711, 2716, 2710, 2711, 2712, 2710, 3279, 3282, 3282, 3282, 3283, 3280, 3474, 3474, 3475, 3476, 5646, 5646, 5646, 5642, 4563, 4561, 4562, 4567, 4563, 4563, 4561, 5194, 5189, 5196, 8518, 8519, 8518, 8520, 8519, 8519, 3673, 3673, 3676, 6399, 6407, 4527, 4522, 4522, 5838, 5836, 5836, 8347, 8349, 1179, 1177, 1176, 1177, 1176, 3294, 3294, 6697, 6708, 6707, 5097, 5094, 5105, 2141, 2144, 2143, 4648, 4643, 4645, 3723, 3723, 3723, 3721, 2445, 2444, 3659, 3649, 3647, 3650, 4460, 4460, 3645, 3641, 3641, 3643, 2776, 2783, 2771, 3348, 3341, 3344, 3341, 2778, 2779, 2783, 2781, 3659, 3653, 3658, 3653, 2624, 2628, 2627, 2625, 2625, 2626, 3584, 3580, 2838, 2837, 4610, 4607, 4605, 4604, 4605, 4802, 4802, 4804, 4802, 4801, 4798, 4800, 2959, 2954, 2956, 5573, 5578, 2539, 2537, 2537, 14957, 14954, 14946, 14953, 4510, 4502, 4502, 4504, 4501, 4774, 4775, 5710, 5929, 5928, 3004, 3003, 3003, 3007, 3008, 4526, 4530, 4528, 4526, 2903, 2906, 2906, 3373, 3379, 3371, 3375, 3375, 3637, 3637, 2096, 2090, 6331, 6327, 6328, 5317, 5320, 5310, 5314, 5963, 5960, 2989, 2989, 2991, 3545, 3551, 3546, 3544, 6593, 6609, 6586, 5183, 5189, 5182, 6773, 6760, 6772, 6761, 5712, 5710, 5710, 6712, 6711, 6715, 4002, 3992, 3998, 6192, 6184, 6186, 6189, 5478, 5485, 4384, 4386, 4385, 4384, 3545, 3264, 3266, 3263, 3266, 5838, 5840, 2884, 2880, 2883, 2884, 2998, 2998, 2998, 3001, 2706, 2701, 2704, 2704, 4195, 4197, 4194, 2768, 2761, 2767, 2762, 3169, 6721, 4036, 2888, 2887, 8826, 8826, 8826, 8824, 2398, 2404, 5021, 5038, 5030, 5825, 3670, 3669, 3577, 3206, 3204, 4054, 8719, 4150, 4153, 854, 7084, 7088, 7086, 6814, 3623, 3624, 7944, 4680, 4682, 4682, 4680, 4683, 4682, 4679, 4680, 5535, 5542, 5534, 5539, 5542, 5537, 4813, 4816, 4815, 4812, 4812, 4813, 2785, 2783, 2786, 2792, 2784, 2792, 4384, 4383, 4386, 4385, 4387, 4825, 4827, 4832, 4823, 4823, 2876, 2877, 2873, 2877, 2873, 7625, 7631, 7632, 7629, 7625, 3088, 3090, 3087, 3087, 2874, 2870, 2870, 2867, 2866, 2868, 2867, 2867, 1977, 1975, 1979, 1976, 4580, 4587, 4585, 4590, 8314, 8310, 8307, 8314, 5827, 5823, 5823, 5825, 5974, 5971, 5974, 5972, 5974, 5973, 5974, 5798, 5800, 5786, 4363, 4363, 4362, 3041, 3039, 3036, 4393, 4394, 4393, 6195, 6199, 6196, 6384, 6384, 6384, 6384, 6383, 6386, 3365, 3366, 3379, 5022, 5019, 5017, 2636, 2646, 2639, 2635, 2636, 2650, 5039, 5035, 5037, 4184, 4185, 4184, 4807, 4809, 4806, 4806, 4808, 4815, 3033, 3044, 3045, 3314, 3313, 3313, 3308, 3313, 3311, 4984, 4977, 4985, 5919, 5918, 5919, 4500, 4505, 4516, 4341, 4348, 4347, 4507, 4522, 4514, 7900, 7887, 7888, 7887, 7886, 7887, 7891, 7888, 5912, 5908, 5904, 5905, 5902, 3650, 3648, 3651, 3651, 3648, 3554, 3557, 3553, 3557, 3557, 2572, 2569, 2569, 2569, 2572, 6191, 6188, 6189, 6189, 6190, 4172, 4174, 4174, 4172, 4170, 5597, 5596, 5598, 5597, 5598, 9010, 9011, 9013, 9013, 9009, 9012, 5407, 5413, 5408, 5406, 5406, 5406, 5713, 5711, 5713, 5712, 6142, 6142, 6140, 6144, 5549, 5543, 5419, 5420, 7092, 7089, 7086, 7089, 6252, 6256, 6257, 6251, 2699, 2698, 5691, 5691, 2859, 2858, 2860, 2861, 4917, 4921, 4923, 4918, 1770, 1772, 6205, 6206, 5200, 5199, 3112, 3108, 2603, 2597, 2599, 2598, 4933, 4931, 4929, 4928, 3285, 3292, 3289, 3291, 3290, 3287, 3996, 4002, 8335, 8340, 6619, 6614, 2819, 2822, 2816, 2817, 2819, 2478, 2472, 2470, 2471, 2466, 4815, 4824, 4822, 4821, 4819, 7170, 7168, 7169, 7171, 7170, 7169, 7170, 7171, 5122, 5120, 5120, 5123, 5123, 5123, 2853, 2854, 2853, 13450, 13449, 13449, 2814, 2824, 2818, 5580, 5579, 5578, 5929, 5933, 5949, 5880, 5881, 5886, 5572, 5574, 5575, 3336, 3336, 3333, 3336, 3339, 3336, 3336, 3336, 3333, 3337, 8766, 8769, 8764, 8766, 5958, 5979, 5958, 5957, 6918, 6924, 6924, 6920, 7068, 7063, 7064, 7064, 4862, 4860, 4859, 4860, 5358, 5358, 5360, 5360, 5284, 5268, 5270, 5271, 3054, 3047, 3051, 3052, 3045, 7561, 7574, 7568, 7567, 7564, 3948, 3943, 3947, 3943, 3943, 2973, 2975, 2974, 2981, 2973, 2979, 2783, 2783, 2779, 5075, 5079, 5070, 5083, 5071, 7581, 7580, 7576, 7584, 7581, 7579, 7581, 3112, 3109, 3108, 3108, 3108, 3077, 3075, 4773, 4772, 4770, 2703, 3717, 3721, 3723, 3723, 6314, 6311, 6311, 1775, 1771, 1773, 1774, 8750, 8754, 8756, 8746, 6554, 6558, 6560, 6557, 6401, 6398, 6399, 6403, 6226, 6222, 6220, 6222, 6224, 6221, 6222, 5838, 5844, 6234, 6231, 6231, 6382, 6382, 6385, 2205, 2208, 2204, 5028, 5024, 5023, 3681, 3681, 3678, 5719, 5722, 5721, 5722, 5720, 3376, 3371, 3361, 3356, 3016, 3013, 3014, 3014, 6692, 6698, 6695, 6693, 6693, 3209, 3223, 3700, 5471, 5471, 5471, 5476, 5473, 5254, 5255, 5225, 5226, 5225, 5224, 5224, 4233, 4237, 5952, 5952, 5951, 5949, 1684, 1684, 1681, 1682, 1686, 2975, 2973, 2976, 2975, 2535, 2534, 2532, 2534, 928, 923, 948, 929, 2386, 2382, 2388, 4987, 4984, 4983, 4985, 6879, 6884, 6880, 6881, 6877, 6877, 6880, 6879, 2558, 2556, 2563, 2183, 2181, 2181, 9704, 9707, 9699, 9704, 2234, 2258, 2254, 5560, 5560, 5575, 5564, 2608, 2604, 2603, 2604, 2605, 5704, 4044, 4038, 4035, 6779, 6766, 6766, 5841, 5840, 5841, 5575, 5572, 4692, 4694, 4696, 4693, 4696, 4700, 4700, 4700, 2548, 2548, 2548, 2552, 2551, 2549, 2546, 2545, 6862, 6866, 6871, 6864, 9929, 4639, 4643, 4642, 3431, 3429, 2752, 2756, 2759, 3365, 3364, 3369, 3364, 3364, 6938, 6943, 6941, 6946, 6950, 2610, 2612, 3340, 5471, 5471, 5473, 5476, 3291, 3296, 3297, 5973, 5970, 5970, 5969, 5971, 14168, 3347, 3347, 3096, 3093, 3100, 3102, 8357, 8354, 8360, 2799, 2800, 2804, 2801, 2800, 3020, 3024, 3017, 3310, 3308, 3308, 3707, 3707, 3703, 3702, 3705, 3703, 7470, 2723, 2724, 4837, 4838, 4840, 4839, 4839, 4839, 4526, 4527, 4526, 4525, 16384, 10069, 10070, 7411, 7420, 7412, 4638, 4638, 4644, 4421, 4415, 4417, 4416, 3425, 3422, 3426, 3423, 2247, 2242, 2244, 4973, 4964, 4970, 7050, 7050, 7057, 8247, 8244, 8236, 8239, 2632, 2629, 2633, 6967, 6968, 6967, 6971, 5029, 5031, 5030, 5034, 2770, 2769, 2763, 2765, 2783, 6005, 6006, 6008, 6005, 7366, 7360, 7361, 4916, 4915, 4914, 4917, 1401, 1422, 1398, 1405, 1404, 1399, 1403, 2565, 4880, 4879, 4878, 5056, 5053, 5059, 5055, 5055, 5055, 1057, 1059, 5954, 5959, 5954, 5956, 5503, 5501, 3995, 3998, 3987, 3990, 6485, 6476, 6476, 6481, 6343, 6340, 6344, 2536, 2937, 2939, 2941, 2938, 2940, 992, 993, 6614, 6615, 6615, 3348, 4479, 4479, 4482, 4481, 4486, 4481, 4482, 2845, 2843, 1390, 1389, 1393, 1398, 8632, 8626, 6202, 6205, 6200, 5081, 5085, 5081, 5082, 8441, 8439, 10067, 10051, 4189, 4179, 4176, 4181, 5106, 5093, 5101, 5093, 2917, 2920, 4627, 4629, 4631, 3333, 3332, 3335, 4089, 4086, 5323, 5330, 5323, 5324, 4734, 4732, 4732, 4700, 4705, 4065, 4068, 6630, 6628, 6624, 6626, 4687, 4681, 4681, 4681, 2247, 2254, 2252, 3083, 3083, 3085, 3083, 3089, 3085, 6165, 6169, 8331, 8336, 8329, 4388, 4389, 4398, 4394, 4387, 5780, 5780, 5784, 8566, 8565, 8569, 8568, 1127, 2902, 2906, 2906, 2901, 9027, 9025, 9029, 2142, 2141, 2142, 1924, 1925, 1924, 5633, 5629, 5632, 5344, 5343, 8741, 8746, 8746, 6040, 6045, 6038, 1303, 1302, 1302, 1301, 4192, 4207, 4198, 4202, 3193, 3195, 3191, 3190, 3191, 3189, 3191, 3191, 3189, 4008, 4009, 4291, 4285, 4291, 4289, 2603, 2606, 2606, 2602, 2604, 4724, 4722, 4723, 4723, 2524, 2529, 5882, 5880, 5883, 5881, 5880, 5879, 3867, 3859, 6677, 6674, 6678, 6677, 6681, 7845, 7842, 5504, 5499, 5654, 5650, 4914, 4916, 3199, 3197, 3200, 3200, 3197, 2928, 2927, 2926, 5112, 5113, 5110, 5115, 6886, 6891, 6885, 6895, 6891, 2794, 2796, 2796, 1483, 1486, 4629, 4628, 4628, 3537, 3531, 6720, 6724, 6718, 6491, 6489, 6487, 2942, 2948, 3826, 3827, 3877, 3878, 15066, 15064, 15064, 9732, 9746, 9735, 5568, 5565, 5568, 5567, 5576, 1437, 1436, 1438, 1438, 1438, 5750, 5747, 5750, 5750, 5748, 3338, 3339, 11847, 11853, 11857, 11847, 2241, 2238, 2246, 3751, 3758, 3757, 2891, 2891, 2890, 16384, 9942, 1548, 4793, 4793, 4789, 4790, 1767, 1767, 1770, 3794, 3795, 13007, 13014, 13005, 13009, 3176, 3179, 3185, 3178, 3178, 3178, 5356, 5355, 5355, 6301, 6306, 4021, 4023, 4023, 4029, 4024, 4567, 4566, 8079, 8077, 8078, 8080, 2661, 2660, 1454, 7845, 7828, 8313, 8317, 8312, 8317, 5162, 5165, 5159, 5161, 7341, 7343, 7338, 7344, 5199, 5196, 5198, 5196, 4082, 4085, 4081, 4081, 3258, 3263, 3257, 7372, 4943, 4938, 4946, 4944, 2477, 2479, 9025, 9025, 9024, 5528, 5529, 5530, 7757, 7737, 7739, 7734, 7736 ], "xaxis": "x", "yaxis": "y" } ], "layout": { "barmode": "relative", "legend": { "title": { "text": "variable" }, "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Histogram of question + context token lengths (total=1451)" }, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "value" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "count" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# plot histogram of full_text lengths\n", "question_token_lengths = []\n", "for inst in instances:\n", " question_token_lengths.append(len(inst['question_with_context']))\n", " \n", "px.histogram(question_token_lengths, \n", " title=f'Histogram of question + context token lengths (total={len(question_token_lengths)})')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Save instances to JSON" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# recursively check the type of each field in the dataset\n", "def check_type(data, level=0):\n", " tabs = '\\t' * level\n", " if isinstance(data, dict):\n", " for key, value in data.items():\n", " print(f'{tabs}{key}: {type(value)}')\n", " check_type(value, level + 1)\n", " elif isinstance(data, list):\n", " for i in data:\n", " check_type(i, level + 1)\n", " else:\n", " pass\n", " # print(f'{tabs}{type(data)}')\n", " # if isinstance(data, BatchEncoding):\n", " # print(f'{tabs}{data[:100]}')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "question_with_context: \n", "paragraph_indices: \n", "evidence: \n", "answer: \n", "metadata: \n", "\tquestion: \n", "\tquestion_tokens: \n", "\tparagraphs: \n", "\tcontext_tokens: \n", "\tquestion_id: \n", "\tarticle_id: \n", "\tall_answers: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\t\t\ttext: \n", "\t\t\ttype: \n", "\tall_evidence: \n", "\tall_evidence_masks: \n" ] } ], "source": [ "check_type(instances[0])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# save instances to file\n", "with open(os.path.join(output_path, f'{split}_instances.json'), 'w') as f:\n", " # pretty print json\n", " json.dump(instances, f, indent=4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "arxiv-agent", "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.12.0" } }, "nbformat": 4, "nbformat_minor": 2 }