{ "metadata": { "kernelspec": { "language": "python", "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.12", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" }, "kaggle": { "accelerator": "none", "dataSources": [], "dockerImageVersionId": 30918, "isInternetEnabled": true, "language": "python", "sourceType": "notebook", "isGpuEnabled": false }, "colab": { "name": "“20250406.msmarco处理", "provenance": [] } }, "nbformat_minor": 0, "nbformat": 4, "cells": [ { "cell_type": "code", "source": [ "import pandas as pd\n", "\n", "df_corpus = pd.read_json(\"hf://datasets/mteb/msmarco/corpus.jsonl\", lines=True)\n", "\n", "df_queries = pd.read_json(\"hf://datasets/mteb/msmarco/queries.jsonl\", lines=True)\n", "\n", "splits = {'train': 'qrels/train.jsonl', 'dev': 'qrels/dev.jsonl', 'test': 'qrels/test.jsonl'}\n", "df_qrels_train = pd.read_json(\"hf://datasets/mteb/msmarco/\" + splits[\"train\"], lines=True)\n", "df_qrels_dev = pd.read_json(\"hf://datasets/mteb/msmarco/\" + splits[\"dev\"], lines=True)\n", "df_qrels_test = pd.read_json(\"hf://datasets/mteb/msmarco/\" + splits[\"test\"], lines=True)" ], "metadata": { "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:21:38.449921Z", "iopub.execute_input": "2025-04-06T09:21:38.450179Z", "iopub.status.idle": "2025-04-06T09:22:42.947898Z", "shell.execute_reply.started": "2025-04-06T09:21:38.450152Z", "shell.execute_reply": "2025-04-06T09:22:42.946353Z" }, "id": "DVah_FHJgb-v" }, "outputs": [], "execution_count": null }, { "cell_type": "code", "source": [ "df_corpus" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:22:52.63252Z", "iopub.execute_input": "2025-04-06T09:22:52.633017Z", "iopub.status.idle": "2025-04-06T09:22:52.661247Z", "shell.execute_reply.started": "2025-04-06T09:22:52.632863Z", "shell.execute_reply": "2025-04-06T09:22:52.660038Z" }, "id": "-gGXexjkgb-w", "outputId": "c7b7a345-be86-4233-d263-376384c55c94" }, "outputs": [ { "execution_count": 2, "output_type": "execute_result", "data": { "text/plain": " _id title text\n0 0 The presence of communication amid scientific ...\n1 1 The Manhattan Project and its atomic bomb help...\n2 2 Essay on The Manhattan Project - The Manhattan...\n3 3 The Manhattan Project was the name for a proje...\n4 4 versions of each volume as well as complementa...\n... ... ... ...\n8841818 8841818 When metal salts emit short wavelengths of vis...\n8841819 8841819 Thousands of people across the United States w...\n8841820 8841820 The recipe that creates blue, for example, inc...\n8841821 8841821 On Independence Days of yore, old-timey crowds...\n8841822 8841822 View full size image. Behind the scenes of the...\n\n[8841823 rows x 3 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
_idtitletext
00The presence of communication amid scientific ...
11The Manhattan Project and its atomic bomb help...
22Essay on The Manhattan Project - The Manhattan...
33The Manhattan Project was the name for a proje...
44versions of each volume as well as complementa...
............
88418188841818When metal salts emit short wavelengths of vis...
88418198841819Thousands of people across the United States w...
88418208841820The recipe that creates blue, for example, inc...
88418218841821On Independence Days of yore, old-timey crowds...
88418228841822View full size image. Behind the scenes of the...
\n

8841823 rows × 3 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_queries" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:23:07.314817Z", "iopub.execute_input": "2025-04-06T09:23:07.315257Z", "iopub.status.idle": "2025-04-06T09:23:07.329863Z", "shell.execute_reply.started": "2025-04-06T09:23:07.315222Z", "shell.execute_reply": "2025-04-06T09:23:07.328637Z" }, "id": "Gqy5Y2ezgb-x", "outputId": "a06e1003-5b30-4cef-eaaa-ad688f5793f4" }, "outputs": [ { "execution_count": 3, "output_type": "execute_result", "data": { "text/plain": " _id text\n0 1185869 )what was the immediate impact of the success ...\n1 1185868 _________ justice is designed to repair the ha...\n2 597651 what color is amber urine\n3 403613 is autoimmune hepatitis a bile acid synthesis ...\n4 1183785 elegxo meaning\n... ... ...\n509957 147073 difference between discrete and process manufa...\n509958 243761 how long did abraham lincoln serve\n509959 162662 does adult acne rosacea give you blepharitis\n509960 247194 how long do you bake muffins\n509961 195199 glioma meaning\n\n[509962 rows x 2 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
_idtext
01185869)what was the immediate impact of the success ...
11185868_________ justice is designed to repair the ha...
2597651what color is amber urine
3403613is autoimmune hepatitis a bile acid synthesis ...
41183785elegxo meaning
.........
509957147073difference between discrete and process manufa...
509958243761how long did abraham lincoln serve
509959162662does adult acne rosacea give you blepharitis
509960247194how long do you bake muffins
509961195199glioma meaning
\n

509962 rows × 2 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_qrels_train" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:23:40.361043Z", "iopub.execute_input": "2025-04-06T09:23:40.361369Z", "iopub.status.idle": "2025-04-06T09:23:40.373621Z", "shell.execute_reply.started": "2025-04-06T09:23:40.361342Z", "shell.execute_reply": "2025-04-06T09:23:40.372723Z" }, "id": "yo8pouAegb-x", "outputId": "2e7d0732-f66b-4690-fddb-2cd721bc4dab" }, "outputs": [ { "execution_count": 5, "output_type": "execute_result", "data": { "text/plain": " query-id corpus-id score\n0 1185869 0 1\n1 1185868 16 1\n2 597651 49 1\n3 403613 60 1\n4 1183785 389 1\n... ... ... ...\n532746 19285 8841362 1\n532747 558837 4989159 1\n532748 559149 8841547 1\n532749 706678 8841643 1\n532750 405466 8841735 1\n\n[532751 rows x 3 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
query-idcorpus-idscore
0118586901
11185868161
2597651491
3403613601
411837853891
............
5327461928588413621
53274755883749891591
53274855914988415471
53274970667888416431
53275040546688417351
\n

532751 rows × 3 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_qrels_dev" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:23:50.855651Z", "iopub.execute_input": "2025-04-06T09:23:50.856029Z", "iopub.status.idle": "2025-04-06T09:23:50.867014Z", "shell.execute_reply.started": "2025-04-06T09:23:50.855996Z", "shell.execute_reply": "2025-04-06T09:23:50.866073Z" }, "id": "OM_oEoFCgb-x", "outputId": "a2c303be-ca2f-4d13-a4ca-8bbd3ed83d71" }, "outputs": [ { "execution_count": 6, "output_type": "execute_result", "data": { "text/plain": " query-id corpus-id score\n0 300674 7067032 1\n1 125705 7067056 1\n2 94798 7067181 1\n3 9083 7067274 1\n4 174249 7067348 1\n... ... ... ...\n7432 147073 8008770 1\n7433 243761 8008787 1\n7434 162662 8008977 1\n7435 247194 8009319 1\n7436 195199 8009377 1\n\n[7437 rows x 3 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
query-idcorpus-idscore
030067470670321
112570570670561
29479870671811
3908370672741
417424970673481
............
743214707380087701
743324376180087871
743416266280089771
743524719480093191
743619519980093771
\n

7437 rows × 3 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_qrels_test" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:23:59.489691Z", "iopub.execute_input": "2025-04-06T09:23:59.490182Z", "iopub.status.idle": "2025-04-06T09:23:59.503658Z", "shell.execute_reply.started": "2025-04-06T09:23:59.490139Z", "shell.execute_reply": "2025-04-06T09:23:59.502273Z" }, "id": "mLhpMdt_gb-x", "outputId": "9ef08f2b-b832-4c71-ca8c-685f92092772" }, "outputs": [ { "execution_count": 7, "output_type": "execute_result", "data": { "text/plain": " query-id corpus-id score\n0 19335 1017759 0\n1 19335 1082489 0\n2 19335 109063 0\n3 19335 1160863 0\n4 19335 1160871 0\n... ... ... ...\n9255 1133167 8839920 2\n9256 1133167 8839922 2\n9257 1133167 944810 0\n9258 1133167 949411 0\n9259 1133167 977421 0\n\n[9260 rows x 3 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
query-idcorpus-idscore
01933510177590
11933510824890
2193351090630
31933511608630
41933511608710
............
9255113316788399202
9256113316788399222
925711331679448100
925811331679494110
925911331679774210
\n

9260 rows × 3 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_qrels_train['query-id'].value_counts()" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:27:02.375382Z", "iopub.execute_input": "2025-04-06T09:27:02.375802Z", "iopub.status.idle": "2025-04-06T09:27:02.472982Z", "shell.execute_reply.started": "2025-04-06T09:27:02.375765Z", "shell.execute_reply": "2025-04-06T09:27:02.471956Z" }, "id": "ZzPvmtlZgb-y", "outputId": "0a7543b8-5619-4cbc-ba38-270b6d2567de" }, "outputs": [ { "execution_count": 8, "output_type": "execute_result", "data": { "text/plain": "query-id\n574458 7\n913949 7\n199730 7\n49751 7\n47866 7\n ..\n384305 1\n979676 1\n1042805 1\n948363 1\n405466 1\nName: count, Length: 502939, dtype: int64" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_corpus_rn = df_corpus[['_id', 'text']].rename(columns={\"_id\": \"corpus-id\",\"text\": \"corpus\"})\n", "print(df_corpus_rn)\n", "df_queries_rn = df_queries[['_id', 'text']].rename(columns={\"_id\": \"query-id\",\"text\": \"query\"})\n", "print(df_queries_rn)\n" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:30:25.893358Z", "iopub.execute_input": "2025-04-06T09:30:25.893793Z", "iopub.status.idle": "2025-04-06T09:30:26.828416Z", "shell.execute_reply.started": "2025-04-06T09:30:25.893715Z", "shell.execute_reply": "2025-04-06T09:30:26.82703Z" }, "id": "gVdV-v4sgb-y", "outputId": "70059fab-b036-470b-a738-069ba611d15e" }, "outputs": [ { "name": "stdout", "text": " corpus-id corpus\n0 0 The presence of communication amid scientific ...\n1 1 The Manhattan Project and its atomic bomb help...\n2 2 Essay on The Manhattan Project - The Manhattan...\n3 3 The Manhattan Project was the name for a proje...\n4 4 versions of each volume as well as complementa...\n... ... ...\n8841818 8841818 When metal salts emit short wavelengths of vis...\n8841819 8841819 Thousands of people across the United States w...\n8841820 8841820 The recipe that creates blue, for example, inc...\n8841821 8841821 On Independence Days of yore, old-timey crowds...\n8841822 8841822 View full size image. Behind the scenes of the...\n\n[8841823 rows x 2 columns]\n query-id query\n0 1185869 )what was the immediate impact of the success ...\n1 1185868 _________ justice is designed to repair the ha...\n2 597651 what color is amber urine\n3 403613 is autoimmune hepatitis a bile acid synthesis ...\n4 1183785 elegxo meaning\n... ... ...\n509957 147073 difference between discrete and process manufa...\n509958 243761 how long did abraham lincoln serve\n509959 162662 does adult acne rosacea give you blepharitis\n509960 247194 how long do you bake muffins\n509961 195199 glioma meaning\n\n[509962 rows x 2 columns]\n", "output_type": "stream" } ], "execution_count": null }, { "cell_type": "code", "source": [ "df_qrels_train_final = df_qrels_train.merge(df_corpus_rn, on='corpus-id', how=\"left\").merge(df_queries_rn, on='query-id', how=\"left\")\n", "print(df_qrels_train_final)\n", "print()\n", "df_qrels_dev_final = df_qrels_dev.merge(df_corpus_rn, on='corpus-id', how=\"left\").merge(df_queries_rn, on='query-id', how=\"left\")\n", "print(df_qrels_dev_final)\n", "print()\n", "df_qrels_test_final = df_qrels_test.merge(df_corpus_rn, on='corpus-id', how=\"left\").merge(df_queries_rn, on='query-id', how=\"left\")\n", "print(df_qrels_test_final)" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:33:28.433846Z", "iopub.execute_input": "2025-04-06T09:33:28.434207Z", "iopub.status.idle": "2025-04-06T09:33:33.572173Z", "shell.execute_reply.started": "2025-04-06T09:33:28.43418Z", "shell.execute_reply": "2025-04-06T09:33:33.570969Z" }, "id": "YKw-nZ2tgb-y", "outputId": "d78d3cb6-652f-49a3-d970-99541d082756" }, "outputs": [ { "name": "stdout", "text": " query-id corpus-id score \\\n0 1185869 0 1 \n1 1185868 16 1 \n2 597651 49 1 \n3 403613 60 1 \n4 1183785 389 1 \n... ... ... ... \n532746 19285 8841362 1 \n532747 558837 4989159 1 \n532748 559149 8841547 1 \n532749 706678 8841643 1 \n532750 405466 8841735 1 \n\n corpus \\\n0 The presence of communication amid scientific ... \n1 The approach is based on a theory of justice t... \n2 Color—urine can be a variety of colors, most... \n3 Inborn errors of bile acid synthesis can produ... \n4 The word convict here (elegcw /elegxo) means t... \n... ... \n532746 What is Anterolisthesis? Anterolisthesis is de... \n532747 Fly fishing in a river. Fly fishing is an angl... \n532748 FSH and LH levels in perimenopause are often f... \n532749 Yowie is one of several names given to a homin... \n532750 Carbonic acid is unstable and decomposes to CO... \n\n query \n0 )what was the immediate impact of the success ... \n1 _________ justice is designed to repair the ha... \n2 what color is amber urine \n3 is autoimmune hepatitis a bile acid synthesis ... \n4 elegxo meaning \n... ... \n532746 anterolisthesis definition \n532747 what are fishing flies \n532748 what are fsh levels during perimenopause \n532749 what is a yowie \n532750 is carbonic acid soluble \n\n[532751 rows x 5 columns]\n\n query-id corpus-id score \\\n0 300674 7067032 1 \n1 125705 7067056 1 \n2 94798 7067181 1 \n3 9083 7067274 1 \n4 174249 7067348 1 \n... ... ... ... \n7432 147073 8008770 1 \n7433 243761 8008787 1 \n7434 162662 8008977 1 \n7435 247194 8009319 1 \n7436 195199 8009377 1 \n\n corpus \\\n0 http://en.wikipedia.org/wiki/William_Bradford_... \n1 Adjective[edit] preventive ‎(comparative mor... \n2 Photoshop: color overlay. In my sunlight touch... \n3 TRUE. Hippocrates is considered the father of ... \n4 How to create a PaySlip using a printer: 1 Lo... \n... ... \n7432 Process Manufacturing involves Variable Ingred... \n7433 Abraham Lincoln served as president from March... \n7434 Rosacea is a facial skin condition that can ca... \n7435 1 Bake at 425F degrees for 5 minutes. 2 Reduc... \n7436 Webster Dictionary (0.00 / 0 votes) Rate this ... \n\n query \n0 how many years did william bradford serve as g... \n1 define preventive \n2 color overlay photoshop \n3 ____________________ is considered the father ... \n4 does xpress bet charge to deposit money in you... \n... ... \n7432 difference between discrete and process manufa... \n7433 how long did abraham lincoln serve \n7434 does adult acne rosacea give you blepharitis \n7435 how long do you bake muffins \n7436 glioma meaning \n\n[7437 rows x 5 columns]\n\n query-id corpus-id score \\\n0 19335 1017759 0 \n1 19335 1082489 0 \n2 19335 109063 0 \n3 19335 1160863 0 \n4 19335 1160871 0 \n... ... ... ... \n9255 1133167 8839920 2 \n9256 1133167 8839922 2 \n9257 1133167 944810 0 \n9258 1133167 949411 0 \n9259 1133167 977421 0 \n\n corpus \\\n0 Man and environment reciprocal relationship. T... \n1 Ethnographic research is a qualitative method ... \n2 1. Identify the fields of anthropology and maj... \n3 Human impact on the environment. Human impact ... \n4 Human impact on the environment. Human impact ... \n... ... \n9255 Weather In Ocho Rios Jamaica - Spring (March, ... \n9256 What's the best time to travel to Ocho Rios in... \n9257 Cairo Yearly Weather Summary. Cairo has an ari... \n9258 The average high temperature reaches 90 degree... \n9259 More trip calculations. 1 flight time from Mi... \n\n query \n0 anthropological definition of environment \n1 anthropological definition of environment \n2 anthropological definition of environment \n3 anthropological definition of environment \n4 anthropological definition of environment \n... ... \n9255 how is the weather in jamaica \n9256 how is the weather in jamaica \n9257 how is the weather in jamaica \n9258 how is the weather in jamaica \n9259 how is the weather in jamaica \n\n[9260 rows x 5 columns]\n", "output_type": "stream" } ], "execution_count": null }, { "cell_type": "markdown", "source": [ "## 数据集处理\n", "query作为cond\n", "corpus作为group\n", "只处理train和dev,test先不管" ], "metadata": { "id": "UpHjFx16gb-y" } }, { "cell_type": "code", "source": [ "def handle(row):\n", " # query_id = row[0]\n", " cond = row[1]['query'].tolist()[0]\n", " group = row[1]['corpus'].tolist()\n", " return (cond, group)\n" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:37:11.62826Z", "iopub.execute_input": "2025-04-06T09:37:11.628583Z", "iopub.status.idle": "2025-04-06T09:37:11.633852Z", "shell.execute_reply.started": "2025-04-06T09:37:11.628556Z", "shell.execute_reply": "2025-04-06T09:37:11.632279Z" }, "id": "iEiQcfzUgb-z" }, "outputs": [], "execution_count": null }, { "cell_type": "markdown", "source": [ "### train" ], "metadata": { "id": "71O78ERCgb-z" } }, { "cell_type": "code", "source": [ "name_group_list_train = [(name[0], group) for name, group in df_qrels_train_final.groupby(['query-id'])]\n", "print(len(name_group_list_train))\n", "print(len(name_group_list_train[0][1]))\n", "print(name_group_list_train[1][1])\n", "print(len(name_group_list_train[1][1]))\n", "\n", "print(\"过滤后\")\n", "name_group_list_train_filter = list(filter(lambda _: len(_[1]) > 1, name_group_list_train))\n", "print(len(name_group_list_train_filter))\n", "print(len(name_group_list_train_filter[0][1]))\n", "print(name_group_list_train_filter[1][1])\n", "print(len(name_group_list_train_filter[1][1]))" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:38:51.057346Z", "iopub.execute_input": "2025-04-06T09:38:51.057702Z", "iopub.status.idle": "2025-04-06T09:39:15.549519Z", "shell.execute_reply.started": "2025-04-06T09:38:51.05767Z", "shell.execute_reply": "2025-04-06T09:39:15.54838Z" }, "id": "PpyOvz7xgb-0", "outputId": "46b0f70b-0e13-4a26-96a4-86a8bd14ae3c" }, "outputs": [ { "name": "stdout", "text": "502939\n1\n query-id corpus-id score \\\n395137 4 5613529 1 \n\n corpus \\\n395137 The formation of AA – Alcoholics Anonymous â... \n\n query \n395137 Defining alcoholism as a disease is associate... \n1\n过滤后\n25352\n2\n query-id corpus-id score \\\n280941 374 4086051 1 \n280942 374 4086052 1 \n280943 374 4086057 1 \n\n corpus \\\n280941 Quick Answer. The Internet was created essenti... \n280942 2003-06-30: the World Wide Web was invented by... \n280943 Tim Berners-Lee. The first web browser - or br... \n\n query \n280941 . what is the world wide web, when was it crea... \n280942 . what is the world wide web, when was it crea... \n280943 . what is the world wide web, when was it crea... \n3\n", "output_type": "stream" } ], "execution_count": null }, { "cell_type": "code", "source": [ "result_train = list(map(handle, name_group_list_train_filter))\n", "result_train_df = pd.DataFrame(result_train, columns=['condition', 'group'])\n", "result_train_df" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:40:31.639048Z", "iopub.execute_input": "2025-04-06T09:40:31.639405Z", "iopub.status.idle": "2025-04-06T09:40:33.318217Z", "shell.execute_reply.started": "2025-04-06T09:40:31.639376Z", "shell.execute_reply": "2025-04-06T09:40:33.317132Z" }, "id": "mvn7K7fEgb-0", "outputId": "67b09522-42e3-46b8-dfcd-7a5501727462" }, "outputs": [ { "execution_count": 21, "output_type": "execute_result", "data": { "text/plain": " condition \\\n0 +pregnant woman symptoms \n1 . what is the world wide web, when was it crea... \n2 12 centimeters equals how many inches \n3 1984 buick regal gear ratio \n4 2% milk calories per glass \n... ... \n25347 why does carpal tunnel syndrome and the little... \n25348 why do you need a will \n25349 why do thunderstorms form \n25350 why do the english say leftenant \n25351 why did us declare war when \n\n group \n0 [Although the CDC states that pregnant women a... \n1 [Quick Answer. The Internet was created essent... \n2 [12 cm x (1 in./2.54 cm) = 4.7 inches multiply... \n3 [Read more. Although they are not listed speci... \n4 [An 8 ounce glass of whole milk contains appro... \n... ... \n25347 [Carpal tunnel syndrome can cause tingling, nu... \n25348 [If you want to leave any part of your assets ... \n25349 [How do they form? Thunderstorms are formed by... \n25350 [It's only the difference in pronunciation. In... \n25351 [The United States declared war on Germany for... \n\n[25352 rows x 2 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
conditiongroup
0+pregnant woman symptoms[Although the CDC states that pregnant women a...
1. what is the world wide web, when was it crea...[Quick Answer. The Internet was created essent...
212 centimeters equals how many inches[12 cm x (1 in./2.54 cm) = 4.7 inches multiply...
31984 buick regal gear ratio[Read more. Although they are not listed speci...
42% milk calories per glass[An 8 ounce glass of whole milk contains appro...
.........
25347why does carpal tunnel syndrome and the little...[Carpal tunnel syndrome can cause tingling, nu...
25348why do you need a will[If you want to leave any part of your assets ...
25349why do thunderstorms form[How do they form? Thunderstorms are formed by...
25350why do the english say leftenant[It's only the difference in pronunciation. In...
25351why did us declare war when[The United States declared war on Germany for...
\n

25352 rows × 2 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "sum(map(lambda _: len(_[1]), name_group_list_train_filter))" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:49:01.525313Z", "iopub.execute_input": "2025-04-06T09:49:01.525673Z", "iopub.status.idle": "2025-04-06T09:49:01.68355Z", "shell.execute_reply.started": "2025-04-06T09:49:01.525648Z", "shell.execute_reply": "2025-04-06T09:49:01.682423Z" }, "id": "igGbXGZEgb-0", "outputId": "c630715d-e72b-4e48-fb59-c6f7d28fa091" }, "outputs": [ { "execution_count": 31, "output_type": "execute_result", "data": { "text/plain": "55164" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "markdown", "source": [ "### test" ], "metadata": { "id": "yT4dp3i0gb-0" } }, { "cell_type": "code", "source": [ "name_group_list_dev = [(name[0], group) for name, group in df_qrels_dev_final.groupby(['query-id'])]\n", "print(len(name_group_list_dev))\n", "print(len(name_group_list_dev[0][1]))\n", "print(name_group_list_dev[1][1])\n", "print(len(name_group_list_dev[1][1]))\n", "\n", "print(\"过滤后\")\n", "name_group_list_dev_filter = list(filter(lambda _: len(_[1]) > 1, name_group_list_dev))\n", "print(len(name_group_list_dev_filter))\n", "print(len(name_group_list_dev_filter[0][1]))\n", "print(name_group_list_dev_filter[1][1])\n", "print(len(name_group_list_dev_filter[1][1]))" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:42:06.63411Z", "iopub.execute_input": "2025-04-06T09:42:06.634475Z", "iopub.status.idle": "2025-04-06T09:42:06.768768Z", "shell.execute_reply.started": "2025-04-06T09:42:06.634446Z", "shell.execute_reply": "2025-04-06T09:42:06.767698Z" }, "id": "Id-dKaMkgb-1", "outputId": "d50d6998-beb4-489e-f9d4-3f3156424221" }, "outputs": [ { "name": "stdout", "text": "6980\n1\n query-id corpus-id score \\\n2655 1215 7395960 1 \n\n corpus \\\n2655 In Canada, there are 3 levels of government. E... \n\n query \n2655 3 levels of government in canada and their res... \n1\n过滤后\n390\n2\n query-id corpus-id score \\\n4136 4947 7581255 1 \n4137 4947 7581263 1 \n\n corpus query \n4136 $25 Million. Ludacris net worth: Award winning... Ludacris Net Worth \n4137 Ludacris net worth is estimated at $25 million... Ludacris Net Worth \n2\n", "output_type": "stream" } ], "execution_count": null }, { "cell_type": "code", "source": [ "result_dev = list(map(handle, name_group_list_dev_filter))\n", "result_dev_df = pd.DataFrame(result_dev, columns=['condition', 'group'])\n", "result_dev_df" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:43:09.323632Z", "iopub.execute_input": "2025-04-06T09:43:09.324034Z", "iopub.status.idle": "2025-04-06T09:43:09.358933Z", "shell.execute_reply.started": "2025-04-06T09:43:09.324002Z", "shell.execute_reply": "2025-04-06T09:43:09.357829Z" }, "id": "SWhMrWLigb-1", "outputId": "23a401b0-c8be-4da8-e9cb-7227e06973bb" }, "outputs": [ { "execution_count": 23, "output_type": "execute_result", "data": { "text/plain": " condition \\\n0 Explain what a bone scan is and what it is use... \n1 Ludacris Net Worth \n2 age not to take off shoes at airline security \n3 aplastic anemia causes and symptoms \n4 asus phones price list \n.. ... \n385 hazel haskett in real life \n386 foods to keep constipation away \n387 effects of using pedialyte \n388 diff types of fuses \n389 definition of shagreen \n\n group \n0 [Why It Is Done. A bone scan is done to: 1 Fi... \n1 [$25 Million. Ludacris net worth: Award winnin... \n2 [It’s a victory for old soles. Travelers ove... \n3 [Symptoms and Complications. Symptoms of aplas... \n4 [More about Asus Mobiles Price List in India. ... \n.. ... \n385 [Hazel Haskett is the young heroine of Dolphin... \n386 [Focus on soluble fiber instead. Keep in mind ... \n387 [Plus, if you’re aiming for weight loss, the... \n388 [Automotive fuses are a class of fuses used to... \n389 [What is Shagreen Shagreen is an exotic materi... \n\n[390 rows x 2 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
conditiongroup
0Explain what a bone scan is and what it is use...[Why It Is Done. A bone scan is done to: 1 Fi...
1Ludacris Net Worth[$25 Million. Ludacris net worth: Award winnin...
2age not to take off shoes at airline security[It’s a victory for old soles. Travelers ove...
3aplastic anemia causes and symptoms[Symptoms and Complications. Symptoms of aplas...
4asus phones price list[More about Asus Mobiles Price List in India. ...
.........
385hazel haskett in real life[Hazel Haskett is the young heroine of Dolphin...
386foods to keep constipation away[Focus on soluble fiber instead. Keep in mind ...
387effects of using pedialyte[Plus, if you’re aiming for weight loss, the...
388diff types of fuses[Automotive fuses are a class of fuses used to...
389definition of shagreen[What is Shagreen Shagreen is an exotic materi...
\n

390 rows × 2 columns

\n
" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "markdown", "source": [ "### 处理上传" ], "metadata": { "id": "33AYPse6gb-1" } }, { "cell_type": "code", "source": [ "! pip install datasets" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:43:47.96705Z", "iopub.execute_input": "2025-04-06T09:43:47.967417Z", "iopub.status.idle": "2025-04-06T09:43:54.54077Z", "shell.execute_reply.started": "2025-04-06T09:43:47.967389Z", "shell.execute_reply": "2025-04-06T09:43:54.539401Z" }, "id": "d4zkEVddgb-1", "outputId": "c5380e14-5acd-4347-f334-dba7102fe64f" }, "outputs": [ { "name": "stdout", "text": "Requirement already satisfied: datasets in /usr/local/lib/python3.10/dist-packages (3.3.1)\nRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from datasets) (3.17.0)\nRequirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from datasets) (1.26.4)\nRequirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (19.0.1)\nRequirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.3.8)\nRequirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from datasets) (2.2.3)\nRequirement already satisfied: requests>=2.32.2 in /usr/local/lib/python3.10/dist-packages (from datasets) (2.32.3)\nRequirement already satisfied: tqdm>=4.66.3 in /usr/local/lib/python3.10/dist-packages (from datasets) (4.67.1)\nRequirement already satisfied: xxhash in /usr/local/lib/python3.10/dist-packages (from datasets) (3.5.0)\nRequirement already satisfied: multiprocess<0.70.17 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.70.16)\nRequirement already satisfied: fsspec<=2024.12.0,>=2023.1.0 in /usr/local/lib/python3.10/dist-packages (from fsspec[http]<=2024.12.0,>=2023.1.0->datasets) (2024.12.0)\nRequirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from datasets) (3.11.12)\nRequirement already satisfied: huggingface-hub>=0.24.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.29.0)\nRequirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from datasets) (24.2)\nRequirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (6.0.2)\nRequirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (2.4.6)\nRequirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.3.2)\nRequirement already satisfied: async-timeout<6.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (5.0.1)\nRequirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (25.1.0)\nRequirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.5.0)\nRequirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (6.1.0)\nRequirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (0.2.1)\nRequirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.18.3)\nRequirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.24.0->datasets) (4.12.2)\nRequirement already satisfied: mkl_fft in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (1.3.8)\nRequirement already satisfied: mkl_random in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (1.2.4)\nRequirement already satisfied: mkl_umath in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (0.1.1)\nRequirement already satisfied: mkl in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (2025.0.1)\nRequirement already satisfied: tbb4py in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (2022.0.0)\nRequirement already satisfied: mkl-service in /usr/local/lib/python3.10/dist-packages (from numpy>=1.17->datasets) (2.4.1)\nRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.2->datasets) (3.4.1)\nRequirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.2->datasets) (3.10)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.2->datasets) (2.3.0)\nRequirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.2->datasets) (2025.1.31)\nRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2.9.0.post0)\nRequirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2025.1)\nRequirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2025.1)\nRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->datasets) (1.17.0)\nRequirement already satisfied: intel-openmp>=2024 in /usr/local/lib/python3.10/dist-packages (from mkl->numpy>=1.17->datasets) (2024.2.0)\nRequirement already satisfied: tbb==2022.* in /usr/local/lib/python3.10/dist-packages (from mkl->numpy>=1.17->datasets) (2022.0.0)\nRequirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.10/dist-packages (from tbb==2022.*->mkl->numpy>=1.17->datasets) (1.2.0)\nRequirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.10/dist-packages (from mkl_umath->numpy>=1.17->datasets) (2024.2.0)\nRequirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.10/dist-packages (from intel-openmp>=2024->mkl->numpy>=1.17->datasets) (2024.2.0)\n", "output_type": "stream" } ], "execution_count": null }, { "cell_type": "code", "source": [ "from datasets import Dataset, DatasetDict\n", "from huggingface_hub import login, create_repo" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:44:15.739725Z", "iopub.execute_input": "2025-04-06T09:44:15.74019Z", "iopub.status.idle": "2025-04-06T09:44:16.888346Z", "shell.execute_reply.started": "2025-04-06T09:44:15.740153Z", "shell.execute_reply": "2025-04-06T09:44:16.886998Z" }, "id": "t5jZUv9ogb-1" }, "outputs": [], "execution_count": null }, { "cell_type": "code", "source": [ "dataset_train = Dataset.from_pandas(result_train_df)\n", "dataset_dev = Dataset.from_pandas(result_dev_df)" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:44:57.703617Z", "iopub.execute_input": "2025-04-06T09:44:57.70424Z", "iopub.status.idle": "2025-04-06T09:44:57.97515Z", "shell.execute_reply.started": "2025-04-06T09:44:57.704205Z", "shell.execute_reply": "2025-04-06T09:44:57.974158Z" }, "id": "9v0L_tQ9gb-2" }, "outputs": [], "execution_count": null }, { "cell_type": "code", "source": [ "dataset_dict = DatasetDict({\n", " \"train\": dataset_train,\n", " \"validation\": dataset_dev\n", "})\n", "dataset_dict" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:45:35.556553Z", "iopub.execute_input": "2025-04-06T09:45:35.556942Z", "iopub.status.idle": "2025-04-06T09:45:35.563684Z", "shell.execute_reply.started": "2025-04-06T09:45:35.556909Z", "shell.execute_reply": "2025-04-06T09:45:35.562624Z" }, "id": "UiEFU-Mdgb-2", "outputId": "1f11b39b-2854-46a8-cfb7-07da1adf2217" }, "outputs": [ { "execution_count": 28, "output_type": "execute_result", "data": { "text/plain": "DatasetDict({\n train: Dataset({\n features: ['condition', 'group'],\n num_rows: 25352\n })\n validation: Dataset({\n features: ['condition', 'group'],\n num_rows: 390\n })\n})" }, "metadata": {} } ], "execution_count": null }, { "cell_type": "code", "source": [ "login(token=\"\")" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:46:22.37811Z", "iopub.execute_input": "2025-04-06T09:46:22.378487Z", "iopub.status.idle": "2025-04-06T09:46:22.551342Z", "shell.execute_reply.started": "2025-04-06T09:46:22.378457Z", "shell.execute_reply": "2025-04-06T09:46:22.550182Z" }, "id": "AzHT7K6mgb-2" }, "outputs": [], "execution_count": null }, { "cell_type": "code", "source": [ "# 创建数据集仓库\n", "repo_id = \"bcai001/c-sts-msmarco-query-as-condition-group-as-pos\" # 例如: \"johnsmith/sentiment-analysis-data\"\n", "create_repo(repo_id, repo_type=\"dataset\", exist_ok=True)\n", "\n", "# 上传数据集\n", "dataset_dict.push_to_hub(repo_id, private=True)\n", "\n", "print(f\"Dataset uploaded to: https://huggingface.co/datasets/{repo_id}\")" ], "metadata": { "trusted": true, "execution": { "iopub.status.busy": "2025-04-06T09:47:17.953954Z", "iopub.execute_input": "2025-04-06T09:47:17.954409Z", "iopub.status.idle": "2025-04-06T09:47:24.300149Z", "shell.execute_reply.started": "2025-04-06T09:47:17.954373Z", "shell.execute_reply": "2025-04-06T09:47:24.299078Z" }, "id": "S4cpLc2tgb-2", "outputId": "3974e20d-75a8-4708-b61e-c7c6a86e77c3", "colab": { "referenced_widgets": [ "c9b5dc7a19cd4d92a8196115f7800616", "eeee18a3be884f9193bab5859c17a690", "54279d4beff64e3a9fbaed1122b15e36", "fee0329cca8c449ca832b910cdbf3754" ] } }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": "Uploading the dataset shards: 0%| | 0/1 [00:00