{ "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": { "8c1c7e4a6b8f47149ddca02e551f48a4": { "model_module": "@jupyter-widgets/controls", "model_name": "VBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "VBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "VBoxView", "box_style": "", "children": [ "IPY_MODEL_c2463a94b1fb44fa8196e7b61636c3b7", "IPY_MODEL_3040b325f55949fdbdc4caf75e9cd618", "IPY_MODEL_d9de6537b056464baa3dde45e81bbd72", "IPY_MODEL_dc8c33db5e814578a4aa9355132e132a" ], "layout": "IPY_MODEL_022ab2bdb55944858b48891baa414d3c" } }, "cdbbba5c25e64371a6678a34e1120dc5": { "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_5b364ad09e3d4158a728284f583616b3", "placeholder": "​", "style": "IPY_MODEL_3e894d7c8a3545c3886c340328d289a2", "value": "

Copy a token from your Hugging Face\ntokens page and paste it below.
Immediately click login after copying\nyour token or it might be stored in plain text in this notebook file.
" } }, "70a2cd0297a6456f8a1913c3037a08cd": { "model_module": "@jupyter-widgets/controls", "model_name": "PasswordModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "PasswordModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "PasswordView", "continuous_update": true, "description": "Token:", "description_tooltip": null, "disabled": false, "layout": "IPY_MODEL_f1b49e3bd1354e24bc911b2d2c7cfc7d", "placeholder": "​", "style": "IPY_MODEL_0c0fa6b93d144ddb8b9a4084dbaee2a4", "value": "" } }, "fe8a530f6c91441fb7f48b77e5e673fa": { "model_module": "@jupyter-widgets/controls", "model_name": "CheckboxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "CheckboxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "CheckboxView", "description": "Add token as git credential?", "description_tooltip": null, "disabled": false, "indent": true, "layout": "IPY_MODEL_f8bf8d132d774ab89cf258a7027b3557", "style": "IPY_MODEL_5d043f830b7f4981b0597136f1e530ed", "value": true } }, "9b84de3ec55a4035bf61621f80b0c374": { "model_module": "@jupyter-widgets/controls", "model_name": "ButtonModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ButtonModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ButtonView", "button_style": "", "description": "Login", "disabled": false, "icon": "", "layout": "IPY_MODEL_3f1f2f9baab74de890b2213d4846611d", "style": "IPY_MODEL_f3f7d114085d477692c4933876b8b5cc", "tooltip": "" } }, "0f044626ebca4e21b8e05a45dae2341d": { "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_a2ceb52d59634de6bf64f41b6f3da3a4", "placeholder": "​", "style": "IPY_MODEL_60dc766ea8734e3baa5df22506d8fcf6", "value": "\nPro Tip: If you don't already have one, you can create a dedicated\n'notebooks' token with 'write' access, that you can then easily reuse for all\nnotebooks. " } }, "022ab2bdb55944858b48891baa414d3c": { "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": "center", "align_self": null, "border": null, "bottom": null, "display": "flex", "flex": null, "flex_flow": "column", "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": "50%" } }, "5b364ad09e3d4158a728284f583616b3": { "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 } }, "3e894d7c8a3545c3886c340328d289a2": { "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": "" } }, "f1b49e3bd1354e24bc911b2d2c7cfc7d": { "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 } }, "0c0fa6b93d144ddb8b9a4084dbaee2a4": { "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": "" } }, "f8bf8d132d774ab89cf258a7027b3557": { "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 } }, "5d043f830b7f4981b0597136f1e530ed": { "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": "" } }, "3f1f2f9baab74de890b2213d4846611d": { "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 } }, "f3f7d114085d477692c4933876b8b5cc": { "model_module": "@jupyter-widgets/controls", "model_name": "ButtonStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ButtonStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "button_color": null, "font_weight": "" } }, "a2ceb52d59634de6bf64f41b6f3da3a4": { "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 } }, "60dc766ea8734e3baa5df22506d8fcf6": { "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": "" } }, "ca18786f952c4f3cbdb34b9a4ae5692e": { "model_module": "@jupyter-widgets/controls", "model_name": "LabelModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "LabelModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "LabelView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_2728eea9f200454d9dc5454385c963a2", "placeholder": "​", "style": "IPY_MODEL_109c14c8f5814ecb92f95409e349cfaf", "value": "Connecting..." } }, "2728eea9f200454d9dc5454385c963a2": { "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 } }, "109c14c8f5814ecb92f95409e349cfaf": { "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": "" } }, "c2463a94b1fb44fa8196e7b61636c3b7": { "model_module": "@jupyter-widgets/controls", "model_name": "LabelModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "LabelModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "LabelView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_973a3f8b019c47e5b96cdb867ec5bba2", "placeholder": "​", "style": "IPY_MODEL_d327dc625f514fb3977ac2949f092cb4", "value": "Token is valid (permission: write)." } }, "3040b325f55949fdbdc4caf75e9cd618": { "model_module": "@jupyter-widgets/controls", "model_name": "LabelModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "LabelModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "LabelView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_f147b05bc86e4aaabcac45e441ad23ea", "placeholder": "​", "style": "IPY_MODEL_4411d82338c244d8aa5a130356f61110", "value": "Your token has been saved in your configured git credential helpers (store)." } }, "d9de6537b056464baa3dde45e81bbd72": { "model_module": "@jupyter-widgets/controls", "model_name": "LabelModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "LabelModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "LabelView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_f6a31775093449928d7b6e5306ff0bc7", "placeholder": "​", "style": "IPY_MODEL_2ca22edaacc6426b886f554090b2c719", "value": "Your token has been saved to /root/.cache/huggingface/token" } }, "dc8c33db5e814578a4aa9355132e132a": { "model_module": "@jupyter-widgets/controls", "model_name": "LabelModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "LabelModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "LabelView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_626b5f225cee422da0de229fb9ac4622", "placeholder": "​", "style": "IPY_MODEL_8c87840632404771a42d21d251deae1e", "value": "Login successful" } }, "973a3f8b019c47e5b96cdb867ec5bba2": { "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 } }, "d327dc625f514fb3977ac2949f092cb4": { "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": "" } }, "f147b05bc86e4aaabcac45e441ad23ea": { "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 } }, "4411d82338c244d8aa5a130356f61110": { "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": "" } }, "f6a31775093449928d7b6e5306ff0bc7": { "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 } }, "2ca22edaacc6426b886f554090b2c719": { "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": "" } }, "626b5f225cee422da0de229fb9ac4622": { "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 } }, "8c87840632404771a42d21d251deae1e": { "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", "source": [ "# WiDS 2023: Language Translation Model\n", "This Jupyter notebook contains the code for the language translation model using a pre-trained Transformer based Neural Networks and NLP from Hugging face 🤗. It includes steps for fine-tuning the model on a specific dataset, preprocessing the data, training, and evaluating the model, ultimately providing a user interactive interface for language translation using Gradio." ], "metadata": { "id": "jd4hr9XpxEAT" } }, { "cell_type": "markdown", "source": [ "Initially, we establish a connection to the GPU to optimize the execution of our program, leveraging its capacity to efficiently process tasks involving substantial datasets." ], "metadata": { "id": "Tn-rAGS7zIPo" } }, { "cell_type": "code", "source": [ "#checking whether GPU is working or not\n", "!nvidia-smi" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "KrFSyiSTzGAu", "outputId": "6655d2e5-8c06-45df-9ebc-579726434678" }, "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Sat Jan 13 08:47:46 2024 \n", "+---------------------------------------------------------------------------------------+\n", "| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |\n", "|-----------------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|=========================================+======================+======================|\n", "| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n", "| N/A 74C P8 13W / 70W | 0MiB / 15360MiB | 0% Default |\n", "| | | N/A |\n", "+-----------------------------------------+----------------------+----------------------+\n", " \n", "+---------------------------------------------------------------------------------------+\n", "| Processes: |\n", "| GPU GI CI PID Type Process name GPU Memory |\n", "| ID ID Usage |\n", "|=======================================================================================|\n", "| No running processes found |\n", "+---------------------------------------------------------------------------------------+\n" ] } ] }, { "cell_type": "code", "source": [ "#installing all the necessary libraries\n", "! pip install -q transformers accelerate sentencepiece gradio datasets evaluate sacrebleu" ], "metadata": { "id": "1i5ye3v4zpOM" }, "execution_count": 2, "outputs": [] }, { "cell_type": "markdown", "source": [ "Importing all the necessary libaries and module." ], "metadata": { "id": "2QCou91X0DcV" } }, { "cell_type": "code", "source": [ "import evaluate\n", "import numpy as np\n", "from datasets import load_dataset\n", "from sklearn.model_selection import train_test_split\n", "from transformers import pipeline\n", "from transformers import AutoTokenizer\n", "from transformers import AutoModelForSeq2SeqLM\n", "from transformers import DataCollatorForSeq2Seq\n", "from transformers import Seq2SeqTrainingArguments\n", "from transformers import Seq2SeqTrainer\n", "from huggingface_hub import notebook_login" ], "metadata": { "id": "jI3MBl6R81Dq" }, "execution_count": 3, "outputs": [] }, { "cell_type": "markdown", "source": [ "We download the \"kde4\" dataset from Hugging Face, a curated dataset designed for language translation. It's essential to specify the two languages involved in the translation process when obtaining this dataset." ], "metadata": { "id": "AVnEuqQdXish" } }, { "cell_type": "code", "source": [ "raw_datasets = load_dataset(\"kde4\", lang1=\"en\", lang2=\"fr\")\n", "raw_datasets" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "0bazUZj5zvr8", "outputId": "d94cbfac-9410-4e8f-9145-0245ee86f920" }, "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_token.py:88: UserWarning: \n", "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", "You will be able to reuse this secret in all of your notebooks.\n", "Please note that authentication is recommended but still optional to access public models or datasets.\n", " warnings.warn(\n", "/usr/local/lib/python3.10/dist-packages/datasets/load.py:1429: FutureWarning: The repository for kde4 contains custom code which must be executed to correctly load the dataset. You can inspect the repository content at https://hf.co/datasets/kde4\n", "You can avoid this message in future by passing the argument `trust_remote_code=True`.\n", "Passing `trust_remote_code=True` will be mandatory to load this dataset from the next major release of `datasets`.\n", " warnings.warn(\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['id', 'translation'],\n", " num_rows: 210173\n", " })\n", "})" ] }, "metadata": {}, "execution_count": 4 } ] }, { "cell_type": "markdown", "source": [ "The dataset initially includes only a training set, but for a comprehensive evaluation of our model's performance, we need both training and testing sets. To achieve this, we employ the train_test_split function, effectively partitioning the dataset into distinct training and testing subsets for subsequent model assessment." ], "metadata": { "id": "7lCOOlj_0zAD" } }, { "cell_type": "code", "source": [ "split_datasets= raw_datasets[\"train\"].train_test_split(test_size=0.2, seed=20)\n", "split_datasets" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "qbrDvPe_0x5A", "outputId": "29166139-473f-4bc0-bc0c-8b39f36f6621" }, "execution_count": 5, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['id', 'translation'],\n", " num_rows: 168138\n", " })\n", " test: Dataset({\n", " features: ['id', 'translation'],\n", " num_rows: 42035\n", " })\n", "})" ] }, "metadata": {}, "execution_count": 5 } ] }, { "cell_type": "code", "source": [ "split_datasets[\"train\"][45][\"translation\"]" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5r2LDjjU1pAI", "outputId": "b2720a51-63b2-4595-d6df-0221ad52d4bf" }, "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{'en': 'If you choose the wrong settings here your articles could be unreadable or not sendable at all, so please be careful with these settings.',\n", " 'fr': 'Si vous choisissez ici les mauvais paramètres, vos articles peuvent devenir illisibles ou vous ne pourrez pas du tout les envoyer. Veuillez donc être prudent avec ces paramètres.'}" ] }, "metadata": {}, "execution_count": 6 } ] }, { "cell_type": "markdown", "source": [ "We will utilize a pre-trained model available on HuggingFace, specifically the Helsinki-NLP/opus-mt-en-fr model. This model has been pre-trained to facilitate translation tasks from English to French, and we will leverage its capabilities for our language translation project." ], "metadata": { "id": "pD-XEIQ41v2I" } }, { "cell_type": "code", "source": [ "model=\"Helsinki-NLP/opus-mt-en-fr\"\n", "translator=pipeline(\"translation\", model=model)\n", "translator(\"If you choose the wrong settings here your articles could be unreadable or not sendable at all, so please be careful with these settings.\")" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5QM1qTcQ2CT4", "outputId": "1eac8925-afe8-45cd-f263-fc9c900829a0" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/transformers/models/marian/tokenization_marian.py:197: UserWarning: Recommended: pip install sacremoses.\n", " warnings.warn(\"Recommended: pip install sacremoses.\")\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "[{'translation_text': \"Si vous choisissez les mauvais paramètres ici, vos articles pourraient être illisibles ou ne pas être envoyés du tout, alors s'il vous plaît soyez prudent avec ces paramètres.\"}]" ] }, "metadata": {}, "execution_count": 7 } ] }, { "cell_type": "markdown", "source": [ "The initial results from the pre-trained model demonstrate reasonably accurate translations. Further refinement through fine-tuning is expected to enhance the translation quality even more.\n", "\n", "Next, we employ the AutoTokenizer to apply the same tokenization scheme used in the pre-trained model to process the dataset." ], "metadata": { "id": "fxdJGwXv2WXt" } }, { "cell_type": "code", "source": [ "tokenizer=AutoTokenizer.from_pretrained(model, return_tensors=\"pt\")" ], "metadata": { "id": "2mh8dVZU2F_f" }, "execution_count": 8, "outputs": [] }, { "cell_type": "code", "source": [ "def pre_processtext(text):\n", " inputs=[sample['en'] for sample in text['translation']]\n", " output=[sample['fr'] for sample in text['translation']]\n", " tokenized_text=tokenizer(inputs, text_target=output, max_length=128, truncation=True) #(text_target because if not done it will tokenize the french sentence according to english and so the labels will then not be correct)\n", " return tokenized_text" ], "metadata": { "id": "UTXFIklN2fNN" }, "execution_count": 9, "outputs": [] }, { "cell_type": "code", "source": [ "tokenized_datasets=split_datasets.map(\n", " pre_processtext,\n", " batched=True,\n", " remove_columns=split_datasets[\"train\"].column_names #(to remove extra columns)\n", ")" ], "metadata": { "id": "9GZsxyhl2hUV" }, "execution_count": 10, "outputs": [] }, { "cell_type": "markdown", "source": [ "Following preprocessing, the next step involves selecting a model for training, and in this case, the choice is the AutoModelForSeq2SeqLM." ], "metadata": { "id": "jVfmONpU2s2B" } }, { "cell_type": "code", "source": [ "model_1= AutoModelForSeq2SeqLM.from_pretrained(model)" ], "metadata": { "id": "SjRCrAz62k6x" }, "execution_count": 11, "outputs": [] }, { "cell_type": "markdown", "source": [ "The data collator plays a crucial role, facilitating dynamic padding, appending -100 to short sentences for length matching, and incorporating a start-of-sentence token, visible in decoder_input_ids." ], "metadata": { "id": "gClhwDls2wzq" } }, { "cell_type": "code", "source": [ "data_collator=DataCollatorForSeq2Seq(tokenizer,model=model_1)" ], "metadata": { "id": "LwPGf4Xk25Ae" }, "execution_count": 12, "outputs": [] }, { "cell_type": "code", "source": [ "batch = data_collator([tokenized_datasets[\"train\"][i] for i in range(1,3)])\n", "print(batch.keys())\n", "print(batch['labels'])\n", "batch['decoder_input_ids']" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "tw6WhfZ_27aY", "outputId": "44512578-ae13-435f-84a1-def8441b4e42" }, "execution_count": 13, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "dict_keys(['input_ids', 'attention_mask', 'labels', 'decoder_input_ids'])\n", "tensor([[25966, 19, 540, 8, 669, 33355, 24, 11106, 37, 583,\n", " 583, 9507, 10571, 3, 49, 19015, 3, 49, 1937, 74,\n", " 2635, 973, 529, 13518, 74, 102, 0],\n", " [14743, 301, 548, 0, -100, -100, -100, -100, -100, -100,\n", " -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,\n", " -100, -100, -100, -100, -100, -100, -100]])\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "tensor([[59513, 25966, 19, 540, 8, 669, 33355, 24, 11106, 37,\n", " 583, 583, 9507, 10571, 3, 49, 19015, 3, 49, 1937,\n", " 74, 2635, 973, 529, 13518, 74, 102],\n", " [59513, 14743, 301, 548, 0, 59513, 59513, 59513, 59513, 59513,\n", " 59513, 59513, 59513, 59513, 59513, 59513, 59513, 59513, 59513, 59513,\n", " 59513, 59513, 59513, 59513, 59513, 59513, 59513]])" ] }, "metadata": {}, "execution_count": 13 } ] }, { "cell_type": "markdown", "source": [ "To assess our model, we employ the sacrebleu score, which focuses on word matching between translations and references. This metric doesn't scrutinize grammatical correctness but penalizes repetitive words not present in the original translation." ], "metadata": { "id": "FRw8bbhb3Ed7" } }, { "cell_type": "code", "source": [ "metric_evaluate= evaluate.load(\"sacrebleu\")" ], "metadata": { "id": "ofoatdSx29pn" }, "execution_count": 14, "outputs": [] }, { "cell_type": "code", "source": [ "def compute_metrics(eval):\n", " preds, labels= eval\n", " if isinstance(preds, tuple): #if model returns more than the prediction logits\n", " preds=preds[0]\n", " decoded_preds= tokenizer.batch_decode(preds, skip_special_tokens=True)\n", "\n", " labels=np.where(labels != -100, labels,tokenizer.pad_token_id) #replacing -100 as we will not be able to decode them\n", " decoded_labels=tokenizer.batch_decode(labels, skip_special_tokens=True)\n", "\n", " decoded_preds=[pred.strip() for pred in decoded_preds]\n", " decoded_labels=[[label.strip()] for label in decoded_labels] #references should be list of list of sentences\n", "\n", " result=metric_evaluate.compute(predictions=decoded_preds, references=decoded_labels)\n", " return {\"bleu\": result[\"score\"]}" ], "metadata": { "id": "73eZuhyD3KSx" }, "execution_count": 15, "outputs": [] }, { "cell_type": "markdown", "source": [ "To preserve my model, I'll utilize the Hugging Face repository. Let's proceed by logging into the Hugging Face platform." ], "metadata": { "id": "Rjiji2Zh3Pd-" } }, { "cell_type": "code", "source": [ "notebook_login()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 145, "referenced_widgets": [ "8c1c7e4a6b8f47149ddca02e551f48a4", "cdbbba5c25e64371a6678a34e1120dc5", "70a2cd0297a6456f8a1913c3037a08cd", "fe8a530f6c91441fb7f48b77e5e673fa", "9b84de3ec55a4035bf61621f80b0c374", "0f044626ebca4e21b8e05a45dae2341d", "022ab2bdb55944858b48891baa414d3c", "5b364ad09e3d4158a728284f583616b3", "3e894d7c8a3545c3886c340328d289a2", "f1b49e3bd1354e24bc911b2d2c7cfc7d", "0c0fa6b93d144ddb8b9a4084dbaee2a4", "f8bf8d132d774ab89cf258a7027b3557", "5d043f830b7f4981b0597136f1e530ed", "3f1f2f9baab74de890b2213d4846611d", "f3f7d114085d477692c4933876b8b5cc", "a2ceb52d59634de6bf64f41b6f3da3a4", "60dc766ea8734e3baa5df22506d8fcf6", "ca18786f952c4f3cbdb34b9a4ae5692e", "2728eea9f200454d9dc5454385c963a2", "109c14c8f5814ecb92f95409e349cfaf", "c2463a94b1fb44fa8196e7b61636c3b7", "3040b325f55949fdbdc4caf75e9cd618", "d9de6537b056464baa3dde45e81bbd72", "dc8c33db5e814578a4aa9355132e132a", "973a3f8b019c47e5b96cdb867ec5bba2", "d327dc625f514fb3977ac2949f092cb4", "f147b05bc86e4aaabcac45e441ad23ea", "4411d82338c244d8aa5a130356f61110", "f6a31775093449928d7b6e5306ff0bc7", "2ca22edaacc6426b886f554090b2c719", "626b5f225cee422da0de229fb9ac4622", "8c87840632404771a42d21d251deae1e" ] }, "id": "Rbk3-DTU3OuC", "outputId": "653cd2e8-4fb9-4495-9fe5-3d99673ac6cd" }, "execution_count": 16, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "VBox(children=(HTML(value='
" ], "text/html": [ "\n", "
\n", " \n", " \n", " [15765/15765 49:09, Epoch 3/3]\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StepTraining Loss
5001.365200
10001.226200
15001.156000
20001.108600
25001.084900
30001.033100
35001.020700
40001.009600
45000.994900
50000.972800
55000.921200
60000.869000
65000.847500
70000.862500
75000.847000
80000.845800
85000.854900
90000.845700
95000.847800
100000.848000
105000.834000
110000.762500
115000.764200
120000.767400
125000.765000
130000.770000
135000.757100
140000.756700
145000.762700
150000.766800
155000.751000

" ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "TrainOutput(global_step=15765, training_loss=0.9012604572793396, metrics={'train_runtime': 2950.8187, 'train_samples_per_second': 170.94, 'train_steps_per_second': 5.343, 'total_flos': 1.008207288336384e+16, 'train_loss': 0.9012604572793396, 'epoch': 3.0})" ] }, "metadata": {}, "execution_count": 19 } ] }, { "cell_type": "code", "source": [ "trainer.push_to_hub(tags=\"translation\", commit_message=\"Training complete\") #To save the latest model onto the repository" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 52 }, "id": "TnYcoiFLzU_f", "outputId": "b4080bed-d2f9-4e91-be88-0ae88d4a325e" }, "execution_count": 20, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/rajbhirud/eng-to-fra-model/commit/7dc6032cdedafc309f004b8d65493fbfe40fd5b7', commit_message='Training complete', commit_description='', oid='7dc6032cdedafc309f004b8d65493fbfe40fd5b7', pr_url=None, pr_revision=None, pr_num=None)" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 20 } ] }, { "cell_type": "code", "source": [ "# we can check the score of our model through the following code\n", "trainer.evaluate(max_length=128)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 141 }, "id": "mhf4dB0pzlA_", "outputId": "f92c5300-8f61-4f04-8a36-62d31028c467" }, "execution_count": 21, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", "

\n", " \n", " \n", " [657/657 45:14]\n", "
\n", " " ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "{'eval_loss': 0.8449926376342773,\n", " 'eval_bleu': 53.45040267621567,\n", " 'eval_runtime': 3010.6388,\n", " 'eval_samples_per_second': 13.962,\n", " 'eval_steps_per_second': 0.218,\n", " 'epoch': 3.0}" ] }, "metadata": {}, "execution_count": 21 } ] }, { "cell_type": "markdown", "source": [ "To observe the model's performance interactively, particularly in language translation, we can leverage Gradio. A ready-to-use script, \"gradio_eng_to_fra.py\", has been provided in the repository. Executing this file enables seamless integration with the Gradio interface, offering users an intuitive platform for language translation without the need for extensive coding." ], "metadata": { "id": "qtHmvt340FXh" } } ] }