{"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":[{"sourceType":"competition","sourceId":121150,"databundleVersionId":15833391,"isSourceIdPinned":false}],"dockerImageVersionId":31286,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## このNotebookの対象\n\n・このコンペに初参加の人  \n・まず提出してみたい人  \n・データ構造を理解したい人","metadata":{}},{"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)\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},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## コンペ概要\n\nこのコンペでは\n\nAkkadian（古代メソポタミア語）\n\nを\n\nEnglish\n\nに翻訳するモデルを作成します。\n\nつまり\n\nAkkadian text → English translation\n\nという機械翻訳タスクです。\n\nこのNotebookでは\n\n・データ構造を理解する  \n・簡単な翻訳モデルを作る  \n・submissionを作る  \n\nことを目的にします。","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:27:40.617289Z","iopub.execute_input":"2026-03-09T11:27:40.617648Z","iopub.status.idle":"2026-03-09T11:27:41.849923Z","shell.execute_reply.started":"2026-03-09T11:27:40.617611Z","shell.execute_reply":"2026-03-09T11:27:41.849054Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"DATA_PATH = \"/kaggle/input/competitions/deep-past-initiative-machine-translation\"\n\ntrain = pd.read_csv(f\"{DATA_PATH}/train.csv\")\ntest = pd.read_csv(f\"{DATA_PATH}/test.csv\")\nsample = pd.read_csv(f\"{DATA_PATH}/sample_submission.csv\")\n\nprint(train.columns)\nprint(test.columns)\nprint(sample.columns)\n\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:31:19.857864Z","iopub.execute_input":"2026-03-09T11:31:19.858474Z","iopub.status.idle":"2026-03-09T11:31:19.924781Z","shell.execute_reply.started":"2026-03-09T11:31:19.858438Z","shell.execute_reply":"2026-03-09T11:31:19.923547Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## データ構造\n\ntrain には主に次の列があります。\n\n- oare_id  \n  データのID\n- transliteration  \n  アッカド語の翻字テキスト\n- translation  \n  英語訳\n\nこのNotebookでは、`transliteration` を入力、`translation` を正解として使います。","metadata":{}},{"cell_type":"code","source":"train[\"transliteration\"].iloc[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:30:15.619201Z","iopub.execute_input":"2026-03-09T11:30:15.620218Z","iopub.status.idle":"2026-03-09T11:30:15.627809Z","shell.execute_reply.started":"2026-03-09T11:30:15.620177Z","shell.execute_reply":"2026-03-09T11:30:15.626782Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"translation\"].iloc[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:30:41.422780Z","iopub.execute_input":"2026-03-09T11:30:41.423161Z","iopub.status.idle":"2026-03-09T11:30:41.431036Z","shell.execute_reply.started":"2026-03-09T11:30:41.423134Z","shell.execute_reply":"2026-03-09T11:30:41.429648Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## 文の長さ分布","metadata":{}},{"cell_type":"code","source":"train[\"length\"] = train[\"transliteration\"].str.len()\n\ntrain[\"length\"].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:32:25.883234Z","iopub.execute_input":"2026-03-09T11:32:25.884456Z","iopub.status.idle":"2026-03-09T11:32:25.903552Z","shell.execute_reply.started":"2026-03-09T11:32:25.884415Z","shell.execute_reply":"2026-03-09T11:32:25.901970Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"words = train[\"translation\"].str.split().explode()\n\ncommon_words = words.value_counts().index[:100]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:32:46.945922Z","iopub.execute_input":"2026-03-09T11:32:46.946456Z","iopub.status.idle":"2026-03-09T11:32:47.012611Z","shell.execute_reply.started":"2026-03-09T11:32:46.946424Z","shell.execute_reply":"2026-03-09T11:32:47.011369Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import random\n\ndef simple_translate(x):\n    \n    n = random.randint(3,8)\n    \n    return \" \".join(random.sample(list(common_words),n))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:32:53.241213Z","iopub.execute_input":"2026-03-09T11:32:53.241756Z","iopub.status.idle":"2026-03-09T11:32:53.247872Z","shell.execute_reply.started":"2026-03-09T11:32:53.241718Z","shell.execute_reply":"2026-03-09T11:32:53.246495Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds = test[\"transliteration\"].apply(simple_translate)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:33:11.186037Z","iopub.execute_input":"2026-03-09T11:33:11.187225Z","iopub.status.idle":"2026-03-09T11:33:11.193186Z","shell.execute_reply.started":"2026-03-09T11:33:11.187181Z","shell.execute_reply":"2026-03-09T11:33:11.191864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    \n    \"id\":test[\"id\"],\n    \"translation\":preds\n})\n\nsubmission.to_csv(\"submission.csv\",index=False)\n\nsubmission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T11:33:19.057439Z","iopub.execute_input":"2026-03-09T11:33:19.057790Z","iopub.status.idle":"2026-03-09T11:33:19.079021Z","shell.execute_reply.started":"2026-03-09T11:33:19.057762Z","shell.execute_reply":"2026-03-09T11:33:19.077994Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## まとめ\n\nこのNotebookでは\n\n・データ構造の確認  \n・文章長の確認  \n・簡単な翻訳ベースライン  \n・submission作成  \n\nを行いました。\n\n今後の改善案\n\n・Transformer翻訳モデル  \n・HuggingFaceモデル  \n・T5  \n・mBART","metadata":{}}]}