{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bed45d12-7681-4ba4-9c89-48a3515704e2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Please request data from http://workshop.colips.org/news2018/terms&conditions_msri.html\n" ] } ], "source": [ "print(\"Please request data from http://workshop.colips.org/news2018/terms&conditions_msri.html\")" ] }, { "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 **NEWS2018**, only `target_hinglish` and `source_hindi` are valid" ] }, { "cell_type": "code", "execution_count": 7, "id": "965589a9-c62e-4659-a6bc-6f0a2bad5d19", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: lxml in /opt/conda/lib/python3.7/site-packages (4.8.0)\n" ] } ], "source": [ "!pip install lxml\n", "import pandas as pd\n", "\n", "train_df = pd.read_xml(\"./NEWS2018_M-EnHi_trn.xml\", names=[\"target_hinglish\", \"source_hindi\"], elems_only=True)\n", "test_df = pd.read_xml(\"./NEWS2018_M-EnHi_tst.xml\", names=[\"target_hinglish\", \"source_hindi\"], elems_only=True)\n", "eval_df = pd.read_xml(\"./NEWS2018_M-EnHi_dev.xml\", names=[\"target_hinglish\", \"source_hindi\"], elems_only=True)\n", "\n", "# Add empty columns\n", "train_df[\"raw_input\"] = \\\n", " train_df[\"parallel_english\"] = \\\n", " train_df[\"alternates\"] = \\\n", " train_df[\"annotations\"] = None\n", "\n", "# Add empty columns\n", "test_df[\"raw_input\"] = \\\n", " test_df[\"parallel_english\"] = \\\n", " test_df[\"alternates\"] = \\\n", " test_df[\"annotations\"] = None\n", "\n", "# Add empty columns\n", "eval_df[\"raw_input\"] = \\\n", " eval_df[\"parallel_english\"] = \\\n", " eval_df[\"alternates\"] = \\\n", " eval_df[\"annotations\"] = None\n" ] }, { "cell_type": "code", "execution_count": 8, "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", "Requirement already satisfied: numpy>=1.19.0 in /opt/conda/lib/python3.7/site-packages (from tables) (1.19.5)\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: 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(['target_hinglish', 'source_hindi', 'raw_input', 'parallel_english',\n", " 'alternates', 'annotations'],\n", " dtype='object')]\n", "\n", " encoding=encoding,\n", "/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(['target_hinglish', 'raw_input', 'parallel_english', 'alternates',\n", " '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": 11, "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": 12, "id": "60461121-bed5-4ba0-ba7d-dd46256c62e3", "metadata": {}, "outputs": [], "source": [ "!rm NEWS2018_M-EnHi_trn.xml\n", "!rm NEWS2018_M-EnHi_tst.xml\n", "!rm NEWS2018_M-EnHi_dev.xml" ] } ], "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 }