File size: 5,353 Bytes
b47751a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "bed45d12-7681-4ba4-9c89-48a3515704e2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please request data from https://codalab.lisn.upsaclay.fr/competitions/1688\n",
"We only need eval_synthetic.csv and train_synthetic.csv\n",
"eval_synthetic.csv process.ipynb train_synthetic.csv\n"
]
}
],
"source": [
"print(\"Please request data from https://codalab.lisn.upsaclay.fr/competitions/1688\")\n",
"print(\"We only need eval_synthetic.csv and train_synthetic.csv\")\n",
"!ls ."
]
},
{
"cell_type": "markdown",
"id": "b5c7c7c7-b9a6-4ea2-a5ef-edaf982ae0ad",
"metadata": {},
"source": [
"### Required columns\n",
"- target_hinglish\n",
"- source_hindi\n",
"- parallel_english\n",
"- annotations\n",
"- raw_input\n",
"- alternates\n",
"\n",
"> For **HingE**, only `target_hinglish`, `parallel_english` and `source_hindi` are valid"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "965589a9-c62e-4659-a6bc-6f0a2bad5d19",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"train_df = pd.read_csv(\"./train_synthetic.csv\", names=[\"parallel_english\", \"source_hindi\", \"target_hinglish\"], header=0, usecols=[0, 1, 2])\n",
"_test_eval_df = pd.read_csv(\"./train_synthetic.csv\", names=[\"parallel_english\", \"source_hindi\", \"target_hinglish\"], header=0, usecols=[0, 1, 2])\n",
"\n",
"# Add empty columns\n",
"train_df[\"raw_input\"] = \\\n",
" train_df[\"alternates\"] = \\\n",
" train_df[\"annotations\"] = None\n",
"\n",
"_test_eval_df[\"raw_input\"] = \\\n",
" _test_eval_df[\"alternates\"] = \\\n",
" _test_eval_df[\"annotations\"] = None\n",
"\n",
"# Split dataset\n",
"from sklearn.model_selection import train_test_split\n",
"eval_df, test_df = train_test_split(_test_eval_df, test_size=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6e804366-34cd-45c7-b3c6-46b7b8c1b420",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting tables\n",
" Using cached tables-3.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB)\n",
"Collecting numexpr>=2.6.2\n",
" Using cached numexpr-2.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (379 kB)\n",
"Requirement already satisfied: packaging in /opt/conda/lib/python3.7/site-packages (from tables) (21.3)\n",
"Requirement already satisfied: numpy>=1.19.0 in /opt/conda/lib/python3.7/site-packages (from tables) (1.19.5)\n",
"Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/lib/python3.7/site-packages (from packaging->tables) (3.0.6)\n",
"Installing collected packages: numexpr, tables\n",
"Successfully installed numexpr-2.8.1 tables-3.7.0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py:2718: PerformanceWarning: \n",
"your performance may suffer as PyTables will pickle object types that it cannot\n",
"map directly to c-types [inferred_type->mixed,key->block0_values] [items->Index(['parallel_english', 'source_hindi', 'target_hinglish', 'raw_input',\n",
" 'alternates', 'annotations'],\n",
" dtype='object')]\n",
"\n",
" encoding=encoding,\n"
]
}
],
"source": [
"!pip install tables\n",
"\n",
"# Save to hdfs files\n",
"train_df.to_hdf(\"./data.h5\", \"train\", complevel=9)\n",
"test_df.to_hdf(\"./data.h5\", \"test\", complevel=9)\n",
"eval_df.to_hdf(\"./data.h5\", \"eval\", complevel=9)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3298f2f3-3e21-478e-b027-947c992f880d",
"metadata": {},
"outputs": [],
"source": [
"# Confirm that everything worked as expected\n",
"\n",
"# Load from hdfs files\n",
"_train_df = pd.read_hdf(\"./data.h5\", \"train\")\n",
"_test_df = pd.read_hdf(\"./data.h5\", \"test\")\n",
"_eval_df = pd.read_hdf(\"./data.h5\", \"eval\")\n",
"\n",
"assert (len(_train_df) == len(train_df)) == \\\n",
" (len(_eval_df) == len(eval_df)) == \\\n",
" (len(_test_df) == len(test_df))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "60461121-bed5-4ba0-ba7d-dd46256c62e3",
"metadata": {},
"outputs": [],
"source": [
"!rm eval_synthetic.csv\n",
"!rm train_synthetic.csv"
]
}
],
"metadata": {
"environment": {
"kernel": "python3",
"name": "managed-notebooks.m87",
"type": "gcloud",
"uri": "gcr.io/deeplearning-platform-release/base-cu110:latest"
},
"kernelspec": {
"display_name": "Python (Local)",
"language": "python",
"name": "local-base"
},
"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.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|