{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "widgets": { "application/vnd.jupyter.widget-state+json": { "8a49fb7918744d23bf64237c2674fc6b": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_7a64e72d88084b6897d53c344aad4358", "IPY_MODEL_85b34cfea65c4a8dbdae30a8eec22a98", "IPY_MODEL_500b7fb2607c4eebbb5bea0bfc4e33ff" ], "layout": "IPY_MODEL_b53f4a68898e45098d6801e4987e4c10" } }, "7a64e72d88084b6897d53c344aad4358": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_008567f59c13464b82ca3946ccf0058c", "placeholder": "​", "style": "IPY_MODEL_6ac91c5649bc4b6fa0d3860e71cdb01b", "value": "Map: 100%" } }, "85b34cfea65c4a8dbdae30a8eec22a98": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_90bfdbd03ac44d5ca3df23ebcc02d863", "max": 74586, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_6618b65302df46098bd2ad029ed668eb", "value": 74586 } }, "500b7fb2607c4eebbb5bea0bfc4e33ff": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_a04d20d2b4934f35a7890f24546023d7", "placeholder": "​", "style": "IPY_MODEL_5f5df2985c6f49d3816888ec4ebd9add", "value": " 74586/74586 [00:44<00:00, 1302.29 examples/s]" } }, "b53f4a68898e45098d6801e4987e4c10": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "008567f59c13464b82ca3946ccf0058c": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "6ac91c5649bc4b6fa0d3860e71cdb01b": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "90bfdbd03ac44d5ca3df23ebcc02d863": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "6618b65302df46098bd2ad029ed668eb": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "a04d20d2b4934f35a7890f24546023d7": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "5f5df2985c6f49d3816888ec4ebd9add": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "419e345a9ff34dce965af89ad6569ff1": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_2f1473b2871b49f5b916298ab9866bd8", "IPY_MODEL_171e066c98944ad2abcad3f61d11144c", "IPY_MODEL_67c666a7cc8e4ae5a5c6c7442fdb8484" ], "layout": "IPY_MODEL_3eb3a35b6b2b414fa725a49e002da0e4" } }, "2f1473b2871b49f5b916298ab9866bd8": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_12e03166c7854af59078eb601478338a", "placeholder": "​", "style": "IPY_MODEL_9310394718a64134b5d17290db28f880", "value": "Map: 100%" } }, "171e066c98944ad2abcad3f61d11144c": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_c851e5be2363465981fa92285c6a9579", "max": 18647, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_3d2bdb8969cd45499c33a49ab73cab39", "value": 18647 } }, "67c666a7cc8e4ae5a5c6c7442fdb8484": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_5e584348fea147fb95649323af691ea9", "placeholder": "​", "style": "IPY_MODEL_20af10029189476d8f84badf52743b26", "value": " 18647/18647 [00:10<00:00, 1932.89 examples/s]" } }, "3eb3a35b6b2b414fa725a49e002da0e4": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "12e03166c7854af59078eb601478338a": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "9310394718a64134b5d17290db28f880": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "c851e5be2363465981fa92285c6a9579": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "3d2bdb8969cd45499c33a49ab73cab39": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "5e584348fea147fb95649323af691ea9": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "20af10029189476d8f84badf52743b26": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "cc5509c288034ce6939f574301fd5eb2": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_6eee983896f948f7919722045b190b01", "IPY_MODEL_114a72cf85334713aefd3ee3616ebeb2", "IPY_MODEL_4dfd352e599c4676b9871da14e8d75b5" ], "layout": "IPY_MODEL_efa7962c591e4b4bb6c54f008444bb0f" } }, "6eee983896f948f7919722045b190b01": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_0169ffddc6014c2ebf92ee902e198e1a", "placeholder": "​", "style": "IPY_MODEL_0e73212111294bdda9c79b97696aaa48", "value": "Downloading builder script: " } }, "114a72cf85334713aefd3ee3616ebeb2": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_6cf0f639236040b9ab8bc84665a1e94a", "max": 1, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_ab1eb221a83e4e7299e5fe1056cbf4b8", "value": 1 } }, "4dfd352e599c4676b9871da14e8d75b5": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_d13fccbfd59c43f687edb2aa0bdd6145", "placeholder": "​", "style": "IPY_MODEL_06c209127feb497bb2e171d229183f16", "value": " 8.15k/? [00:00<00:00, 561kB/s]" } }, "efa7962c591e4b4bb6c54f008444bb0f": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "0169ffddc6014c2ebf92ee902e198e1a": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "0e73212111294bdda9c79b97696aaa48": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "6cf0f639236040b9ab8bc84665a1e94a": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "20px" } }, "ab1eb221a83e4e7299e5fe1056cbf4b8": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "d13fccbfd59c43f687edb2aa0bdd6145": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": 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, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "06c209127feb497bb2e171d229183f16": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } } } } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "source": [ "# Fine-Tuning mT5 for English → German Translation\n", "\n", "This notebook fine-tunes **`google/mt5-small`** on the **WMT16 En→De** dataset using Hugging Face Transformers.\n", "\n", "- Model: Multilingual T5 (mT5) – pre-trained on 101 languages **without supervised translation**\n", "- Task: Teach it **high-quality English to German translation** via fine-tuning\n", "- Dataset: WMT16 (via `datasets` library)\n", "- Framework: `transformers` + `seq2seq` Trainer\n", "\n", "---" ], "metadata": { "id": "XnxaVxCe8gjQ" } }, { "cell_type": "markdown", "source": [ "## 1. Install Dependencies" ], "metadata": { "id": "P05w2JE68gjR" } }, { "cell_type": "code", "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "3-EOS45xALKJ", "outputId": "7b790ea5-c852-4688-9189-91a725c6be72" }, "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Mounted at /content/drive\n" ] } ] }, { "cell_type": "code", "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m51.8/51.8 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m104.1/104.1 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m84.1/84.1 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } ], "source": [ "!pip install -q transformers datasets sentencepiece sacrebleu accelerate evaluate\n", "!pip install -q torch --index-url https://download.pytorch.org/whl/cu118" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "tBzChq5L8gjR", "outputId": "264ac5a0-a9ef-4f49-a5be-6045a15181f6" } }, { "cell_type": "code", "source": [ "!pip install pandas" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "1O0iGKJ7A6yW", "outputId": "4194b26b-9090-4444-866f-b86e7058179b" }, "execution_count": 5, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (2.2.2)\n", "Requirement already satisfied: numpy>=1.26.0 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.0.2)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n", "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n" ] } ] }, { "cell_type": "markdown", "source": [ "## 2. Load Dataset (WMT16 En→De)" ], "metadata": { "id": "_niqDW2e8gjS" } }, { "cell_type": "code", "source": [ "import gdown\n", "import json\n", "\n", "data_path = \"/content/drive/MyDrive/llm-translator/parallel_corpus.json\" # Adjust path\n", "try:\n", " with open(data_path, \"r\", encoding=\"utf-8\") as file:\n", " data = json.load(file)\n", " print(f\"Loaded {len(data)} entries from parallel_corpus.json\")\n", "except FileNotFoundError:\n", " print(f\"Error: The file '{data_path}' was not found.\")\n", " exit(1)\n", "except json.JSONDecodeError:\n", " print(\"Error: Failed to decode JSON from the file.\")\n", " exit(1)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "ds1obOiM8gjT", "outputId": "25f14e99-d3fb-491b-c9c8-7807e8d2b6f5" }, "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Loaded 31192 entries from parallel_corpus.json\n" ] } ] }, { "cell_type": "code", "source": [ "import string\n", "import pandas as pd\n", "from datasets import Dataset, DatasetDict\n", "\n", "\n", "# Build the three language pairs exactly as you did\n", "def is_valid(t): return bool(t and t.strip() and t.strip() not in string.punctuation)\n", "df = pd.DataFrame(data)\n", "breton_df = df[df.apply(lambda r: is_valid(r[\"niv_text\"]) and is_valid(r[\"koad21_text\"]), axis=1)][[\"niv_text\",\"koad21_text\"]].rename(columns={\"niv_text\":\"en\",\"koad21_text\":\"target\"})\n", "breton_df[\"language\"] = \"br\"\n", "cornish_df = df[df.apply(lambda r: is_valid(r[\"niv_text\"]) and is_valid(r[\"abk_text\"]), axis=1)][[\"niv_text\",\"abk_text\"]].rename(columns={\"niv_text\":\"en\",\"abk_text\":\"target\"})\n", "cornish_df[\"language\"] = \"abk\"\n", "welsh_df = df[df.apply(lambda r: is_valid(r[\"niv_text\"]) and is_valid(r[\"bcnda_text\"]), axis=1)][[\"niv_text\",\"bcnda_text\"]].rename(columns={\"niv_text\":\"en\",\"bcnda_text\":\"target\"})\n", "welsh_df[\"language\"] = \"cy\"\n", "\n", "\n", "combined_df = pd.concat([breton_df, cornish_df, welsh_df], ignore_index=True)\n", "print(combined_df.head(5))\n", "dataset = Dataset.from_pandas(combined_df).train_test_split(test_size=0.2, seed=42)\n", "print(f\"Combined dataset size: {len(combined_df)} pairs (Breton: {len(breton_df)}, Cornish: {len(cornish_df)}, Welsh: {len(welsh_df)})\")\n", "\n", "raw_datasets = DatasetDict({\n", " \"train\": dataset[\"train\"],\n", " \"test\" : dataset[\"test\"]\n", "})\n", "print(f\"Train: {len(raw_datasets['train'])}, Test: {len(raw_datasets['test'])}\")\n", "print(raw_datasets['train'])" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "jbv3mVHMAdZT", "outputId": "f42a3f59-4be9-46f3-fc9d-80f4614cbf3f" }, "execution_count": 10, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " en \\\n", "0 The Lord called to Moses and spoke to him from... \n", "1 “Speak to the Israelites and say to them: ‘Whe... \n", "2 “ ‘If the offering is a burnt offering from th... \n", "3 You are to lay your hand on the head of the bu... \n", "4 You are to slaughter the young bull before the... \n", "\n", " target language \n", "0 An AOTROU a c’halvas Moizez hag a gomzas dezha... br \n", "1 Komz da vibien Israel ha lavar: Pa raio unan b... br \n", "2 Mar d-eo e brof ul loskaberzh a loened bras, e... br \n", "3 Lakaat a raio e zorn war benn al loskaberzh, a... br \n", "4 Lazhañ a raio ar c’hole dirak an AOTROU ; an a... br \n", "Combined dataset size: 93233 pairs (Breton: 31077, Cornish: 31086, Welsh: 31070)\n", "Train: 74586, Test: 18647\n", "Dataset({\n", " features: ['en', 'target', 'language'],\n", " num_rows: 74586\n", "})\n" ] } ] }, { "cell_type": "markdown", "source": [ "## 3. Load Model & Tokenizer" ], "metadata": { "id": "920INjs88gjT" } }, { "cell_type": "code", "source": [ "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n", "\n", "model_name = \"t5-small\"\n", "tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)\n", "model = AutoModelForSeq2SeqLM.from_pretrained(model_name)\n", "\n", "# mT5 uses SentencePiece – no fast tokenizer available" ], "metadata": { "id": "7XvJ2Sl38gjT" }, "execution_count": 11, "outputs": [] }, { "cell_type": "markdown", "source": [ "## 4. Preprocess Function" ], "metadata": { "id": "H-cPZfJj8gjU" } }, { "cell_type": "code", "source": [ "max_input_length = 128\n", "max_target_length = 128\n", "\n", "def preprocess(examples):\n", " inputs = [f\"translate English to {lang}: {en}\"\n", " for lang, en in zip(examples[\"language\"], examples[\"en\"])]\n", " targets = examples[\"target\"]\n", " model_inputs = tokenizer(inputs, max_length=max_input_length,\n", " truncation=True, padding=\"max_length\")\n", " labels = tokenizer(targets, max_length=max_target_length,\n", " truncation=True, padding=\"max_length\").input_ids\n", " model_inputs[\"labels\"] = labels\n", " return model_inputs\n", "\n" ], "metadata": { "id": "eY7-UjaE8gjU" }, "execution_count": 13, "outputs": [] }, { "cell_type": "code", "source": [ "# Apply preprocessing\n", "print(\"Tokenising …\")\n", "print(raw_datasets)\n", "tokenized_datasets = raw_datasets.map(preprocess,\n", " batched=True,\n", " remove_columns=raw_datasets[\"train\"].column_names)\n", "\n", "print(tokenized_datasets)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 456, "referenced_widgets": [ "8a49fb7918744d23bf64237c2674fc6b", "7a64e72d88084b6897d53c344aad4358", "85b34cfea65c4a8dbdae30a8eec22a98", "500b7fb2607c4eebbb5bea0bfc4e33ff", "b53f4a68898e45098d6801e4987e4c10", "008567f59c13464b82ca3946ccf0058c", "6ac91c5649bc4b6fa0d3860e71cdb01b", "90bfdbd03ac44d5ca3df23ebcc02d863", "6618b65302df46098bd2ad029ed668eb", "a04d20d2b4934f35a7890f24546023d7", "5f5df2985c6f49d3816888ec4ebd9add", "419e345a9ff34dce965af89ad6569ff1", "2f1473b2871b49f5b916298ab9866bd8", "171e066c98944ad2abcad3f61d11144c", "67c666a7cc8e4ae5a5c6c7442fdb8484", "3eb3a35b6b2b414fa725a49e002da0e4", "12e03166c7854af59078eb601478338a", "9310394718a64134b5d17290db28f880", "c851e5be2363465981fa92285c6a9579", "3d2bdb8969cd45499c33a49ab73cab39", "5e584348fea147fb95649323af691ea9", "20af10029189476d8f84badf52743b26" ] }, "id": "HVO9qHXZ8gjV", "outputId": "0a5edd95-149e-4596-abc3-2668b500f7b1" }, "execution_count": 14, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Tokenising …\n", "DatasetDict({\n", " train: Dataset({\n", " features: ['en', 'target', 'language'],\n", " num_rows: 74586\n", " })\n", " test: Dataset({\n", " features: ['en', 'target', 'language'],\n", " num_rows: 18647\n", " })\n", "})\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "Map: 0%| | 0/74586 [00:00" ], "text/html": [ "\n", "
\n", " \n", " \n", " [ 136/13986 42:16 < 72:48:56, 0.05 it/s, Epoch 0.03/3]\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EpochTraining LossValidation Loss

" ] }, "metadata": {} }, { "output_type": "error", "ename": "KeyboardInterrupt", "evalue": "", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/tmp/ipython-input-4032920361.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtrainer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/trainer.py\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)\u001b[0m\n\u001b[1;32m 2323\u001b[0m \u001b[0mhf_hub_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0menable_progress_bars\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2324\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2325\u001b[0;31m return inner_training_loop(\n\u001b[0m\u001b[1;32m 2326\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2327\u001b[0m \u001b[0mresume_from_checkpoint\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mresume_from_checkpoint\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/trainer.py\u001b[0m in \u001b[0;36m_inner_training_loop\u001b[0;34m(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)\u001b[0m\n\u001b[1;32m 2672\u001b[0m )\n\u001b[1;32m 2673\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2674\u001b[0;31m \u001b[0mtr_loss_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtraining_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum_items_in_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2675\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2676\u001b[0m if (\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/trainer.py\u001b[0m in \u001b[0;36mtraining_step\u001b[0;34m(***failed resolving arguments***)\u001b[0m\n\u001b[1;32m 4069\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"scale_wrt_gas\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4070\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4071\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maccelerator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4072\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4073\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdetach\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/accelerate/accelerator.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(self, loss, **kwargs)\u001b[0m\n\u001b[1;32m 2738\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlomo_backward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlearning_rate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2739\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2740\u001b[0;31m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2741\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2742\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mset_trigger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/_tensor.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(self, gradient, retain_graph, create_graph, inputs)\u001b[0m\n\u001b[1;32m 645\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 646\u001b[0m )\n\u001b[0;32m--> 647\u001b[0;31m torch.autograd.backward(\n\u001b[0m\u001b[1;32m 648\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgradient\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mretain_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 649\u001b[0m )\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/autograd/__init__.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)\u001b[0m\n\u001b[1;32m 352\u001b[0m \u001b[0;31m# some Python versions print out the first line of a multi-line function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 353\u001b[0m \u001b[0;31m# calls in the traceback and some print out the last line\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 354\u001b[0;31m _engine_run_backward(\n\u001b[0m\u001b[1;32m 355\u001b[0m \u001b[0mtensors\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 356\u001b[0m \u001b[0mgrad_tensors_\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/autograd/graph.py\u001b[0m in \u001b[0;36m_engine_run_backward\u001b[0;34m(t_outputs, *args, **kwargs)\u001b[0m\n\u001b[1;32m 827\u001b[0m \u001b[0munregister_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_register_logging_hooks_on_whole_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt_outputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 828\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 829\u001b[0;31m return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass\n\u001b[0m\u001b[1;32m 830\u001b[0m \u001b[0mt_outputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 831\u001b[0m ) # Calls into the C++ engine to run the backward pass\n", "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] } ] }, { "cell_type": "markdown", "source": [ "## 9. Inference Example" ], "metadata": { "id": "7NiOt4SY8gjW" } }, { "cell_type": "code", "source": [ "text = \"Hello, how are you today? I hope you're doing well.\"\n", "\n", "inputs = tokenizer(text, return_tensors=\"pt\").to(model.device)\n", "generated_ids = model.generate(\n", " inputs[\"input_ids\"],\n", " max_length=128,\n", " num_beams=5,\n", " early_stopping=True\n", ")\n", "print(generated_ids)\n", "translation = tokenizer.decode(generated_ids[0], skip_special_tokens=True)\n", "print(\"English:\", text)\n", "print(\"German:\", translation)" ], "metadata": { "id": "YKCXr6Ap8gjW" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "## 10. Save Model (Optional)" ], "metadata": { "id": "Y_nlerIE8gjW" } }, { "cell_type": "code", "source": [ "import os\n", "\n", "os.makedirs(final_dir, exist_ok=True)\n", "\n", "trainer.save_model(final_dir)\n", "tokenizer.save_pretrained(final_dir)\n", "print(f\"SAVED TO DRIVE: {final_dir}\")\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "guMiVDeT8gjW", "outputId": "1ab58e4d-2dd6-441b-ef48-bec14a4a445e" }, "execution_count": 34, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "('./mt5-en-de-finetuned/tokenizer_config.json',\n", " './mt5-en-de-finetuned/special_tokens_map.json',\n", " './mt5-en-de-finetuned/spiece.model',\n", " './mt5-en-de-finetuned/added_tokens.json')" ] }, "metadata": {}, "execution_count": 34 } ] }, { "cell_type": "markdown", "source": [ "---\n", "\n", "**Done!** You now have a fine-tuned mT5 model for **English → German** translation.\n", "\n", "To adapt to **any other language**, just change:\n", "- `wmt16` → another dataset (e.g., `opus100`, `flores200`)\n", "- `source_lang`, `target_lang` keys\n", "- Dataset name in `load_dataset()`\n", "\n", "Let me know if you want a version for **low-resource languages** (e.g., Swahili, Quechua)!" ], "metadata": { "id": "4RwTey1F8gjW" } } ] }