{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":121150,"databundleVersionId":15061024,"sourceType":"competition"}],"dockerImageVersionId":31259,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nfrom collections import Counter\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.682076Z","iopub.execute_input":"2026-02-09T16:59:51.682393Z","iopub.status.idle":"2026-02-09T16:59:51.690708Z","shell.execute_reply.started":"2026-02-09T16:59:51.682366Z","shell.execute_reply":"2026-02-09T16:59:51.689251Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/deep-past-initiative-machine-translation/train.csv')\ntest  = pd.read_csv('/kaggle/input/deep-past-initiative-machine-translation/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.692778Z","iopub.execute_input":"2026-02-09T16:59:51.693101Z","iopub.status.idle":"2026-02-09T16:59:51.757100Z","shell.execute_reply.started":"2026-02-09T16:59:51.693072Z","shell.execute_reply":"2026-02-09T16:59:51.755959Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.758772Z","iopub.execute_input":"2026-02-09T16:59:51.759902Z","iopub.status.idle":"2026-02-09T16:59:51.769988Z","shell.execute_reply.started":"2026-02-09T16:59:51.759862Z","shell.execute_reply":"2026-02-09T16:59:51.768750Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing = df.isnull\nmissing","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.772899Z","iopub.execute_input":"2026-02-09T16:59:51.773208Z","iopub.status.idle":"2026-02-09T16:59:51.799550Z","shell.execute_reply.started":"2026-02-09T16:59:51.773181Z","shell.execute_reply":"2026-02-09T16:59:51.798622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ndf[\"src_tokens\"] = df[\"transliteration\"].astype(str).apply(lambda x: len(x.split()))\ndf[\"tgt_tokens\"] = df[\"translation\"].astype(str).apply(lambda x: len(x.split()))\n\ndf[\"src_chars\"] = df[\"transliteration\"].astype(str).apply(len)\ndf[\"tgt_chars\"] = df[\"translation\"].astype(str).apply(len)\n\ndf[\"len_ratio\"] = df[\"tgt_tokens\"] / (df[\"src_tokens\"] + 1)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.800897Z","iopub.execute_input":"2026-02-09T16:59:51.801181Z","iopub.status.idle":"2026-02-09T16:59:51.854283Z","shell.execute_reply.started":"2026-02-09T16:59:51.801154Z","shell.execute_reply":"2026-02-09T16:59:51.853263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(8,5))\nplt.hist(df[\"src_tokens\"], bins=50, alpha=0.7, label=\"Transliteration\")\nplt.hist(df[\"tgt_tokens\"], bins=50, alpha=0.7, label=\"English Translation\")\nplt.xlabel(\"Number of Tokens\")\nplt.ylabel(\"Frequency\")\nplt.title(\"Token Length Distribution\")\nplt.legend()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T16:59:51.855390Z","iopub.execute_input":"2026-02-09T16:59:51.855961Z","iopub.status.idle":"2026-02-09T16:59:52.276415Z","shell.execute_reply.started":"2026-02-09T16:59:51.855898Z","shell.execute_reply":"2026-02-09T16:59:52.275017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(6,6))\nplt.scatter(df[\"src_chars\"], df[\"tgt_chars\"], alpha=0.4)\nplt.xlabel(\"Transliteration Characters\")\nplt.ylabel(\"Translation Characters\")\nplt.title(\"Source vs Target Character Length\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T17:01:16.723314Z","iopub.execute_input":"2026-02-09T17:01:16.723661Z","iopub.status.idle":"2026-02-09T17:01:16.938719Z","shell.execute_reply.started":"2026-02-09T17:01:16.723633Z","shell.execute_reply":"2026-02-09T17:01:16.937493Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"src_vocab = Counter(\" \".join(df[\"transliteration\"]).split())\ncommon_src = src_vocab.most_common(20)\n\nwords, counts = zip(*common_src)\n\nplt.figure(figsize=(10,4))\nplt.bar(words, counts)\nplt.xticks(rotation=45)\nplt.ylabel(\"Frequency\")\nplt.title(\"Top 20 Transliteration Tokens\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T17:01:49.370993Z","iopub.execute_input":"2026-02-09T17:01:49.371340Z","iopub.status.idle":"2026-02-09T17:01:49.644776Z","shell.execute_reply.started":"2026-02-09T17:01:49.371308Z","shell.execute_reply":"2026-02-09T17:01:49.643678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(6,4))\nplt.hist(df[df[\"src_tokens\"] < 10][\"src_tokens\"], bins=10)\nplt.title(\"Very Short Transliteration Samples\")\nplt.xlabel(\"Tokens\")\nplt.ylabel(\"Count\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-09T17:02:35.162992Z","iopub.execute_input":"2026-02-09T17:02:35.163387Z","iopub.status.idle":"2026-02-09T17:02:35.323542Z","shell.execute_reply.started":"2026-02-09T17:02:35.163359Z","shell.execute_reply":"2026-02-09T17:02:35.322593Z"}},"outputs":[],"execution_count":null}]}