{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# download path\n", "# https://huggingface.co/datasets/din0s/asqa" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "SEED = 2024\n", "# SAMPLE_NUM = 500\n", "CACHE_DIR = r\"/share/ninglu_shao/data/dataset\"\n", "OUTPUT_PATH = r\"/share/ninglu_shao/data/Citation/asqa.jsonl\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/share/ninglu_shao/envs/snl/lib/python3.10/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 os\n", "os.environ[\"https_proxy\"] = \"http://127.0.0.1:15777\"\n", "os.environ[\"http_proxy\"] = \"http://127.0.0.1:15777\"\n", "\n", "import datasets" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Found cached dataset parquet (/share/ninglu_shao/data/dataset/din0s___parquet/din0s--asqa-e1511a96e1e7140e/0.0.0/14a00e99c0d15a23649d0db8944380ac81082d4b021f398733dd84f3a6c569a7)\n", "100%|██████████| 2/2 [00:00<00:00, 90.93it/s]\n" ] }, { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['ambiguous_question', 'qa_pairs', 'wikipages', 'annotations', 'sample_id'],\n", " num_rows: 4353\n", " })\n", " dev: Dataset({\n", " features: ['ambiguous_question', 'qa_pairs', 'wikipages', 'annotations', 'sample_id'],\n", " num_rows: 948\n", " })\n", "})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset = datasets.load_dataset(\"din0s/asqa\", cache_dir=CACHE_DIR)\n", "\n", "dataset" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"/share/ninglu_shao/code/ALCE/data/asqa_eval_dpr_top100.json\", \"r\") as f:\n", " tmp_data = json.load(f)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "data = []\n", "\n", "for d in dataset[\"dev\"]:\n", " data.append({\n", " \"question\": d[\"ambiguous_question\"],\n", " \"answers\": [x[\"long_answer\"] for x in d[\"annotations\"]],\n", " })" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import jsonlines\n", "\n", "with jsonlines.open(OUTPUT_PATH, \"w\") as f:\n", " f.write_all(data)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"/share/ninglu_shao/code/ALCE/data/asqa_eval_dpr_top100.json\", \"r\") as f:\n", " tmp_data = json.load(f)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import jsonlines\n", "\n", "with jsonlines.open(\"/share/ninglu_shao/code/Citation/data/output/asqa.jsonl\", \"r\") as f:\n", " my_data = list(f.iter())" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'doc_id': 3262915,\n", " 'score': 77.37831115722656,\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"FIFA World Rankings The FIFA World Ranking is a ranking system for men's national teams in association football, currently led by Belgium. The teams of the member nations of FIFA, football's world governing body, are ranked based on their game results with the most successful teams being ranked highest. The rankings were introduced in December 1992, and eight teams (Argentina, Belgium, Brazil, France, Germany, Italy, the Netherlands and Spain) have held the top position, of which Brazil have spent the longest ranked first. A points system is used, with points being awarded based on the results of all FIFA-recognised full\"},\n", " {'doc_id': 3262933,\n", " 'score': 76.84109497070312,\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"based on the importance of the match and the strength of the opponent. A win over a weak opponent resulted in fewer points being awarded than a win over a much stronger one. Further adaptations in 2006 were made to reduce the number of years' results considered from 8 to 4, with greater reliance on matches from within the previous 12 months. Still, criticisms of the rankings remained, with particular anomalies being noted including: the United States rise to fourth in 2006, to the surprise of even their own players; Israel's climb to 15th in November 2008, which surprised the\"},\n", " {'doc_id': 3262941,\n", " 'score': 76.24816131591797,\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"The 19 July 2018 release was cancelled following the new calculation method implementation. FIFA World Rankings The FIFA World Ranking is a ranking system for men's national teams in association football, currently led by Belgium. The teams of the member nations of FIFA, football's world governing body, are ranked based on their game results with the most successful teams being ranked highest. The rankings were introduced in December 1992, and eight teams (Argentina, Belgium, Brazil, France, Germany, Italy, the Netherlands and Spain) have held the top position, of which Brazil have spent the longest ranked first. A points system is\"},\n", " {'doc_id': 20809878,\n", " 'score': 75.57286834716797,\n", " 'title': 'World Football Elo Ratings',\n", " 'text': \"Ukraine 26 years, and for Montenegro 11 years. For Croatia and Slovakia the average is dominated by the single rating during the 50 years between the few games played between 1940 and 1943 and the rebirth of the countries in the 1990s. Likewise, South Africa's average is mostly determined by the 44 matches (of a 417 total in 2018) played in the 86 years before it rejoined FIFA in 1992. This table is a list of the national teams with the highest average Elo score over approximately the last half century, from 1 January 1970 to 1 January 2018. Before\"},\n", " {'doc_id': 3262929,\n", " 'score': 75.47522735595703,\n", " 'title': 'FIFA World Rankings',\n", " 'text': '2017, Brazil returned to the No. 1 spot for the first time since just prior to the 2010 World Cup, but Germany regained the top spot in July after winning the Confederations Cup. In August 2018, France became the leader in the FIFA rankings again after nearly 16 years, having won the 2018 FIFA World Cup, and this is also the first time FIFA adopted the Elo rating system to the ranking system. One month later, for the first time two teams were tied at the top spot as Belgium returned to the number one spot with the same ranking'}]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_data[0][\"doc_list\"]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': 'wiki:3262915',\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"FIFA World Rankings The FIFA World Ranking is a ranking system for men's national teams in association football, currently led by Belgium. The teams of the member nations of FIFA, football's world governing body, are ranked based on their game results with the most successful teams being ranked highest. The rankings were introduced in December 1992, and eight teams (Argentina, Belgium, Brazil, France, Germany, Italy, the Netherlands and Spain) have held the top position, of which Brazil have spent the longest ranked first. A points system is used, with points being awarded based on the results of all FIFA-recognised full\",\n", " 'score': '76.65874',\n", " 'has_answer': False},\n", " {'id': 'wiki:3262933',\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"based on the importance of the match and the strength of the opponent. A win over a weak opponent resulted in fewer points being awarded than a win over a much stronger one. Further adaptations in 2006 were made to reduce the number of years' results considered from 8 to 4, with greater reliance on matches from within the previous 12 months. Still, criticisms of the rankings remained, with particular anomalies being noted including: the United States rise to fourth in 2006, to the surprise of even their own players; Israel's climb to 15th in November 2008, which surprised the\",\n", " 'score': '75.95405',\n", " 'has_answer': False},\n", " {'id': 'wiki:3262941',\n", " 'title': 'FIFA World Rankings',\n", " 'text': \"The 19 July 2018 release was cancelled following the new calculation method implementation. FIFA World Rankings The FIFA World Ranking is a ranking system for men's national teams in association football, currently led by Belgium. The teams of the member nations of FIFA, football's world governing body, are ranked based on their game results with the most successful teams being ranked highest. The rankings were introduced in December 1992, and eight teams (Argentina, Belgium, Brazil, France, Germany, Italy, the Netherlands and Spain) have held the top position, of which Brazil have spent the longest ranked first. A points system is\",\n", " 'score': '75.65221',\n", " 'has_answer': False},\n", " {'id': 'wiki:20809878',\n", " 'title': 'World Football Elo Ratings',\n", " 'text': \"Ukraine 26 years, and for Montenegro 11 years. For Croatia and Slovakia the average is dominated by the single rating during the 50 years between the few games played between 1940 and 1943 and the rebirth of the countries in the 1990s. Likewise, South Africa's average is mostly determined by the 44 matches (of a 417 total in 2018) played in the 86 years before it rejoined FIFA in 1992. This table is a list of the national teams with the highest average Elo score over approximately the last half century, from 1 January 1970 to 1 January 2018. Before\",\n", " 'score': '75.10149',\n", " 'has_answer': False},\n", " {'id': 'wiki:20805343',\n", " 'title': 'FIFA World Ranking system (2006–2018)',\n", " 'text': \"match status multipliers are as follows: A win against a very highly ranked opponent is a considerably greater achievement than a win against a low-rated opponent, thus the strength of the opposing team is an important factor. The new system uses an opposition strength factor based on team rankings. The previous system was based on points difference. The formula used is: with the exceptions that the team ranked #1 is given a multiplier of 2, and teams ranked 150th and below are assigned the minimum multiplier of 0.5. The ranking position is taken from the opposition's ranking in the most\",\n", " 'score': '75.08292',\n", " 'has_answer': False},\n", " {'id': 'wiki:3262929',\n", " 'title': 'FIFA World Rankings',\n", " 'text': '2017, Brazil returned to the No. 1 spot for the first time since just prior to the 2010 World Cup, but Germany regained the top spot in July after winning the Confederations Cup. In August 2018, France became the leader in the FIFA rankings again after nearly 16 years, having won the 2018 FIFA World Cup, and this is also the first time FIFA adopted the Elo rating system to the ranking system. One month later, for the first time two teams were tied at the top spot as Belgium returned to the number one spot with the same ranking',\n", " 'score': '74.90401',\n", " 'has_answer': False}]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tmp_data[0][\"docs\"][:6]" ] }, { "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.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }