{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"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.12.12"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceType":"competition","sourceId":121150,"databundleVersionId":15833391},{"sourceType":"datasetVersion","sourceId":14899351,"datasetId":9366631,"databundleVersionId":15763950},{"sourceType":"modelInstanceVersion","sourceId":755680,"databundleVersionId":15750522,"modelInstanceId":577094,"modelId":589419}],"dockerImageVersionId":31260,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true},"papermill":{"default_parameters":{},"duration":152.290084,"end_time":"2026-03-06T10:51:23.477647","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2026-03-06T10:48:51.187563","version":"2.6.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"043e611049324c32b2c12de72cb0a499":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_0708d4b9e9744ea8bb4c61fa3f9ecfd6","placeholder":"​","style":"IPY_MODEL_fe2b90f4fbb4444182453c3c8546eb6f","tabbable":null,"tooltip":null,"value":"MBR: 100%"}},"05c48bda667d416589c35616deda1e22":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_aa629f0238ca4cf987882e6f5f8f5f4e","IPY_MODEL_2d4dadecf6bd4ea2bd669b18e8be8a2f","IPY_MODEL_0f4d1ed17b6c4bd3b08c0f8bfa20cf3f"],"layout":"IPY_MODEL_41c9dd0cda7041a38de8e3d92474e70d","tabbable":null,"tooltip":null}},"0708d4b9e9744ea8bb4c61fa3f9ecfd6":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"089efdff309d49ac8b59d3ae2525218a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_9b545404e8f24e788014496b07416105","IPY_MODEL_e62197f25bc641ca9161315417665e6b","IPY_MODEL_d3e8f26be5c8418c906a5977ae0b7013"],"layout":"IPY_MODEL_eed5afb3c7744571825718d1372ce729","tabbable":null,"tooltip":null}},"0dff9c6ff64b4bd1a1b0bc0fc468cddb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_d41957e2e7fb4ff0a71fb240b87083b2","placeholder":"​","style":"IPY_MODEL_82b57b2e630d4422ad5ac0169eda93e0","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"0f4d1ed17b6c4bd3b08c0f8bfa20cf3f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5808008632d1433ebdcbacd16439f24f","placeholder":"​","style":"IPY_MODEL_4f30b5da400c4d69aa114e9833ffae5a","tabbable":null,"tooltip":null,"value":" 252/252 [00:00&lt;00:00, 382.96it/s, Materializing param=shared.weight]"}},"11c84005daca41a59d469f65038365f1":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"18b269c212b34d66a3353691611de45f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"18f8b7c3a20b4b2f91177840fc3e7aa9":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"1959a96900cc462fb76eb22effbca740":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"19a0f2fa8765422fbb3ed703aa8e23c3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"1a0725b5dc954a12bbc1e503e09ab7de":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_18f8b7c3a20b4b2f91177840fc3e7aa9","max":4,"min":0,"orientation":"horizontal","style":"IPY_MODEL_664a8ffd556c4a599719c73d08aa082c","tabbable":null,"tooltip":null,"value":4}},"1c193879c4644eefb65719a6d7bc5e2b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"1fa7b1f9c56f436fbbb465ccf0f9fbea":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"2d4dadecf6bd4ea2bd669b18e8be8a2f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_b420352e3e7846d9b4de45fd626c040f","max":252,"min":0,"orientation":"horizontal","style":"IPY_MODEL_c0bdf8ccc8fc4073acf7743342b2a785","tabbable":null,"tooltip":null,"value":252}},"3b89b24c90e84f4d9e3b6d53a5411c0d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"41c9dd0cda7041a38de8e3d92474e70d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4285b9ea9056407f9006d6efd2659a17":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_fb4849a9f9854e31b3bf400d18f2f5c9","max":4,"min":0,"orientation":"horizontal","style":"IPY_MODEL_9eab6679fdf54c89a97b346f092ecfa0","tabbable":null,"tooltip":null,"value":4}},"4e2fbb58804d41ff865068bc86c6db1d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_d8286dfe8176475590eca6931fd5db46","placeholder":"​","style":"IPY_MODEL_1c193879c4644eefb65719a6d7bc5e2b","tabbable":null,"tooltip":null,"value":" 4/4 [00:33&lt;00:00,  9.40s/it]"}},"4f30b5da400c4d69aa114e9833ffae5a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"5808008632d1433ebdcbacd16439f24f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5c25acbf560743978c61f9aeae5688a0":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5ec2c2546f4c4f9cbca7d2ae94b97c68":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5edd6d3b4f9e40c381f4d9149c3342db":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"664a8ffd556c4a599719c73d08aa082c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"6ada73780a9f4488b55fa2660548dec5":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"82b57b2e630d4422ad5ac0169eda93e0":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"84de4f7dd545495d858c38ae2001b8b5":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_8dc453e45a4a4147a166778c5f93e16e","placeholder":"​","style":"IPY_MODEL_fa6a44bd32d94b5bb08fd3c76700d805","tabbable":null,"tooltip":null,"value":" 252/252 [00:00&lt;00:00, 357.60it/s, Materializing param=shared.weight]"}},"8dc453e45a4a4147a166778c5f93e16e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"91377e1fbbe446a8a8aeb8c529b17f01":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"9b545404e8f24e788014496b07416105":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_d06c3ad399284d1d923f7b9065443816","placeholder":"​","style":"IPY_MODEL_d38c4628049d4740b3bfc7d829d50063","tabbable":null,"tooltip":null,"value":"[Model-A]: 100%"}},"9c08da86e17048c182ee2d7d0ebdc54b":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"9eab6679fdf54c89a97b346f092ecfa0":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"9fcd8d6c00be4273be089f003b248c45":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"aa629f0238ca4cf987882e6f5f8f5f4e":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5ec2c2546f4c4f9cbca7d2ae94b97c68","placeholder":"​","style":"IPY_MODEL_fde2509ab2504572b905ac189eebe308","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"ae443aff15004e4897a39e449056b4fa":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_9c08da86e17048c182ee2d7d0ebdc54b","placeholder":"​","style":"IPY_MODEL_1959a96900cc462fb76eb22effbca740","tabbable":null,"tooltip":null,"value":"[Model-B]: 100%"}},"b385b25237364e73af0b831a41dd76ba":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_043e611049324c32b2c12de72cb0a499","IPY_MODEL_1a0725b5dc954a12bbc1e503e09ab7de","IPY_MODEL_b9c30f4d078f44b290289ff4696255c7"],"layout":"IPY_MODEL_1fa7b1f9c56f436fbbb465ccf0f9fbea","tabbable":null,"tooltip":null}},"b420352e3e7846d9b4de45fd626c040f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b9996b38299a4f359cd53a3709c0d2b7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_ae443aff15004e4897a39e449056b4fa","IPY_MODEL_4285b9ea9056407f9006d6efd2659a17","IPY_MODEL_4e2fbb58804d41ff865068bc86c6db1d"],"layout":"IPY_MODEL_9fcd8d6c00be4273be089f003b248c45","tabbable":null,"tooltip":null}},"b9c30f4d078f44b290289ff4696255c7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5c25acbf560743978c61f9aeae5688a0","placeholder":"​","style":"IPY_MODEL_19a0f2fa8765422fbb3ed703aa8e23c3","tabbable":null,"tooltip":null,"value":" 4/4 [00:00&lt;00:00, 12.63it/s]"}},"ba17bfae397d411f8eb6b4f194d16aff":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_0dff9c6ff64b4bd1a1b0bc0fc468cddb","IPY_MODEL_f93e790964b34989b7deb931aa7e9e77","IPY_MODEL_84de4f7dd545495d858c38ae2001b8b5"],"layout":"IPY_MODEL_6ada73780a9f4488b55fa2660548dec5","tabbable":null,"tooltip":null}},"c0bdf8ccc8fc4073acf7743342b2a785":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"d06c3ad399284d1d923f7b9065443816":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d29550aaaa7d48ebbccb5a9c86d7d8bb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"d38c4628049d4740b3bfc7d829d50063":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"d3e8f26be5c8418c906a5977ae0b7013":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_91377e1fbbe446a8a8aeb8c529b17f01","placeholder":"​","style":"IPY_MODEL_3b89b24c90e84f4d9e3b6d53a5411c0d","tabbable":null,"tooltip":null,"value":" 4/4 [00:37&lt;00:00, 10.28s/it]"}},"d41957e2e7fb4ff0a71fb240b87083b2":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d8286dfe8176475590eca6931fd5db46":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e62197f25bc641ca9161315417665e6b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_11c84005daca41a59d469f65038365f1","max":4,"min":0,"orientation":"horizontal","style":"IPY_MODEL_d29550aaaa7d48ebbccb5a9c86d7d8bb","tabbable":null,"tooltip":null,"value":4}},"eed5afb3c7744571825718d1372ce729":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f93e790964b34989b7deb931aa7e9e77":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_5edd6d3b4f9e40c381f4d9149c3342db","max":252,"min":0,"orientation":"horizontal","style":"IPY_MODEL_18b269c212b34d66a3353691611de45f","tabbable":null,"tooltip":null,"value":252}},"fa6a44bd32d94b5bb08fd3c76700d805":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"fb4849a9f9854e31b3bf400d18f2f5c9":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"fde2509ab2504572b905ac189eebe308":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"fe2b90f4fbb4444182453c3c8546eb6f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}}},"version_major":2,"version_minor":0}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <div style=\"text-align:center; border-radius:18px; padding:18px; margin-bottom:12px; font-size:150%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 6px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 3px 8px rgba(0,0,0,0.35); color:white;\"><b>Deep Past Challenge — Ensemble × MBR</b></div>\n\n<a id=\"top\"></a>\n\n## Navigation\n\n* [1. Setup](#section1)\n* [2. Configuration](#section2)\n* [3. Text Processing](#section3)\n* [4. Dataset and Batching](#section4)\n* [5. Model Wrapper](#section5)\n* [6. MBR Selection](#section6)\n* [7. Inference Pipeline](#section7)\n* [8. Run and Save Submission](#section8)","metadata":{}},{"cell_type":"markdown","source":"# <div style=\"text-align:center; border-radius:15px; padding:15px; margin-top:10px; font-size:110%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>Thanks https://www.kaggle.com/meenalsinha for this amazing notebook, its impressive work :)</b></div>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"section1\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>1. Setup</b></div>","metadata":{}},{"cell_type":"code","source":"!pip install sacrebleu","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:18:50.660995Z","iopub.execute_input":"2026-03-09T00:18:50.661257Z","iopub.status.idle":"2026-03-09T00:22:28.884146Z","shell.execute_reply.started":"2026-03-09T00:18:50.661223Z","shell.execute_reply":"2026-03-09T00:22:28.883397Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport gc\nimport re\nimport json\nimport math\nimport random\nimport logging\nimport warnings\n\nfrom pathlib import Path\nfrom dataclasses import dataclass\nfrom contextlib import nullcontext\nfrom typing import List, Tuple\n\nimport pandas as pd\nimport numpy as np\nimport torch\nfrom torch.utils.data import Dataset, DataLoader, Sampler\nfrom transformers import AutoTokenizer, AutoModelForSeq2SeqLM\nfrom tqdm.auto import tqdm\n\nimport sacrebleu\n\nwarnings.filterwarnings(\"ignore\")\n\nos.environ.setdefault(\"OMP_NUM_THREADS\", \"4\")\nos.environ.setdefault(\"MKL_NUM_THREADS\", \"4\")\nos.environ.setdefault(\"TOKENIZERS_PARALLELISM\", \"true\")\n\ndef _cuda_bf16_supported() -> bool:\n    if not torch.cuda.is_available():\n        return False\n    try:\n        return bool(getattr(torch.cuda, \"is_bf16_supported\", lambda: False)())\n    except Exception:\n        return False\n\n\ndef _bf16_ctx(device: torch.device, enabled: bool):\n    if enabled and device.type == \"cuda\" and _cuda_bf16_supported():\n        return torch.autocast(device_type=\"cuda\", dtype=torch.bfloat16)\n    return nullcontext()\n\ndef setup_logging(output_dir: str) -> logging.Logger:\n    Path(output_dir).mkdir(exist_ok=True, parents=True)\n\n    for h in logging.root.handlers[:]:\n        logging.root.removeHandler(h)\n\n    logging.basicConfig(\n        level=logging.INFO,\n        format=\"%(asctime)s | %(levelname)s | %(message)s\",\n        handlers=[\n            logging.StreamHandler(),\n            logging.FileHandler(Path(output_dir) / \"ensemble_mbr.log\"),\n        ],\n    )\n    return logging.getLogger(\"ensemble_mbr\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:28.886293Z","iopub.execute_input":"2026-03-09T00:22:28.886815Z","iopub.status.idle":"2026-03-09T00:22:32.550780Z","shell.execute_reply.started":"2026-03-09T00:22:28.886785Z","shell.execute_reply":"2026-03-09T00:22:32.549660Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section2\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>2. Configuration</b></div>","metadata":{}},{"cell_type":"code","source":"@dataclass\nclass EnsembleMBRConfig:\n    test_data_path: str = \"/kaggle/input/deep-past-initiative-machine-translation/test.csv\"\n    output_dir: str     = \"/kaggle/working/\"\n    model_a_path: str   = \"/kaggle/input/final-byt5/byt5-akkadian-optimized-34x\"\n    model_b_path: str   = \"/kaggle/input/models/mattiaangeli/byt5-akkadian-mbr-v2/pytorch/default/1\"\n\n    max_input_length: int = 512\n    max_new_tokens: int   = 384\n    batch_size: int       = 2\n    num_workers: int      = 2\n    num_buckets: int      = 8\n\n    num_beam_cands: int = 5\n    num_beams: int      = 10\n    length_penalty: float = 1.15\n    early_stopping: bool  = True\n    repetition_penalty: float = 1.12\n\n    num_sample_cands: int = 3\n    mbr_top_p: float       = 0.95\n    mbr_temperature: float = 0.82\n    mbr_pool_cap: int      = 40\n\n    use_mixed_precision: bool    = True\n    use_better_transformer: bool = True\n    use_bucket_batching: bool    = True\n    use_adaptive_beams: bool     = True\n    aggressive_postprocessing: bool = False\n    checkpoint_freq: int = 200\n\n    def __post_init__(self):\n        self.device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n        Path(self.output_dir).mkdir(exist_ok=True, parents=True)\n\n        if not torch.cuda.is_available():\n            self.use_mixed_precision = False\n            self.use_better_transformer = False\n\n        self.use_bf16_amp = bool(\n            self.use_mixed_precision\n            and self.device.type == \"cuda\"\n            and _cuda_bf16_supported()\n        )\n\n        assert self.num_beams >= self.num_beam_cands\n\n\ndef print_env(cfg: EnsembleMBRConfig):\n    print(f\"PyTorch  : {torch.__version__}\")\n    print(f\"CUDA     : {torch.cuda.is_available()}\")\n\n    if torch.cuda.is_available():\n        print(f\"GPU      : {torch.cuda.get_device_name(0)}\")\n        mem = torch.cuda.get_device_properties(0).total_memory / 1e9\n        print(f\"GPU Mem  : {mem:.2f} GB\")\n        print(f\"BF16     : {_cuda_bf16_supported()}\")\n\n    print(f\"BF16 AMP : {cfg.use_bf16_amp}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.551485Z","iopub.status.idle":"2026-03-09T00:22:32.551805Z","shell.execute_reply.started":"2026-03-09T00:22:32.551674Z","shell.execute_reply":"2026-03-09T00:22:32.551691Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section3\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>3. Text Processing</b></div>","metadata":{}},{"cell_type":"code","source":"_V2 = re.compile(r\"([aAeEiIuU])(?:2|₂)\")\n_V3 = re.compile(r\"([aAeEiIuU])(?:3|₃)\")\n\n_ACUTE = str.maketrans({\"a\":\"á\",\"e\":\"é\",\"i\":\"í\",\"u\":\"ú\",\"A\":\"Á\",\"E\":\"É\",\"I\":\"Í\",\"U\":\"Ú\"})\n_GRAVE = str.maketrans({\"a\":\"à\",\"e\":\"è\",\"i\":\"ì\",\"u\":\"ù\",\"A\":\"À\",\"E\":\"È\",\"I\":\"Ì\",\"U\":\"Ù\"})\n\n\ndef _ascii_to_diacritics(s):\n\n    s = s.replace(\"sz\",\"š\").replace(\"SZ\",\"Š\")\n    s = s.replace(\"s,\",\"ṣ\").replace(\"S,\",\"Ṣ\")\n    s = s.replace(\"t,\",\"ṭ\").replace(\"T,\",\"Ṭ\")\n\n    s = _V2.sub(lambda m: m.group(1).translate(_ACUTE), s)\n    s = _V3.sub(lambda m: m.group(1).translate(_GRAVE), s)\n\n    return s\n\n_WS_RE = re.compile(r\"\\s+\")\n\n_GAP_UNIFIED_RE = re.compile(\n    r\"<\\s*gap\\s*>\"\n    r\"|\\.{3,}\"\n    r\"|…+\"\n    r\"|\\[\\.+\\]\"\n    r\"|\\bx\\b\",\n    re.I\n)\n\n\ndef _normalize_gaps_vec(ser):\n    return ser.str.replace(_GAP_UNIFIED_RE,\"<gap>\",regex=True)\n\nclass OptimizedPreprocessor:\n\n    def preprocess_batch(self, texts):\n\n        ser = pd.Series(texts).fillna(\"\").astype(str)\n\n        ser = ser.apply(_ascii_to_diacritics)\n\n        ser = _normalize_gaps_vec(ser)\n\n        ser = ser.str.replace(_WS_RE,\" \",regex=True)\n\n        return ser.str.strip().tolist()\n\nclass VectorizedPostprocessor:\n\n    def postprocess_batch(self, texts):\n\n        s = pd.Series(texts).fillna(\"\").astype(str)\n\n        s = s.str.replace(_WS_RE,\" \",regex=True)\n\n        return s.str.strip().tolist()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.553254Z","iopub.status.idle":"2026-03-09T00:22:32.553604Z","shell.execute_reply.started":"2026-03-09T00:22:32.553409Z","shell.execute_reply":"2026-03-09T00:22:32.553430Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section4\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>4. Dataset and Batching</b></div>","metadata":{}},{"cell_type":"code","source":"class AkkadianDataset(Dataset):\n\n    def __init__(self, df, preprocessor, logger):\n\n        self.sample_ids = df[\"id\"].tolist()\n\n        proc = preprocessor.preprocess_batch(df[\"transliteration\"].tolist())\n\n        self.input_texts = [\n            \"translate Akkadian to English: \" + t\n            for t in proc\n        ]\n\n        logger.info(f\"Dataset size: {len(self.sample_ids)}\")\n\n    def __len__(self):\n        return len(self.sample_ids)\n\n    def __getitem__(self, idx):\n        return self.sample_ids[idx], self.input_texts[idx]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.554566Z","iopub.status.idle":"2026-03-09T00:22:32.554907Z","shell.execute_reply.started":"2026-03-09T00:22:32.554726Z","shell.execute_reply":"2026-03-09T00:22:32.554749Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section5\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>5. Model Wrapper</b></div>","metadata":{}},{"cell_type":"code","source":"class ModelWrapper:\n\n    def __init__(self, model_path, cfg, logger, label):\n\n        self.cfg = cfg\n        self.logger = logger\n        self.label = label\n\n        logger.info(f\"Loading {label}\")\n\n        self.tokenizer = AutoTokenizer.from_pretrained(model_path)\n\n        self.model = (\n            AutoModelForSeq2SeqLM\n            .from_pretrained(model_path)\n            .to(cfg.device)\n            .eval()\n        )\n\n    def collate(self, batch):\n\n        ids = [b[0] for b in batch]\n        texts = [b[1] for b in batch]\n\n        enc = self.tokenizer(\n            texts,\n            padding=True,\n            truncation=True,\n            max_length=self.cfg.max_input_length,\n            return_tensors=\"pt\"\n        )\n\n        return ids, enc\n\n\n    def generate_candidates(self, input_ids, mask):\n\n        cfg = self.cfg\n        B = input_ids.shape[0]\n\n        ctx = _bf16_ctx(cfg.device, cfg.use_bf16_amp)\n\n        with ctx:\n\n            beam_out = self.model.generate(\n                input_ids=input_ids,\n                attention_mask=mask,\n                num_beams=cfg.num_beams,\n                num_return_sequences=cfg.num_beam_cands,\n                do_sample=False,\n                max_new_tokens=cfg.max_new_tokens,\n                length_penalty=cfg.length_penalty,\n                repetition_penalty=cfg.repetition_penalty\n            )\n\n            beam_texts = self.tokenizer.batch_decode(\n                beam_out,\n                skip_special_tokens=True\n            )\n\n            samp_out = self.model.generate(\n                input_ids=input_ids,\n                attention_mask=mask,\n                do_sample=True,\n                num_return_sequences=cfg.num_sample_cands,\n                top_p=cfg.mbr_top_p,\n                temperature=cfg.mbr_temperature,\n                max_new_tokens=cfg.max_new_tokens\n            )\n\n            samp_texts = self.tokenizer.batch_decode(\n                samp_out,\n                skip_special_tokens=True\n            )\n\n        Rb = cfg.num_beam_cands\n        Rs = cfg.num_sample_cands\n\n        pools = []\n\n        for i in range(B):\n            pool = list(beam_texts[i * Rb:(i + 1) * Rb])\n            pool += list(samp_texts[i * Rs:(i + 1) * Rs])\n            pools.append(pool)\n\n        return pools\n            ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.556989Z","iopub.status.idle":"2026-03-09T00:22:32.557239Z","shell.execute_reply.started":"2026-03-09T00:22:32.557124Z","shell.execute_reply":"2026-03-09T00:22:32.557139Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section6\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>6. MBR Selection</b></div>","metadata":{}},{"cell_type":"code","source":"class MBRSelector:\n\n    def __init__(self,pool_cap=40):\n\n        self.metric=sacrebleu.metrics.CHRF(word_order=2)\n\n        self.pool_cap=pool_cap\n\n\n    def _score(self,a,b):\n\n        if not a or not b:\n            return 0\n\n        return self.metric.sentence_score(a,[b]).score\n\n\n    def pick(self,candidates):\n\n        candidates=list(dict.fromkeys(candidates))\n\n        candidates=candidates[:self.pool_cap]\n\n        if len(candidates)==1:\n            return candidates[0]\n\n        best=None\n        best_score=-1\n\n        for i,a in enumerate(candidates):\n\n            score=0\n\n            for j,b in enumerate(candidates):\n\n                if i!=j:\n                    score+=self._score(a,b)\n\n            score/=max(1,len(candidates)-1)\n\n            if score>best_score:\n                best_score=score\n                best=a\n\n        return best","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.558282Z","iopub.status.idle":"2026-03-09T00:22:32.558652Z","shell.execute_reply.started":"2026-03-09T00:22:32.558448Z","shell.execute_reply":"2026-03-09T00:22:32.558485Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section7\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>7. Inference Pipeline</b></div>","metadata":{}},{"cell_type":"code","source":"class EnsembleEngine:\n\n    def __init__(self, cfg, logger):\n\n        self.cfg = cfg\n        self.logger = logger\n\n        self.preprocessor = OptimizedPreprocessor()\n        self.postprocessor = VectorizedPostprocessor()\n\n        self.mbr = MBRSelector(cfg.mbr_pool_cap)\n\n\n    def run(self, test_df):\n\n        dataset = AkkadianDataset(\n            test_df,\n            self.preprocessor,\n            self.logger\n        )\n\n        wrapperA = ModelWrapper(\n            self.cfg.model_a_path,\n            self.cfg,\n            self.logger,\n            \"Model-A\"\n        )\n\n        wrapperB = ModelWrapper(\n            self.cfg.model_b_path,\n            self.cfg,\n            self.logger,\n            \"Model-B\"\n        )\n\n        loader = DataLoader(\n            dataset,\n            batch_size=self.cfg.batch_size,\n            shuffle=False,\n            collate_fn=wrapperA.collate\n        )\n\n        results = []\n\n        for ids, enc in tqdm(loader):\n\n            input_ids = enc.input_ids.to(self.cfg.device)\n            mask = enc.attention_mask.to(self.cfg.device)\n\n            batch_pools_A = wrapperA.generate_candidates(input_ids, mask)\n            batch_pools_B = wrapperB.generate_candidates(input_ids, mask)\n\n            for sid, poolA, poolB in zip(ids, batch_pools_A, batch_pools_B):\n\n                pool = poolA + poolB\n                pool = self.postprocessor.postprocess_batch(pool)\n\n                best = self.mbr.pick(pool)\n\n                if not best or not str(best).strip():\n                    best = \"The tablet is too damaged to translate.\"\n\n                results.append(best)\n\n        return results","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.560921Z","iopub.status.idle":"2026-03-09T00:22:32.561160Z","shell.execute_reply.started":"2026-03-09T00:22:32.561054Z","shell.execute_reply":"2026-03-09T00:22:32.561067Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id=\"section8\"></a>\n\n# <div style=\"text-align:center; border-radius:15px; padding:15px; font-size:115%; font-family:'Arial Black', Arial, sans-serif; text-shadow:2px 2px 5px rgba(0,0,0,0.7); background:linear-gradient(90deg, #1e3c72, #c31432); box-shadow:0 2px 5px rgba(0,0,0,0.3); color:white;\"><b>8. Run and Save Submission</b></div>","metadata":{}},{"cell_type":"code","source":"cfg = EnsembleMBRConfig()\n\nlogger = setup_logging(cfg.output_dir)\n\nprint(\"Device:\", cfg.device)\n\ntest_df = pd.read_csv(cfg.test_data_path)\n\nprint(\"Test size:\", len(test_df))\n\nengine = EnsembleEngine(cfg, logger)\ntranslations = engine.run(test_df)\n\nsubmission = pd.DataFrame({\n    \"id\": test_df[\"id\"],\n    \"translation\": translations\n})\n\noutput_path = \"/kaggle/working/submission.csv\"\nsubmission.to_csv(output_path, index=False)\n\nprint(\"\\nSubmission saved to:\", output_path)\n\nimport os\nprint(\"File exists:\", os.path.exists(output_path))\n\nprint(\"\\nFiles in /kaggle/working:\")\nprint(os.listdir(\"/kaggle/working\"))\n\nprint(\"\\nSubmission preview:\")\nprint(submission.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-09T00:22:32.561983Z","iopub.status.idle":"2026-03-09T00:22:32.562287Z","shell.execute_reply.started":"2026-03-09T00:22:32.562143Z","shell.execute_reply":"2026-03-09T00:22:32.562159Z"}},"outputs":[],"execution_count":null}]}