{"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":15232461,"datasetId":9745025,"databundleVersionId":16128963},{"sourceType":"datasetVersion","sourceId":14899351,"datasetId":9366631,"databundleVersionId":15763950},{"sourceType":"datasetVersion","sourceId":15278990,"datasetId":9773638,"databundleVersionId":16180026},{"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":"code","source":"#!/usr/bin/env python3\n\"\"\"\n4-model routed MBR submission script for the Deep Past Challenge.\n\nPinned to the current mixed48 replay winner in this repo:\n- variant = selective_public_safe\n- mixed48 local_raw = 35.63049489273052\n- source = reports/pool_dump_dev_mixed_short_long_proxy48_dualall_20260320_v1/replay_sweep_v3/sweep_summary.csv\n\nModel family:\n1. baseline_all: byt5-akkadian-mbr-v2 on all rows\n2. open34x_all: byt5-akkadian-optimized-34x on all rows\n3. main_3039: latest short expert on short rows\n4. long_3039: long expert on long rows\n\nVerified route/decode core:\n- route threshold = 400 bytes\n- default decode = rp 1.1, lp 1.0, early_stopping = True\n- long decode = max_new_tokens 416, min_length 64, rp 1.15, lp 1.2, early_stopping = True\n\nRuntime guards:\n1. Strict startup checks for all required model files.\n2. 4-row Kaggle public test fast-skip for save/run.\n3. Timeout watchdog degrades generation before notebook timeout.\n\nSelective postprocess:\n1. apply safe postprocess only to public branches: baseline_all + open34x_all\n2. keep expert branches main_3039 + long_3039 raw before MBR\n\"\"\"\n\nimport atexit\nimport gc\nimport logging\nimport math\nimport os\nimport re\nimport shutil\nimport statistics\nimport tempfile\nimport time\nfrom collections import Counter\nfrom dataclasses import dataclass\nfrom pathlib import Path\nfrom typing import Dict, List, Sequence\n\nimport pandas as pd\nimport torch\nfrom torch.utils.data import DataLoader, Dataset\nfrom tqdm.auto import tqdm\nfrom transformers import AutoModelForSeq2SeqLM, AutoTokenizer\n\ntry:\n    from contextlib import nullcontext\nexcept ImportError:\n    class nullcontext(object):\n        def __init__(self, enter_result=None):\n            self.enter_result = enter_result\n\n        def __enter__(self):\n            return self.enter_result\n\n        def __exit__(self, exc_type, exc_value, traceback):\n            return False\n\ntry:\n    import sacrebleu\nexcept ImportError:\n    class _Score(object):\n        def __init__(self, score):\n            self.score = float(score)\n\n    def _char_ngrams(text, n):\n        return Counter(text[i : i + n] for i in range(max(0, len(text) - n + 1)))\n\n    def _token_ngrams(tokens, n):\n        return Counter(tuple(tokens[i : i + n]) for i in range(max(0, len(tokens) - n + 1)))\n\n    class _FallbackCHRF(object):\n        def __init__(self, word_order=2):\n            self.word_order = word_order\n\n        def sentence_score(self, hyp, refs):\n            ref = refs[0] if refs else \"\"\n            scores = []\n            for n in range(1, 7):\n                hyp_ngrams = _char_ngrams(hyp, n)\n                ref_ngrams = _char_ngrams(ref, n)\n                if not hyp_ngrams or not ref_ngrams:\n                    continue\n                overlap = sum((hyp_ngrams & ref_ngrams).values())\n                precision = overlap / float(sum(hyp_ngrams.values()) or 1)\n                recall = overlap / float(sum(ref_ngrams.values()) or 1)\n                if precision + recall == 0.0:\n                    scores.append(0.0)\n                else:\n                    scores.append((2.0 * precision * recall) / (precision + recall))\n            return _Score(100.0 * (sum(scores) / float(len(scores) or 1)))\n\n    class _FallbackBLEU(object):\n        def __init__(self, effective_order=True):\n            self.effective_order = effective_order\n\n        def sentence_score(self, hyp, refs):\n            ref = refs[0] if refs else \"\"\n            hyp_tokens = hyp.split()\n            ref_tokens = ref.split()\n            if not hyp_tokens:\n                return _Score(0.0)\n            max_order = min(4, len(hyp_tokens)) if self.effective_order else 4\n            precisions = []\n            for n in range(1, max_order + 1):\n                hyp_ngrams = _token_ngrams(hyp_tokens, n)\n                ref_ngrams = _token_ngrams(ref_tokens, n)\n                total = float(sum(hyp_ngrams.values()) or 1.0)\n                overlap = float(sum((hyp_ngrams & ref_ngrams).values()))\n                precisions.append((overlap + 1.0) / (total + 1.0))\n            log_prec = sum(math.log(p) for p in precisions) / float(len(precisions) or 1)\n            bp = 1.0\n            if len(hyp_tokens) < len(ref_tokens):\n                bp = math.exp(1.0 - (len(ref_tokens) / float(len(hyp_tokens) or 1)))\n            return _Score(100.0 * bp * math.exp(log_prec))\n\n    class _MetricsCompat(object):\n        CHRF = _FallbackCHRF\n        BLEU = _FallbackBLEU\n\n    class _SacreBleuCompat(object):\n        metrics = _MetricsCompat()\n\n    sacrebleu = _SacreBleuCompat()\n\n\nos.environ.setdefault(\"OMP_NUM_THREADS\", \"4\")\nos.environ.setdefault(\"MKL_NUM_THREADS\", \"4\")\nos.environ.setdefault(\"TOKENIZERS_PARALLELISM\", \"true\")\n\nTMP_TOKENIZER_DIRS = []\nPROMPT_PREFIX = \"translate Akkadian to English: \"\nGLOBAL_START_TIME = time.time()\nTIMEOUT_THRESHOLD_SEC = float(os.getenv(\"AKK_TIMEOUT_THRESHOLD_SEC\", str(8.25 * 3600)))\nPUBLIC_SAFE_LABELS = {\"baseline_all\", \"open34x_all\"}\n\n\ndef cleanup_tmp_tokenizers():\n    for path in TMP_TOKENIZER_DIRS:\n        try:\n            shutil.rmtree(str(path), ignore_errors=True)\n        except Exception:\n            pass\n\n\natexit.register(cleanup_tmp_tokenizers)\n\n\ndef setup_logger():\n    logger = logging.getLogger(\"routed_4model_mbr\")\n    logger.setLevel(logging.INFO)\n    if not logger.handlers:\n        handler = logging.StreamHandler()\n        handler.setFormatter(logging.Formatter(\"%(asctime)s | %(levelname)s | %(message)s\"))\n        logger.addHandler(handler)\n    return logger\n\n\nLOGGER = setup_logger()\n\n\ndef is_time_running_out():\n    return (time.time() - GLOBAL_START_TIME) > TIMEOUT_THRESHOLD_SEC\n\n\ndef resolve_existing_path(candidates: Sequence[str]) -> str:\n    for path in candidates:\n        if path and Path(path).exists():\n            return path\n    return candidates[0]\n\n\ndef find_weight_file(model_dir: Path) -> Path:\n    for name in (\"model.safetensors\", \"pytorch_model.bin\", \"flax_model.msgpack\"):\n        candidate = model_dir / name\n        if candidate.exists():\n            return candidate\n    return model_dir / \"model.safetensors\"\n\n\ndef validate_model_dir(label: str, model_dir: str):\n    model_path = Path(model_dir)\n    missing = []\n    if not model_path.exists():\n        raise FileNotFoundError(\"{} directory is missing: {}\".format(label, model_path))\n    if not model_path.is_dir():\n        raise FileNotFoundError(\"{} is not a directory: {}\".format(label, model_path))\n\n    required_files = [\n        model_path / \"config.json\",\n        model_path / \"tokenizer_config.json\",\n        model_path / \"special_tokens_map.json\",\n    ]\n    for file_path in required_files:\n        if not file_path.exists():\n            missing.append(str(file_path))\n\n    weight_file = find_weight_file(model_path)\n    if not weight_file.exists():\n        missing.append(\n            \"{} (expected one of model.safetensors / pytorch_model.bin / flax_model.msgpack)\".format(model_path)\n        )\n\n    if missing:\n        raise FileNotFoundError(\n            \"{} is incomplete. Missing files: {}\".format(label, \" | \".join(missing))\n        )\n\n\n@dataclass(frozen=True)\nclass DecodeConfig:\n    max_new_tokens: int\n    min_length: int = 0\n    repetition_penalty: float = 1.0\n    length_penalty: float = 1.0\n    early_stopping: bool = True\n\n\n@dataclass\nclass KaggleConfig:\n    test_data_path: str = \"/kaggle/input/deep-past-initiative-machine-translation/test.csv\"\n    sample_sub_path: str = \"/kaggle/input/deep-past-initiative-machine-translation/sample_submission.csv\"\n    output_dir: str = \"/kaggle/working/\"\n    route_debug_path: str = \"/kaggle/working/route_debug.csv\"\n\n    baseline_model: str = \"\"\n    open_model: str = \"\"\n    main_model: str = \"\"\n    long_model: str = \"\"\n\n    route_threshold_bytes: int = 400\n    public_test_fast_skip_rows: int = 4\n    enable_public_test_fast_skip: bool = os.getenv(\"AKK_ENABLE_PUBLIC_TEST_FAST_SKIP\", \"1\").strip() != \"0\"\n    force_full_inference: bool = os.getenv(\"AKK_FORCE_FULL_INFERENCE\", \"0\").strip() == \"1\"\n    max_input_length: int = 512\n    batch_size: int = 2 if torch.cuda.is_available() else 1\n    num_workers: int = 2\n\n    default_max_new_tokens: int = 384\n    default_min_length: int = 0\n    default_repetition_penalty: float = 1.1\n    default_length_penalty: float = 1.0\n    default_early_stopping: bool = True\n\n    long_max_new_tokens: int = 416\n    long_min_length: int = 64\n    long_repetition_penalty: float = 1.15\n    long_length_penalty: float = 1.2\n    long_early_stopping: bool = True\n\n    num_beam_cands: int = 4\n    num_sample_cands: int = 8\n    mbr_pool_cap: int = 48\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(parents=True, exist_ok=True)\n        try:\n            self.use_bf16 = bool(self.device.type == \"cuda\" and torch.cuda.is_bf16_supported())\n        except Exception:\n            self.use_bf16 = False\n\n        baseline_candidates = [\n            os.getenv(\"AKK_BASELINE_MODEL_PATH\", \"\").strip(),\n            \"/kaggle/input/models/mattiaangeli/byt5-akkadian-mbr-v2/pytorch/default/1\",\n        ]\n        open_candidates = [\n            os.getenv(\"AKK_OPEN_MODEL_PATH\", \"\").strip(),\n            \"/kaggle/input/final-byt5/byt5-akkadian-optimized-34x\",\n        ]\n        main_candidates = [\n            os.getenv(\"AKK_MAIN_MODEL_PATH\", \"\").strip(),\n            \"/kaggle/input/datasets/bianfu/short-model-v2/rw00028_short_model_20260320\",\n            \"/kaggle/input/datasets/bianfu/2model-v1/main_model\",\n        ]\n        long_candidates = [\n            os.getenv(\"AKK_LONG_MODEL_PATH\", \"\").strip(),\n            \"/kaggle/input/datasets/bianfu/2model-v1/long_model\",\n        ]\n        self.baseline_model = resolve_existing_path([x for x in baseline_candidates if x])\n        self.open_model = resolve_existing_path([x for x in open_candidates if x])\n        self.main_model = resolve_existing_path([x for x in main_candidates if x])\n        self.long_model = resolve_existing_path([x for x in long_candidates if x])\n\n    def default_decode_cfg(self):\n        return DecodeConfig(\n            max_new_tokens=self.default_max_new_tokens,\n            min_length=self.default_min_length,\n            repetition_penalty=self.default_repetition_penalty,\n            length_penalty=self.default_length_penalty,\n            early_stopping=self.default_early_stopping,\n        )\n\n    def long_decode_cfg(self):\n        return DecodeConfig(\n            max_new_tokens=self.long_max_new_tokens,\n            min_length=self.long_min_length,\n            repetition_penalty=self.long_repetition_penalty,\n            length_penalty=self.long_length_penalty,\n            early_stopping=self.long_early_stopping,\n        )\n\n\n_GAP_UNIFIED_RE = re.compile(\n    r\"<\\s*big[\\s_\\-]*gap\\s*>|<\\s*gap\\s*>|\\bbig[\\s_\\-]*gap\\b|\\bx(?:\\s+x)+\\b|\\.{3,}|\\[\\.+\\]|\\[\\s*x\\s*\\]|\\(\\s*x\\s*\\)|(?<!\\w)x{2,}(?!\\w)|(?<!\\w)x(?!\\w)|\\(\\s*large\\s+break\\s*\\)|\\(\\s*break\\s*\\)\",\n    re.I,\n)\n_PN_RE = re.compile(r\"\\bPN\\b\")\n_SHEKEL_REPLS = [\n    (re.compile(r\"5\\s+11\\s*/\\s*12\\s+shekels?\", re.I), \"6 shekels less 15 grains\"),\n    (re.compile(r\"5\\s*/\\s*12\\s+shekels?\", re.I), \"1/3 shekel 15 grains\"),\n    (re.compile(r\"7\\s*/\\s*12\\s+shekels?\", re.I), \"1/2 shekel 15 grains\"),\n    (re.compile(r\"1\\s*/\\s*12\\s*(?:\\(shekel\\)|\\bshekel)?\", re.I), \"15 grains\"),\n]\n_EXACT_FRAC_RE = re.compile(r\"(?<![\\w/])(0\\.8333|0\\.6666|0\\.3333|0\\.1666|0\\.625|0\\.75|0\\.25|0\\.5)(?![\\w/])\")\n_EXACT_FRAC_MAP = {\n    \"0.8333\": \"5/6\",\n    \"0.6666\": \"2/3\",\n    \"0.3333\": \"1/3\",\n    \"0.1666\": \"1/6\",\n    \"0.625\": \"5/8\",\n    \"0.75\": \"3/4\",\n    \"0.25\": \"1/4\",\n    \"0.5\": \"1/2\",\n}\n_SOFT_GRAM_RE = re.compile(r\"\\(\\s*(?:fem|plur|pl|sing|singular|plural|\\?|\\!)(?:\\.\\s*(?:plur|plural|sing|singular))?\\.?\\s*[^)]*\\)\", re.I)\n_UNCERTAIN_RE = re.compile(r\"\\(\\?\\)\")\n_CURLY_DQ_RE = re.compile(\"[\\u201c\\u201d]\")\n_CURLY_SQ_RE = re.compile(\"[\\u2018\\u2019]\")\n_MONTH_RE = re.compile(r\"\\bMonth\\s+(XII|XI|X|IX|VIII|VII|VI|V|IV|III|II|I)\\b\", re.I)\n_ROMAN2INT = {\n    \"I\": 1,\n    \"II\": 2,\n    \"III\": 3,\n    \"IV\": 4,\n    \"V\": 5,\n    \"VI\": 6,\n    \"VII\": 7,\n    \"VIII\": 8,\n    \"IX\": 9,\n    \"X\": 10,\n    \"XI\": 11,\n    \"XII\": 12,\n}\n_STRAY_MARKS_RE = re.compile(r\"<<[^>]*>>|<(?!gap\\b)[^>]*>\")\n_WS_RE = re.compile(r\"\\s+\")\n_REPEAT_WORD_RE = re.compile(r\"\\b(\\w+)(?:\\s+\\1\\b)+\", re.I)\n\n\ndef _month_repl(match):\n    return \"Month {}\".format(_ROMAN2INT.get(match.group(1).upper(), match.group(1)))\n\n\nclass SafePostprocessor:\n    def process(self, text):\n        s = str(text or \"\")\n        s = _GAP_UNIFIED_RE.sub(\"<gap>\", s)\n        s = _PN_RE.sub(\"<gap>\", s)\n        for pattern, repl in _SHEKEL_REPLS:\n            s = pattern.sub(repl, s)\n        s = _EXACT_FRAC_RE.sub(lambda m: _EXACT_FRAC_MAP[m.group(1)], s)\n        s = _SOFT_GRAM_RE.sub(\" \", s)\n        s = _UNCERTAIN_RE.sub(\"\", s)\n        s = _STRAY_MARKS_RE.sub(\"\", s)\n        s = _CURLY_DQ_RE.sub('\"', s)\n        s = _CURLY_SQ_RE.sub(\"'\", s)\n        s = _MONTH_RE.sub(_month_repl, s)\n        s = s.replace(\"<gap>\", \" __GAP__ \")\n        s = _REPEAT_WORD_RE.sub(r\"\\1\", s)\n        for n in range(4, 1, -1):\n            s = re.sub(\n                r\"\\b((?:\\w+\\s+){\" + str(n - 1) + r\"}\\w+)(?:\\s+\\1\\b)+\",\n                r\"\\1\",\n                s,\n                flags=re.I,\n            )\n        s = s.replace(\" __GAP__ \", \"<gap>\")\n        return _WS_RE.sub(\" \", s).strip()\n\n\nclass LinearMBRSelector:\n    def __init__(self, pool_cap=48):\n        self.pool_cap = pool_cap\n        self._chrf = sacrebleu.metrics.CHRF(word_order=2)\n        self._bleu = sacrebleu.metrics.BLEU(effective_order=True)\n        self.w_chrf = 0.55\n        self.w_bleu = 0.25\n        self.w_jaccard = 0.20\n        self.w_length = 0.10\n        self._pw_total = self.w_chrf + self.w_bleu + self.w_jaccard\n\n    def _score(self, a, b):\n        if not a or not b:\n            return 0.0\n        chrf_val = float(self._chrf.sentence_score(a, [b]).score)\n        try:\n            bleu_val = float(self._bleu.sentence_score(a, [b]).score)\n        except Exception:\n            bleu_val = 0.0\n        ta = set(a.lower().split())\n        tb = set(b.lower().split())\n        if ta and tb:\n            jaccard_val = 100.0 * len(ta & tb) / len(ta | tb)\n        elif not ta and not tb:\n            jaccard_val = 100.0\n        else:\n            jaccard_val = 0.0\n        return (\n            self.w_chrf * chrf_val\n            + self.w_bleu * bleu_val\n            + self.w_jaccard * jaccard_val\n        ) / self._pw_total\n\n    def pick(self, candidates):\n        seen = set()\n        deduped = []\n        for cand in candidates:\n            cand = str(cand or \"\").strip()\n            if cand and cand not in seen:\n                seen.add(cand)\n                deduped.append(cand)\n        deduped = deduped[: self.pool_cap]\n        count = len(deduped)\n        if count == 0:\n            return \"The tablet is too damaged to translate.\"\n        if count == 1:\n            return deduped[0]\n\n        lengths = [len(x.split()) for x in deduped]\n        median_len = float(statistics.median(lengths))\n        sigma = max(median_len * 0.4, 5.0)\n\n        best_score = -1e9\n        best_text = deduped[0]\n        for idx, cand in enumerate(deduped):\n            pairwise = sum(self._score(cand, other) for j, other in enumerate(deduped) if j != idx) / max(1, count - 1)\n            z = (lengths[idx] - median_len) / sigma\n            length_bonus = 100.0 * math.exp(-0.5 * z * z)\n            final_score = pairwise + self.w_length * length_bonus\n            if final_score > best_score:\n                best_score = final_score\n                best_text = cand\n        return best_text\n\n\nclass AkkadianDataset(Dataset):\n    def __init__(self, df):\n        self.ids = df[\"id\"].tolist()\n        self.texts = [PROMPT_PREFIX + str(text) for text in df[\"transliteration\"].tolist()]\n\n    def __len__(self):\n        return len(self.ids)\n\n    def __getitem__(self, idx):\n        return self.ids[idx], self.texts[idx]\n\n\ndef safe_load_tokenizer(model_dir):\n    model_dir_path = Path(model_dir)\n    try:\n        return AutoTokenizer.from_pretrained(str(model_dir_path), local_files_only=True)\n    except Exception as exc:\n        if \"Non-consecutive added token\" not in str(exc):\n            raise\n\n    tmp_dir = Path(tempfile.mkdtemp(prefix=\"tokfix_\"))\n    TMP_TOKENIZER_DIRS.append(tmp_dir)\n    for item in model_dir_path.iterdir():\n        if item.name == \"added_tokens.json\":\n            continue\n        dst = tmp_dir / item.name\n        if item.is_dir():\n            shutil.copytree(str(item), str(dst))\n        else:\n            shutil.copy2(str(item), str(dst))\n    return AutoTokenizer.from_pretrained(str(tmp_dir), local_files_only=True)\n\n\ndef safe_load_model(model_dir):\n    model_dir_path = Path(model_dir)\n    try:\n        return AutoModelForSeq2SeqLM.from_pretrained(str(model_dir_path), local_files_only=True)\n    except OSError as exc:\n        flax_weights = model_dir_path / \"flax_model.msgpack\"\n        if flax_weights.exists() and \"Flax weights\" in str(exc):\n            return AutoModelForSeq2SeqLM.from_pretrained(\n                str(model_dir_path),\n                from_flax=True,\n                local_files_only=True,\n            )\n        raise\n\n\nclass SafeModelWrapper:\n    def __init__(self, model_path, cfg, label):\n        self.cfg = cfg\n        self.label = label\n        LOGGER.info(\"[%s] Loading %s\", label, model_path)\n        self.tokenizer = safe_load_tokenizer(model_path)\n        self.model = safe_load_model(model_path).to(cfg.device).eval()\n        if cfg.device.type == \"cuda\":\n            torch.cuda.empty_cache()\n            LOGGER.info(\"[%s] GPU allocated %.2f GB\", label, torch.cuda.memory_allocated() / 1e9)\n\n    def collate(self, batch):\n        ids = [item[0] for item in batch]\n        texts = [item[1] for item in batch]\n        enc = self.tokenizer(\n            texts,\n            max_length=self.cfg.max_input_length,\n            padding=True,\n            truncation=True,\n            return_tensors=\"pt\",\n        )\n        return ids, enc\n\n    def generate_candidates(self, input_ids, attention_mask, decode_cfg):\n        batch_size = input_ids.shape[0]\n        if self.cfg.use_bf16:\n            amp_ctx = torch.autocast(device_type=\"cuda\", dtype=torch.bfloat16)\n        else:\n            amp_ctx = nullcontext()\n\n        if is_time_running_out():\n            beam_cands = 1\n            sample_cands = 0\n            LOGGER.warning(\"[%s] timeout fallback: greedy-only mode\", self.label)\n        else:\n            beam_cands = self.cfg.num_beam_cands\n            sample_cands = self.cfg.num_sample_cands\n\n        pools = [[] for _ in range(batch_size)]\n        with amp_ctx:\n            beam_outputs = self.model.generate(\n                input_ids=input_ids,\n                attention_mask=attention_mask,\n                do_sample=False,\n                num_beams=max(4, beam_cands),\n                num_return_sequences=beam_cands,\n                max_new_tokens=decode_cfg.max_new_tokens,\n                min_length=decode_cfg.min_length,\n                repetition_penalty=decode_cfg.repetition_penalty,\n                length_penalty=decode_cfg.length_penalty,\n                early_stopping=decode_cfg.early_stopping,\n                use_cache=True,\n            )\n            beam_texts = self.tokenizer.batch_decode(beam_outputs, skip_special_tokens=True)\n            for idx in range(batch_size):\n                pools[idx].extend(beam_texts[idx * beam_cands : (idx + 1) * beam_cands])\n\n            if sample_cands > 0:\n                sample_outputs = self.model.generate(\n                    input_ids=input_ids,\n                    attention_mask=attention_mask,\n                    do_sample=True,\n                    top_p=0.9,\n                    temperature=0.8,\n                    num_beams=1,\n                    num_return_sequences=sample_cands,\n                    max_new_tokens=decode_cfg.max_new_tokens,\n                    min_length=decode_cfg.min_length,\n                    repetition_penalty=decode_cfg.repetition_penalty,\n                    early_stopping=decode_cfg.early_stopping,\n                    use_cache=True,\n                )\n                sample_texts = self.tokenizer.batch_decode(sample_outputs, skip_special_tokens=True)\n                for idx in range(batch_size):\n                    pools[idx].extend(sample_texts[idx * sample_cands : (idx + 1) * sample_cands])\n\n        return pools\n\n    def unload(self):\n        del self.model\n        del self.tokenizer\n        gc.collect()\n        if torch.cuda.is_available():\n            torch.cuda.empty_cache()\n            LOGGER.info(\"[%s] Unloaded\", self.label)\n\n\ndef utf8_len(text):\n    return len(str(text).encode(\"utf-8\"))\n\n\ndef process_subset(subset_df, model_path, label, decode_cfg, cfg, master_pools):\n    if subset_df.empty:\n        LOGGER.info(\"[%s] subset empty, skip\", label)\n        return\n    wrapper = SafeModelWrapper(model_path, cfg, label)\n    dataset = AkkadianDataset(subset_df)\n    loader = DataLoader(\n        dataset,\n        batch_size=cfg.batch_size,\n        shuffle=False,\n        num_workers=cfg.num_workers,\n        collate_fn=wrapper.collate,\n    )\n    try:\n        with torch.inference_mode():\n            for batch_ids, enc in tqdm(loader, desc=\"Generating {}\".format(label)):\n                input_ids = enc.input_ids.to(cfg.device)\n                attention_mask = enc.attention_mask.to(cfg.device)\n                batch_pools = wrapper.generate_candidates(input_ids, attention_mask, decode_cfg)\n                for sample_id, pool in zip(batch_ids, batch_pools):\n                    master_pools[str(sample_id)].extend(\n                        {\"label\": label, \"text\": str(text)}\n                        for text in pool\n                    )\n    finally:\n        wrapper.unload()\n\n\ndef write_route_debug(df, cfg):\n    route_df = df.copy()\n    route_df[\"route\"] = [\n        \"long_expert\" if src_len > cfg.route_threshold_bytes else \"short_expert\"\n        for src_len in route_df[\"src_len\"].tolist()\n    ]\n    route_df[\"baseline_model\"] = Path(cfg.baseline_model).name\n    route_df[\"open_model\"] = Path(cfg.open_model).name\n    route_df[\"main_model\"] = Path(cfg.main_model).name\n    route_df[\"long_model\"] = Path(cfg.long_model).name\n    route_df.to_csv(cfg.route_debug_path, index=False)\n    LOGGER.info(\"Route debug saved to %s\", cfg.route_debug_path)\n\n\ndef ensure_startup_files_exist(cfg):\n    required_paths = {\n        \"test_data_path\": cfg.test_data_path,\n        \"sample_sub_path\": cfg.sample_sub_path,\n    }\n    missing = []\n    for key, path_str in required_paths.items():\n        if not Path(path_str).exists():\n            missing.append(\"{}={}\".format(key, path_str))\n    if missing:\n        raise FileNotFoundError(\"Missing required startup files: {}\".format(\" | \".join(missing)))\n    validate_model_dir(\"baseline_model\", cfg.baseline_model)\n    validate_model_dir(\"open_model\", cfg.open_model)\n    validate_model_dir(\"main_model\", cfg.main_model)\n    validate_model_dir(\"long_model\", cfg.long_model)\n\n\ndef should_fast_skip_public_test(df, cfg):\n    if cfg.force_full_inference:\n        return False\n    if not cfg.enable_public_test_fast_skip:\n        return False\n    return len(df) == cfg.public_test_fast_skip_rows\n\n\ndef build_fast_skip_rows(df):\n    fallback_text = \"Public test fast-skip mode.\"\n    return [{\"id\": sample_id, \"translation\": fallback_text} for sample_id in df[\"id\"].tolist()]\n\n\ndef write_fast_skip_route_debug(df, cfg):\n    route_df = df.copy()\n    route_df[\"route\"] = \"public_test_fast_skip\"\n    route_df[\"baseline_model\"] = \"skipped\"\n    route_df[\"open_model\"] = \"skipped\"\n    route_df[\"main_model\"] = \"skipped\"\n    route_df[\"long_model\"] = \"skipped\"\n    route_df.to_csv(cfg.route_debug_path, index=False)\n    LOGGER.info(\"Fast-skip route debug saved to %s\", cfg.route_debug_path)\n\n\ndef run_pipeline():\n    cfg = KaggleConfig()\n    LOGGER.info(\"=\" * 60)\n    LOGGER.info(\"4-model routed MBR submission\")\n    LOGGER.info(\"device=%s bf16=%s\", cfg.device, cfg.use_bf16)\n    LOGGER.info(\"baseline=%s\", cfg.baseline_model)\n    LOGGER.info(\"open=%s\", cfg.open_model)\n    LOGGER.info(\"main=%s\", cfg.main_model)\n    LOGGER.info(\"long=%s\", cfg.long_model)\n    LOGGER.info(\"route threshold=%s bytes\", cfg.route_threshold_bytes)\n    LOGGER.info(\"timeout threshold sec=%s\", TIMEOUT_THRESHOLD_SEC)\n    LOGGER.info(\"=\" * 60)\n\n    ensure_startup_files_exist(cfg)\n    df = pd.read_csv(cfg.test_data_path)\n    if should_fast_skip_public_test(df, cfg):\n        LOGGER.warning(\n            \"Detected %d-row public test file. Fast-skip path enabled. Set AKK_FORCE_FULL_INFERENCE=1 to disable.\",\n            len(df),\n        )\n        out_path = Path(cfg.output_dir) / \"submission.csv\"\n        pd.DataFrame(build_fast_skip_rows(df)).to_csv(out_path, index=False)\n        write_fast_skip_route_debug(df, cfg)\n        LOGGER.info(\"submission saved to %s\", out_path)\n        return\n\n    df[\"src_len\"] = df[\"transliteration\"].apply(utf8_len)\n    short_df = df[df[\"src_len\"] <= cfg.route_threshold_bytes].copy()\n    long_df = df[df[\"src_len\"] > cfg.route_threshold_bytes].copy()\n\n    LOGGER.info(\"total=%d short=%d long=%d\", len(df), len(short_df), len(long_df))\n    write_route_debug(df, cfg)\n\n    master_pools = {str(sample_id): [] for sample_id in df[\"id\"].tolist()}\n\n    process_subset(df, cfg.baseline_model, \"baseline_all\", cfg.default_decode_cfg(), cfg, master_pools)\n    process_subset(df, cfg.open_model, \"open34x_all\", cfg.default_decode_cfg(), cfg, master_pools)\n    process_subset(short_df, cfg.main_model, \"main_3039\", cfg.default_decode_cfg(), cfg, master_pools)\n    process_subset(long_df, cfg.long_model, \"long_3039\", cfg.long_decode_cfg(), cfg, master_pools)\n\n    processor = SafePostprocessor()\n    mbr = LinearMBRSelector(pool_cap=cfg.mbr_pool_cap)\n    LOGGER.info(\"Selective safe labels=%s\", \",\".join(sorted(PUBLIC_SAFE_LABELS)))\n    final_rows = []\n    for sample_id in tqdm(df[\"id\"].tolist(), desc=\"MBR voting\"):\n        raw_pool = master_pools[str(sample_id)]\n        cleaned_pool = []\n        for entry in raw_pool:\n            if isinstance(entry, dict):\n                label = str(entry.get(\"label\", \"\"))\n                text = str(entry.get(\"text\", \"\"))\n            else:\n                label = \"\"\n                text = str(entry)\n            if label in PUBLIC_SAFE_LABELS:\n                cleaned_pool.append(processor.process(text))\n            else:\n                cleaned_pool.append(text.strip())\n        best = mbr.pick(cleaned_pool)\n        final_rows.append({\"id\": sample_id, \"translation\": best})\n\n    out_path = Path(cfg.output_dir) / \"submission.csv\"\n    pd.DataFrame(final_rows).to_csv(out_path, index=False)\n    LOGGER.info(\"submission saved to %s\", out_path)\n\n\nif __name__ == \"__main__\":\n    run_pipeline()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-19T18:59:51.101422Z","iopub.execute_input":"2026-03-19T18:59:51.101676Z","iopub.status.idle":"2026-03-19T18:59:51.146797Z","shell.execute_reply.started":"2026-03-19T18:59:51.101653Z","shell.execute_reply":"2026-03-19T18:59:51.146151Z"}},"outputs":[],"execution_count":null}]}