{"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"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"! pip install /kaggle/input/bengali-packages/jiwer-3.0.3-py3-none-any.whl -f ./ --no-index\n! python -m pip install --no-index --find-links=/kaggle/input/bengali-packages seamless-communication\n! mkdir -p ~/.cache/torch\n! cp -rf ../input/bengali-m4t-medium/hub ~/.cache/torch/\n\n!cp -r /kaggle/input/python-packages2 /tmp\n!tar xvfz /tmp/python-packages2/normalizer.tgz\n!pip install ./normalizer/bnunicodenormalizer-0.0.24.tar.gz -f ./ --no-index","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:44:12.574574Z","iopub.execute_input":"2023-09-11T22:44:12.574928Z","iopub.status.idle":"2023-09-11T22:48:16.537958Z","shell.execute_reply.started":"2023-09-11T22:44:12.574892Z","shell.execute_reply":"2023-09-11T22:48:16.536760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pandas as pd\nimport torch\nfrom seamless_communication.models.inference import Translator\n\nfrom bnunicodenormalizer import Normalizer","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:48:16.540694Z","iopub.execute_input":"2023-09-11T22:48:16.541613Z","iopub.status.idle":"2023-09-11T22:48:21.894363Z","shell.execute_reply.started":"2023-09-11T22:48:16.541569Z","shell.execute_reply":"2023-09-11T22:48:21.893386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"translator = Translator(\"seamlessM4T_medium\", \"vocoder_36langs\", torch.device(\"cuda:0\"), torch.float16)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:48:21.895813Z","iopub.execute_input":"2023-09-11T22:48:21.896326Z","iopub.status.idle":"2023-09-11T22:49:14.720092Z","shell.execute_reply.started":"2023-09-11T22:48:21.896288Z","shell.execute_reply":"2023-09-11T22:49:14.719041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv(\"/kaggle/input/bengaliai-speech/sample_submission.csv\")\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:49:14.722534Z","iopub.execute_input":"2023-09-11T22:49:14.723163Z","iopub.status.idle":"2023-09-11T22:49:14.773564Z","shell.execute_reply.started":"2023-09-11T22:49:14.723126Z","shell.execute_reply":"2023-09-11T22:49:14.772557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = []\ndata_dir = \"/kaggle/input/bengaliai-speech/test_mp3s\"\nfor index, row in test_df.iterrows():\n    file_path = os.path.join(data_dir, row[\"id\"] + \".mp3\")\n    translated_text, _, _ = translator.predict(file_path, \"s2tt\", \"ben\")\n    prediction.append(str(translated_text))","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:49:14.775346Z","iopub.execute_input":"2023-09-11T22:49:14.775725Z","iopub.status.idle":"2023-09-11T22:49:19.454584Z","shell.execute_reply.started":"2023-09-11T22:49:14.775690Z","shell.execute_reply":"2023-09-11T22:49:19.453612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bnorm = Normalizer()\n\ndef postprocess(sentence):\n    _words = [bnorm(word)['normalized']  for word in sentence.split()]\n    sentence = \" \".join([word for word in _words if word is not None])\n    try:\n        if sentence[-1]!=\"।\":\n            sentence+=\"।\"\n    except:\n        print(sentence)\n    return sentence\n\nnormed_prediction = [postprocess(p) for p in prediction]\nnormed_prediction = [p if len(p) > 0 else \"।\" for p in normed_prediction]","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:49:19.475042Z","iopub.execute_input":"2023-09-11T22:49:19.475571Z","iopub.status.idle":"2023-09-11T22:49:19.500270Z","shell.execute_reply.started":"2023-09-11T22:49:19.475537Z","shell.execute_reply":"2023-09-11T22:49:19.499353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[\"sentence\"] = normed_prediction\ntest_df.to_csv(\"submission.csv\", index=False)\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T22:50:21.599233Z","iopub.execute_input":"2023-09-11T22:50:21.599609Z","iopub.status.idle":"2023-09-11T22:50:21.613278Z","shell.execute_reply.started":"2023-09-11T22:50:21.599579Z","shell.execute_reply":"2023-09-11T22:50:21.612198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}