Anish13 commited on
Commit
8bbb79e
ยท
verified ยท
1 Parent(s): 2c7879e

Upload copy-of-unit4-1 (1).ipynb

Browse files
Files changed (1) hide show
  1. copy-of-unit4-1 (1).ipynb +1 -0
copy-of-unit4-1 (1).ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"accelerator":"GPU","colab":{"provenance":[],"collapsed_sections":["BPLwsPajb1f8","L_WSo0VUV99t","mjY-eq3eWh9O","JoTC9o2SczNn","x62pP0PHdA-y"],"gpuType":"T4"},"widgets":{"application/vnd.jupyter.widget-state+json":{"28119533120c4595a31e13fab5dcb97d":{"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_0775c017861845efa934dc7d6149d221","IPY_MODEL_7989b07a863f4383934fe7ed0903658e","IPY_MODEL_27d869b037f94c2fbb914876e346c118"],"layout":"IPY_MODEL_7de189f08d3e4b5db2a44dc182e79d7e"}},"0775c017861845efa934dc7d6149d221":{"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_11fe33de898d4b19bc8b3ebe737ef5ed","placeholder":"โ€‹","style":"IPY_MODEL_e09537e88867428ab7a6992e10ec77d6","value":"model.pt:โ€‡100%"}},"7989b07a863f4383934fe7ed0903658e":{"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_f9cdd3b7d68a4e82b9e98d6e3dd87183","max":3264,"min":0,"orientation":"horizontal","style":"IPY_MODEL_95c3279bd69b436092073186b9313ae8","value":3264}},"27d869b037f94c2fbb914876e346c118":{"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_268df11068fc451a8310e229318a9cfd","placeholder":"โ€‹","style":"IPY_MODEL_c9fb622fbdba4b63b6c3dafc39a916ce","value":"โ€‡3.26k/3.26kโ€‡[00:00&lt;00:00,โ€‡19.7kB/s]"}},"7de189f08d3e4b5db2a44dc182e79d7e":{"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}},"11fe33de898d4b19bc8b3ebe737ef5ed":{"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}},"e09537e88867428ab7a6992e10ec77d6":{"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":""}},"f9cdd3b7d68a4e82b9e98d6e3dd87183":{"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}},"95c3279bd69b436092073186b9313ae8":{"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":""}},"268df11068fc451a8310e229318a9cfd":{"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}},"c9fb622fbdba4b63b6c3dafc39a916ce":{"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":""}},"18d34bd634cf49849812778ce46d6db0":{"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":[],"layout":"IPY_MODEL_c1320b6f80b04f71a0e03c4909e59940"}},"f201d5a775af4946827895215bf822bc":{"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_ed8451f203ac4ea1a3a2897b139f46d5","placeholder":"โ€‹","style":"IPY_MODEL_62356dff90f44a7a90f063f9facff457","value":"<center> <img\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.svg\nalt='Hugging Face'> <br> Copy a token from <a\nhref=\"https://huggingface.co/settings/tokens\" target=\"_blank\">your Hugging Face\ntokens page</a> and paste it below. <br> Immediately click login after copying\nyour token or it might be stored in plain text in this notebook file. </center>"}},"fd85a618a03f438da4ac9b19eda777ba":{"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_b2f43eb0cfda4ae88e20d380aad711cf","placeholder":"โ€‹","style":"IPY_MODEL_b2bb36ffe34f494a811eff587b0f1834","value":""}},"699364a499904296b63878a4531f2eb1":{"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_dccfe2431bf4460d9262a2d8650c5f20","style":"IPY_MODEL_e2915c3e083143e1822f990cbc837fc5","value":false}},"450382dce34b4e5f9e479387484ecace":{"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_5d2505175dce4d2ebbae612af271b93b","style":"IPY_MODEL_0668087c715745b6aeb0cd618b917b8e","tooltip":""}},"34b6565d6ed24ea795a92956a8db6017":{"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_14e99f4ce2e14cdebd6c7c2a1306603d","placeholder":"โ€‹","style":"IPY_MODEL_e847d4725ed1472c9ecc8710c0c26ae8","value":"\n<b>Pro Tip:</b> 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. </center>"}},"c1320b6f80b04f71a0e03c4909e59940":{"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%"}},"ed8451f203ac4ea1a3a2897b139f46d5":{"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}},"62356dff90f44a7a90f063f9facff457":{"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":""}},"b2f43eb0cfda4ae88e20d380aad711cf":{"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}},"b2bb36ffe34f494a811eff587b0f1834":{"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":""}},"dccfe2431bf4460d9262a2d8650c5f20":{"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}},"e2915c3e083143e1822f990cbc837fc5":{"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":""}},"5d2505175dce4d2ebbae612af271b93b":{"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}},"0668087c715745b6aeb0cd618b917b8e":{"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":""}},"14e99f4ce2e14cdebd6c7c2a1306603d":{"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}},"e847d4725ed1472c9ecc8710c0c26ae8":{"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":""}},"520893b1710f45f69840ead1cb5c0cec":{"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_a166a338a8674bfeaf26fd2925534f56","placeholder":"โ€‹","style":"IPY_MODEL_df1fd92758dd4a2b96b34e576e120bb2","value":"Connecting..."}},"a166a338a8674bfeaf26fd2925534f56":{"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}},"df1fd92758dd4a2b96b34e576e120bb2":{"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":""}}}},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[],"dockerImageVersionId":31012,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Unit 4: Code your first Deep Reinforcement Learning Algorithm with PyTorch: Reinforce. And test its robustness ๐Ÿ’ช\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/unit6/thumbnail.png\" alt=\"thumbnail\"/>\n\n\nIn this notebook, you'll code your first Deep Reinforcement Learning algorithm from scratch: Reinforce (also called Monte Carlo Policy Gradient).\n\nReinforce is a *Policy-based method*: a Deep Reinforcement Learning algorithm that tries **to optimize the policy directly without using an action-value function**.\n\nMore precisely, Reinforce is a *Policy-gradient method*, a subclass of *Policy-based methods* that aims **to optimize the policy directly by estimating the weights of the optimal policy using gradient ascent**.\n\nTo test its robustness, we're going to train it in 2 different simple environments:\n- Cartpole-v1\n- PixelcopterEnv\n\nโฌ‡๏ธ Here is an example of what **you will achieve at the end of this notebook.** โฌ‡๏ธ","metadata":{"id":"CjRWziAVU2lZ"}},{"cell_type":"markdown","source":" <img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/unit6/envs.gif\" alt=\"Environments\"/>\n","metadata":{"id":"s4rBom2sbo7S"}},{"cell_type":"markdown","source":"### ๐ŸŽฎ Environments:\n\n- [CartPole-v1](https://www.gymlibrary.dev/environments/classic_control/cart_pole/)\n- [PixelCopter](https://pygame-learning-environment.readthedocs.io/en/latest/user/games/pixelcopter.html)\n\n### ๐Ÿ“š RL-Library:\n\n- Python\n- PyTorch\n\n\nWe're constantly trying to improve our tutorials, so **if you find some issues in this notebook**, please [open an issue on the GitHub Repo](https://github.com/huggingface/deep-rl-class/issues).","metadata":{"id":"BPLwsPajb1f8"}},{"cell_type":"markdown","source":"## Objectives of this notebook ๐Ÿ†\nAt the end of the notebook, you will:\n- Be able to **code from scratch a Reinforce algorithm using PyTorch.**\n- Be able to **test the robustness of your agent using simple environments.**\n- Be able to **push your trained agent to the Hub** with a nice video replay and an evaluation score ๐Ÿ”ฅ.","metadata":{"id":"L_WSo0VUV99t"}},{"cell_type":"markdown","source":"## This notebook is from the Deep Reinforcement Learning Course\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/notebooks/deep-rl-course-illustration.jpg\" alt=\"Deep RL Course illustration\"/>","metadata":{"id":"lEPrZg2eWa4R"}},{"cell_type":"markdown","source":"In this free course, you will:\n\n- ๐Ÿ“– Study Deep Reinforcement Learning in **theory and practice**.\n- ๐Ÿง‘โ€๐Ÿ’ป Learn to **use famous Deep RL libraries** such as Stable Baselines3, RL Baselines3 Zoo, CleanRL and Sample Factory 2.0.\n- ๐Ÿค– Train **agents in unique environments**\n\nAnd more check ๐Ÿ“š the syllabus ๐Ÿ‘‰ https://simoninithomas.github.io/deep-rl-course\n\nDonโ€™t forget to **<a href=\"http://eepurl.com/ic5ZUD\">sign up to the course</a>** (we are collecting your email to be able toย **send you the links when each Unit is published and give you information about the challenges and updates).**\n\n\nThe best way to keep in touch is to join our discord server to exchange with the community and with us ๐Ÿ‘‰๐Ÿป https://discord.gg/ydHrjt3WP5","metadata":{"id":"6p5HnEefISCB"}},{"cell_type":"markdown","source":"## Prerequisites ๐Ÿ—๏ธ\nBefore diving into the notebook, you need to:\n\n๐Ÿ”ฒ ๐Ÿ“š [Study Policy Gradients by reading Unit 4](https://huggingface.co/deep-rl-course/unit4/introduction)","metadata":{"id":"mjY-eq3eWh9O"}},{"cell_type":"markdown","source":"# Let's code Reinforce algorithm from scratch ๐Ÿ”ฅ\n\n\nTo validate this hands-on for the certification process, you need to push your trained models to the Hub.\n\n- Get a result of >= 350 for `Cartpole-v1`.\n- Get a result of >= 5 for `PixelCopter`.\n\nTo find your result, go to the leaderboard and find your model, **the result = mean_reward - std of reward**. **If you don't see your model on the leaderboard, go at the bottom of the leaderboard page and click on the refresh button**.\n\nFor more information about the certification process, check this section ๐Ÿ‘‰ https://huggingface.co/deep-rl-course/en/unit0/introduction#certification-process\n","metadata":{"id":"Bsh4ZAamchSl"}},{"cell_type":"markdown","source":"## An advice ๐Ÿ’ก\nIt's better to run this colab in a copy on your Google Drive, so that **if it timeouts** you still have the saved notebook on your Google Drive and do not need to fill everything from scratch.\n\nTo do that you can either do `Ctrl + S` or `File > Save a copy in Google Drive.`","metadata":{"id":"JoTC9o2SczNn"}},{"cell_type":"markdown","source":"## Set the GPU ๐Ÿ’ช\n- To **accelerate the agent's training, we'll use a GPU**. To do that, go to `Runtime > Change Runtime type`\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/notebooks/gpu-step1.jpg\" alt=\"GPU Step 1\">","metadata":{"id":"PU4FVzaoM6fC"}},{"cell_type":"markdown","source":"- `Hardware Accelerator > GPU`\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/notebooks/gpu-step2.jpg\" alt=\"GPU Step 2\">","metadata":{"id":"KV0NyFdQM9ZG"}},{"cell_type":"markdown","source":"## Create a virtual display ๐Ÿ–ฅ\n\nDuring the notebook, we'll need to generate a replay video. To do so, with colab, **we need to have a virtual screen to be able to render the environment** (and thus record the frames).\n\nHence the following cell will install the librairies and create and run a virtual screen ๐Ÿ–ฅ","metadata":{"id":"bTpYcVZVMzUI"}},{"cell_type":"code","source":"%%capture\n!apt install python-opengl\n!apt install ffmpeg\n!apt install xvfb\n!pip install pyvirtualdisplay\n!pip install pyglet==1.5.1","metadata":{"id":"jV6wjQ7Be7p5","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:21:34.912648Z","iopub.execute_input":"2025-04-24T21:21:34.912926Z","iopub.status.idle":"2025-04-24T21:21:46.807451Z","shell.execute_reply.started":"2025-04-24T21:21:34.912898Z","shell.execute_reply":"2025-04-24T21:21:46.806535Z"}},"outputs":[],"execution_count":25},{"cell_type":"code","source":"# Virtual display\nfrom pyvirtualdisplay import Display\n\nvirtual_display = Display(visible=0, size=(1400, 900))\nvirtual_display.start()","metadata":{"id":"Sr-Nuyb1dBm0","colab":{"base_uri":"https://localhost:8080/"},"outputId":"d0c7df72-ad34-4050-c227-846c170264c6","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:21:46.809000Z","iopub.execute_input":"2025-04-24T21:21:46.809294Z","iopub.status.idle":"2025-04-24T21:21:46.891038Z","shell.execute_reply.started":"2025-04-24T21:21:46.809260Z","shell.execute_reply":"2025-04-24T21:21:46.890274Z"}},"outputs":[{"execution_count":26,"output_type":"execute_result","data":{"text/plain":"<pyvirtualdisplay.display.Display at 0x7edf68aea050>"},"metadata":{}}],"execution_count":26},{"cell_type":"markdown","source":"## Install the dependencies ๐Ÿ”ฝ\nThe first step is to install the dependencies. Weโ€™ll install multiple ones:\n\n- `gym`\n- `gym-games`: Extra gym environments made with PyGame.\n- `huggingface_hub`: ๐Ÿค— works as a central place where anyone can share and explore models and datasets. It has versioning, metrics, visualizations, and other features that will allow you to easily collaborate with others.\n\nYou may be wondering why we install gym and not gymnasium, a more recent version of gym? **Because the gym-games we are using are not updated yet with gymnasium**.\n\nThe differences you'll encounter here:\n- In `gym` we don't have `terminated` and `truncated` but only `done`.\n- In `gym` using `env.step()` returns `state, reward, done, info`\n\nYou can learn more about the differences between Gym and Gymnasium here ๐Ÿ‘‰ https://gymnasium.farama.org/content/migration-guide/\n\n\nYou can see here all the Reinforce models available ๐Ÿ‘‰ https://huggingface.co/models?other=reinforce\n\nAnd you can find all the Deep Reinforcement Learning models here ๐Ÿ‘‰ https://huggingface.co/models?pipeline_tag=reinforcement-learning\n","metadata":{"id":"tjrLfPFIW8XK"}},{"cell_type":"code","source":"!pip install -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt","metadata":{"id":"e8ZVi-uydpgL","colab":{"base_uri":"https://localhost:8080/"},"outputId":"834a28df-0e44-40e1-a84e-d24787872c2b","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:21:49.628234Z","iopub.execute_input":"2025-04-24T21:21:49.628718Z","iopub.status.idle":"2025-04-24T21:21:55.534209Z","shell.execute_reply.started":"2025-04-24T21:21:49.628694Z","shell.execute_reply":"2025-04-24T21:21:55.533471Z"}},"outputs":[{"name":"stdout","text":"Collecting git+https://github.com/ntasfi/PyGame-Learning-Environment.git (from -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 1))\n Cloning https://github.com/ntasfi/PyGame-Learning-Environment.git to /tmp/pip-req-build-a75tb8_f\n Running command git clone --filter=blob:none --quiet https://github.com/ntasfi/PyGame-Learning-Environment.git /tmp/pip-req-build-a75tb8_f\n Resolved https://github.com/ntasfi/PyGame-Learning-Environment.git to commit 3dbe79dc0c35559bb441b9359948aabf9bb3d331\n Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\nCollecting git+https://github.com/simoninithomas/gym-games (from -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2))\n Cloning https://github.com/simoninithomas/gym-games to /tmp/pip-req-build-jzkhu8pj\n Running command git clone --filter=blob:none --quiet https://github.com/simoninithomas/gym-games /tmp/pip-req-build-jzkhu8pj\n Resolved https://github.com/simoninithomas/gym-games to commit f31695e4ba028400628dc054ee8a436f28193f0b\n Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\nRequirement already satisfied: huggingface_hub in /usr/local/lib/python3.11/dist-packages (from -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (0.30.2)\nRequirement already satisfied: imageio-ffmpeg in /usr/local/lib/python3.11/dist-packages (from -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 4)) (0.6.0)\nRequirement already satisfied: pyyaml==6.0 in /usr/local/lib/python3.11/dist-packages (from -r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 5)) (6.0)\nRequirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (from ple==0.0.1->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 1)) (1.23.5)\nRequirement already satisfied: Pillow in /usr/local/lib/python3.11/dist-packages (from ple==0.0.1->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 1)) (11.1.0)\nRequirement already satisfied: gym>=0.13.0 in /usr/local/lib/python3.11/dist-packages (from gym-games==1.0.4->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2)) (0.25.2)\nRequirement already satisfied: setuptools>=65.5.1 in /usr/local/lib/python3.11/dist-packages (from gym-games==1.0.4->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2)) (75.1.0)\nRequirement already satisfied: pygame>=1.9.6 in /usr/local/lib/python3.11/dist-packages (from gym-games==1.0.4->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2)) (2.6.1)\nRequirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (3.18.0)\nRequirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (2025.3.2)\nRequirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (24.2)\nRequirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (2.32.3)\nRequirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (4.67.1)\nRequirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (4.13.1)\nRequirement already satisfied: cloudpickle>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from gym>=0.13.0->gym-games==1.0.4->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2)) (3.1.1)\nRequirement already satisfied: gym_notices>=0.0.4 in /usr/local/lib/python3.11/dist-packages (from gym>=0.13.0->gym-games==1.0.4->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 2)) (0.0.8)\nRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (3.4.1)\nRequirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (3.10)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (2.3.0)\nRequirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface_hub->-r https://raw.githubusercontent.com/huggingface/deep-rl-class/main/notebooks/unit4/requirements-unit4.txt (line 3)) (2025.1.31)\n","output_type":"stream"}],"execution_count":27},{"cell_type":"markdown","source":"## Import the packages ๐Ÿ“ฆ\nIn addition to import the installed libraries, we also import:\n\n- `imageio`: A library that will help us to generate a replay video\n\n","metadata":{"id":"AAHAq6RZW3rn"}},{"cell_type":"code","source":"import numpy as np\n\nfrom collections import deque\n\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\n# PyTorch\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\nfrom torch.distributions import Categorical\n\n# Gym\nimport gym\nimport gym_pygame\n\n# Hugging Face Hub\nfrom huggingface_hub import notebook_login # To log to our Hugging Face account to be able to upload models to the Hub.\nimport imageio","metadata":{"id":"V8oadoJSWp7C","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:21:56.165561Z","iopub.execute_input":"2025-04-24T21:21:56.166196Z","iopub.status.idle":"2025-04-24T21:21:56.173096Z","shell.execute_reply.started":"2025-04-24T21:21:56.166171Z","shell.execute_reply":"2025-04-24T21:21:56.172279Z"}},"outputs":[],"execution_count":28},{"cell_type":"markdown","source":"## Check if we have a GPU\n\n- Let's check if we have a GPU\n- If it's the case you should see `device:cuda0`","metadata":{"id":"RfxJYdMeeVgv"}},{"cell_type":"code","source":"device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")","metadata":{"id":"kaJu5FeZxXGY","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:01.285769Z","iopub.execute_input":"2025-04-24T21:22:01.286059Z","iopub.status.idle":"2025-04-24T21:22:01.289949Z","shell.execute_reply.started":"2025-04-24T21:22:01.286036Z","shell.execute_reply":"2025-04-24T21:22:01.289014Z"}},"outputs":[],"execution_count":29},{"cell_type":"code","source":"print(device)","metadata":{"id":"U5TNYa14aRav","colab":{"base_uri":"https://localhost:8080/"},"outputId":"b5745489-c354-4b3c-89e2-6e48feebd233","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:01.506213Z","iopub.execute_input":"2025-04-24T21:22:01.506418Z","iopub.status.idle":"2025-04-24T21:22:01.510884Z","shell.execute_reply.started":"2025-04-24T21:22:01.506404Z","shell.execute_reply":"2025-04-24T21:22:01.509911Z"}},"outputs":[{"name":"stdout","text":"cuda:0\n","output_type":"stream"}],"execution_count":30},{"cell_type":"markdown","source":"We're now ready to implement our Reinforce algorithm ๐Ÿ”ฅ","metadata":{"id":"PBPecCtBL_pZ"}},{"cell_type":"markdown","source":"# First agent: Playing CartPole-v1 ๐Ÿค–","metadata":{"id":"8KEyKYo2ZSC-"}},{"cell_type":"markdown","source":"## Create the CartPole environment and understand how it works\n### [The environment ๐ŸŽฎ](https://www.gymlibrary.dev/environments/classic_control/cart_pole/)\n","metadata":{"id":"haLArKURMyuF"}},{"cell_type":"markdown","source":"### Why do we use a simple environment like CartPole-v1?\nAs explained in [Reinforcement Learning Tips and Tricks](https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html), when you implement your agent from scratch you need **to be sure that it works correctly and find bugs with easy environments before going deeper**. Since finding bugs will be much easier in simple environments.\n\n\n> Try to have some โ€œsign of lifeโ€ on toy problems\n\n\n> Validate the implementation by making it run on harder and harder envs (you can compare results against the RL zoo). You usually need to run hyperparameter optimization for that step.\n___\n### The CartPole-v1 environment\n\n> A pole is attached by an un-actuated joint to a cart, which moves along a frictionless track. The pendulum is placed upright on the cart and the goal is to balance the pole by applying forces in the left and right direction on the cart.\n\n\n\nSo, we start with CartPole-v1. The goal is to push the cart left or right **so that the pole stays in the equilibrium.**\n\nThe episode ends if:\n- The pole Angle is greater than ยฑ12ยฐ\n- Cart Position is greater than ยฑ2.4\n- Episode length is greater than 500\n\nWe get a reward ๐Ÿ’ฐ of +1 every timestep the Pole stays in the equilibrium.","metadata":{"id":"AH_TaLKFXo_8"}},{"cell_type":"code","source":"env_id = \"CartPole-v1\"\n# Create the env\nenv = gym.make(env_id)\n\n# Create the evaluation env\neval_env = gym.make(env_id)\n\n# Get the state space and action space\ns_size = env.observation_space.shape[0]\na_size = env.action_space.n","metadata":{"id":"POOOk15_K6KA","colab":{"base_uri":"https://localhost:8080/"},"outputId":"f1477325-285e-49d8-85b8-2c6e0e65b6cb"},"outputs":[{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.11/dist-packages/gym/core.py:317: DeprecationWarning: \u001b[33mWARN: Initializing wrapper in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.\u001b[0m\n"," deprecation(\n","/usr/local/lib/python3.11/dist-packages/gym/wrappers/step_api_compatibility.py:39: DeprecationWarning: \u001b[33mWARN: Initializing environment in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.\u001b[0m\n"," deprecation(\n"]}],"execution_count":null},{"cell_type":"code","source":"print(\"_____OBSERVATION SPACE_____ \\n\")\nprint(\"The State Space is: \", s_size)\nprint(\"Sample observation\", env.observation_space.sample()) # Get a random observation","metadata":{"id":"FMLFrjiBNLYJ","colab":{"base_uri":"https://localhost:8080/"},"outputId":"97285224-725c-43f6-9cb2-3efc04198d51"},"outputs":[{"output_type":"stream","name":"stdout","text":["_____OBSERVATION SPACE_____ \n","\n","The State Space is: 4\n","Sample observation [-2.4656408e+00 -1.9462213e+38 -2.6063386e-01 8.4515411e+37]\n"]}],"execution_count":null},{"cell_type":"code","source":"print(\"\\n _____ACTION SPACE_____ \\n\")\nprint(\"The Action Space is: \", a_size)\nprint(\"Action Space Sample\", env.action_space.sample()) # Take a random action","metadata":{"id":"Lu6t4sRNNWkN","colab":{"base_uri":"https://localhost:8080/"},"outputId":"cbffe825-2f57-4eec-b055-5b613e15807f"},"outputs":[{"output_type":"stream","name":"stdout","text":["\n"," _____ACTION SPACE_____ \n","\n","The Action Space is: 2\n","Action Space Sample 1\n"]}],"execution_count":null},{"cell_type":"markdown","source":"## Let's build the Reinforce Architecture\nThis implementation is based on two implementations:\n- [PyTorch official Reinforcement Learning example](https://github.com/pytorch/examples/blob/main/reinforcement_learning/reinforce.py)\n- [Udacity Reinforce](https://github.com/udacity/deep-reinforcement-learning/blob/master/reinforce/REINFORCE.ipynb)\n- [Improvement of the integration by Chris1nexus](https://github.com/huggingface/deep-rl-class/pull/95)\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/unit6/reinforce.png\" alt=\"Reinforce\"/>","metadata":{"id":"7SJMJj3WaFOz"}},{"cell_type":"markdown","source":"So we want:\n- Two fully connected layers (fc1 and fc2).\n- Using ReLU as activation function of fc1\n- Using Softmax to output a probability distribution over actions","metadata":{"id":"49kogtxBODX8"}},{"cell_type":"code","source":"class Policy(nn.Module):\n def __init__(self, s_size, a_size, h_size):\n super(Policy, self).__init__()\n # Create two fully connected layers\n self.fc1 = nn.Linear(s_size, h_size)\n self.fc2 = nn.Linear(h_size, a_size)\n\n def forward(self, x):\n # Define the forward pass\n # state goes to fc1 then we apply ReLU activation function\n x = self.fc1(x)\n x = F.relu(x)\n # state goes to fc2\n x = self.fc2(x)\n # We output the softmax\n return F.softmax(x, dim=1)\n\n def act(self, state):\n \"\"\"\n Given a state, take action\n \"\"\"\n state = torch.from_numpy(state).float().unsqueeze(0).to(device)\n probs = self.forward(state).cpu()\n m = Categorical(probs)\n action = m.sample() # stochastic: sample from distribution\n return action.item(), m.log_prob(action)","metadata":{"id":"w2LHcHhVZvPZ"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"debug_policy = Policy(s_size, a_size, 64).to(device)\ndebug_policy.act(env.reset())","metadata":{"id":"lwnqGBCNePor","colab":{"base_uri":"https://localhost:8080/"},"outputId":"3e6175d0-44dc-411f-a0ac-a2c300e5c4c4"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["(1, tensor([-0.8403], grad_fn=<SqueezeBackward1>))"]},"metadata":{},"execution_count":72}],"execution_count":null},{"cell_type":"markdown","source":"By using CartPole, it was easier to debug since **we know that the bug comes from our integration and not from our simple environment**.","metadata":{"id":"rgJWQFU_eUYw"}},{"cell_type":"markdown","source":"- Since **we want to sample an action from the probability distribution over actions**, we can't use `action = np.argmax(m)` since it will always output the action that have the highest probability.\n\n- We need to replace with `action = m.sample()` that will sample an action from the probability distribution P(.|s)","metadata":{"id":"c-20i7Pk0l1T"}},{"cell_type":"markdown","source":"### Let's build the Reinforce Training Algorithm\nThis is the Reinforce algorithm pseudocode:\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/unit6/pg_pseudocode.png\" alt=\"Policy gradient pseudocode\"/>\n ","metadata":{"id":"4MXoqetzfIoW"}},{"cell_type":"markdown","source":"- When we calculate the return Gt (line 6) we see that we calculate the sum of discounted rewards **starting at timestep t**.\n\n- Why? Because our policy should only **reinforce actions on the basis of the consequences**: so rewards obtained before taking an action are useless (since they were not because of the action), **only the ones that come after the action matters**.\n\n- Before coding this you should read this section [don't let the past distract you](https://spinningup.openai.com/en/latest/spinningup/rl_intro3.html#don-t-let-the-past-distract-you) that explains why we use reward-to-go policy gradient.\n\nWe use an interesting technique coded by [Chris1nexus](https://github.com/Chris1nexus) to **compute the return at each timestep efficiently**. The comments explained the procedure. Don't hesitate also [to check the PR explanation](https://github.com/huggingface/deep-rl-class/pull/95)\nBut overall the idea is to **compute the return at each timestep efficiently**.\n\n","metadata":{"id":"QmcXG-9i2Qu2"}},{"cell_type":"markdown","source":"# Line7\nAveraging (or summing) the return G_t from one trajectory multiplied by the log probability of the corresponding action a_t\n\n# Line8\nLooking at each action in the trajectory\n\n- Seeing how good the return was that followed it (i.e., how good the outcome of that decision was)\n\n- Then adjusting the policy so that:\n\n- Good actions become more likely\n\n- Bad actions become less likely","metadata":{"id":"IJohLo9zo2BY"}},{"cell_type":"markdown","source":"The second question you may ask is **why do we minimize the loss**? You talked about Gradient Ascent not Gradient Descent?\n\n- We want to maximize our utility function $J(\\theta)$ but in PyTorch like in Tensorflow it's better to **minimize an objective function.**\n - So let's say we want to reinforce action 3 at a certain timestep. Before training this action P is 0.25.\n - So we want to modify $\\theta$ such that $\\pi_\\theta(a_3|s; \\theta) > 0.25$\n - Because all P must sum to 1, max $\\pi_\\theta(a_3|s; \\theta)$ will **minimize other action probability.**\n - So we should tell PyTorch **to min $1 - \\pi_\\theta(a_3|s; \\theta)$.**\n - This loss function approaches 0 as $\\pi_\\theta(a_3|s; \\theta)$ nears 1.\n - So we are encouraging the gradient to max $\\pi_\\theta(a_3|s; \\theta)$\n","metadata":{"id":"O554nUGPpcoq"}},{"cell_type":"code","source":"def reinforce(policy, optimizer, n_training_episodes, max_t, gamma, print_every):\n # Help us to calculate the score during the training\n scores_deque = deque(maxlen=100)\n scores = []\n # Line 3 of pseudocode\n for i_episode in range(1, n_training_episodes+1):\n saved_log_probs = []\n rewards = []\n state = env.reset()# TODO: reset the environment\n # Line 4 of pseudocode\n for t in range(max_t):\n action, log_prob = policy.act(state) # TODO get the action\n saved_log_probs.append(log_prob)\n state, reward, done, _ = env.step(action) # TODO: take an env step\n rewards.append(reward)\n if done:\n break\n scores_deque.append(sum(rewards))\n scores.append(sum(rewards))\n\n # Line 6 of pseudocode: calculate the return\n returns = deque(maxlen=max_t)\n n_steps = len(rewards)\n # Compute the discounted returns at each timestep,\n # as the sum of the gamma-discounted return at time t (G_t) + the reward at time t\n\n # In O(N) time, where N is the number of time steps\n # (this definition of the discounted return G_t follows the definition of this quantity\n # shown at page 44 of Sutton&Barto 2017 2nd draft)\n # G_t = r_(t+1) + r_(t+2) + ...\n\n # Given this formulation, the returns at each timestep t can be computed\n # by re-using the computed future returns G_(t+1) to compute the current return G_t\n # G_t = r_(t+1) + gamma*G_(t+1)\n # G_(t-1) = r_t + gamma* G_t\n # (this follows a dynamic programming approach, with which we memorize solutions in order\n # to avoid computing them multiple times)\n\n # This is correct since the above is equivalent to (see also page 46 of Sutton&Barto 2017 2nd draft)\n # G_(t-1) = r_t + gamma*r_(t+1) + gamma*gamma*r_(t+2) + ...\n\n\n ## Given the above, we calculate the returns at timestep t as:\n # gamma[t] * return[t] + reward[t]\n #\n ## We compute this starting from the last timestep to the first, in order\n ## to employ the formula presented above and avoid redundant computations that would be needed\n ## if we were to do it from first to last.\n\n ## Hence, the queue \"returns\" will hold the returns in chronological order, from t=0 to t=n_steps\n ## thanks to the appendleft() function which allows to append to the position 0 in constant time O(1)\n ## a normal python list would instead require O(N) to do this.\n for t in range(n_steps)[::-1]:\n disc_return_t = (returns[0] if len(returns)>0 else 0)\n returns.appendleft(gamma * disc_return_t + rewards[t]) # TODO: complete here\n\n ## standardization of the returns is employed to make training more stable\n eps = np.finfo(np.float32).eps.item()\n\n ## eps is the smallest representable float, which is\n # added to the standard deviation of the returns to avoid numerical instabilities\n returns = torch.tensor(returns)\n returns = (returns - returns.mean()) / (returns.std() + eps)\n\n # Line 7:\n policy_loss = []\n for log_prob, disc_return in zip(saved_log_probs, returns):\n policy_loss.append(-log_prob * disc_return)\n policy_loss = torch.cat(policy_loss).sum()\n\n # Line 8: PyTorch prefers gradient descent\n optimizer.zero_grad()\n policy_loss.backward()\n optimizer.step()\n\n if i_episode % print_every == 0:\n print('Episode {}\\tAverage Score: {:.2f}'.format(i_episode, np.mean(scores_deque)))\n\n return scores","metadata":{"id":"iOdv8Q9NfLK7","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:27.076961Z","iopub.execute_input":"2025-04-24T21:22:27.077453Z","iopub.status.idle":"2025-04-24T21:22:27.087587Z","shell.execute_reply.started":"2025-04-24T21:22:27.077429Z","shell.execute_reply":"2025-04-24T21:22:27.086700Z"}},"outputs":[],"execution_count":31},{"cell_type":"markdown","source":"## Train it\n- We're now ready to train our agent.\n- But first, we define a variable containing all the training hyperparameters.\n- You can change the training parameters (and should ๐Ÿ˜‰)","metadata":{"id":"RIWhQyJjfpEt"}},{"cell_type":"code","source":"cartpole_hyperparameters = {\n \"h_size\": 16,\n \"n_training_episodes\": 1000,\n \"n_evaluation_episodes\": 10,\n \"max_t\": 1000,\n \"gamma\": 1.0,\n \"lr\": 1e-2,\n \"env_id\": env_id,\n \"state_space\": s_size,\n \"action_space\": a_size,\n}","metadata":{"id":"utRe1NgtVBYF"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Create policy and place it to the device\ncartpole_policy = Policy(cartpole_hyperparameters[\"state_space\"], cartpole_hyperparameters[\"action_space\"], cartpole_hyperparameters[\"h_size\"]).to(device)\ncartpole_optimizer = optim.Adam(cartpole_policy.parameters(), lr=cartpole_hyperparameters[\"lr\"])","metadata":{"id":"D3lWyVXBVfl6"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scores = reinforce(cartpole_policy,\n cartpole_optimizer,\n cartpole_hyperparameters[\"n_training_episodes\"],\n cartpole_hyperparameters[\"max_t\"],\n cartpole_hyperparameters[\"gamma\"],\n 100)","metadata":{"id":"uGf-hQCnfouB","colab":{"base_uri":"https://localhost:8080/"},"outputId":"8ce57ece-a80a-4e41-8d49-da9b5f68f201"},"outputs":[{"output_type":"stream","name":"stdout","text":["Episode 100\tAverage Score: 29.11\n","Episode 200\tAverage Score: 129.63\n","Episode 300\tAverage Score: 179.59\n","Episode 400\tAverage Score: 213.86\n","Episode 500\tAverage Score: 280.62\n","Episode 600\tAverage Score: 107.42\n","Episode 700\tAverage Score: 117.47\n","Episode 800\tAverage Score: 351.23\n","Episode 900\tAverage Score: 467.48\n","Episode 1000\tAverage Score: 500.00\n"]}],"execution_count":null},{"cell_type":"markdown","source":"## Define evaluation method ๐Ÿ“\n- Here we define the evaluation method that we're going to use to test our Reinforce agent.","metadata":{"id":"Qajj2kXqhB3g"}},{"cell_type":"code","source":"def evaluate_agent(env, max_steps, n_eval_episodes, policy):\n \"\"\"\n Evaluate the agent for ``n_eval_episodes`` episodes and returns average reward and std of reward.\n :param env: The evaluation environment\n :param n_eval_episodes: Number of episode to evaluate the agent\n :param policy: The Reinforce agent\n \"\"\"\n episode_rewards = []\n for episode in range(n_eval_episodes):\n state = env.reset()\n step = 0\n done = False\n total_rewards_ep = 0\n\n for step in range(max_steps):\n action, _ = policy.act(state)\n new_state, reward, done, info = env.step(action)\n total_rewards_ep += reward\n\n if done:\n break\n state = new_state\n episode_rewards.append(total_rewards_ep)\n mean_reward = np.mean(episode_rewards)\n std_reward = np.std(episode_rewards)\n\n return mean_reward, std_reward","metadata":{"id":"3FamHmxyhBEU","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:33.259090Z","iopub.execute_input":"2025-04-24T21:22:33.259406Z","iopub.status.idle":"2025-04-24T21:22:33.264515Z","shell.execute_reply.started":"2025-04-24T21:22:33.259386Z","shell.execute_reply":"2025-04-24T21:22:33.263731Z"}},"outputs":[],"execution_count":32},{"cell_type":"markdown","source":"## Evaluate our agent ๐Ÿ“ˆ","metadata":{"id":"xdH2QCrLTrlT"}},{"cell_type":"code","source":"!pip install numpy==1.23.5\n","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":582},"id":"1JqR593xf6PL","outputId":"3c177cbb-319a-45b2-e988-a85f32cb2fa4","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:35.411416Z","iopub.execute_input":"2025-04-24T21:22:35.411673Z","iopub.status.idle":"2025-04-24T21:22:38.316110Z","shell.execute_reply.started":"2025-04-24T21:22:35.411656Z","shell.execute_reply":"2025-04-24T21:22:38.315321Z"}},"outputs":[{"name":"stdout","text":"Requirement already satisfied: numpy==1.23.5 in /usr/local/lib/python3.11/dist-packages (1.23.5)\n","output_type":"stream"}],"execution_count":33},{"cell_type":"code","source":"evaluate_agent(eval_env,\n cartpole_hyperparameters[\"max_t\"],\n cartpole_hyperparameters[\"n_evaluation_episodes\"],\n cartpole_policy)","metadata":{"id":"ohGSXDyHh0xx","colab":{"base_uri":"https://localhost:8080/"},"outputId":"a9fc1dd2-a75e-4e05-91a1-522706d84d61"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["(np.float64(500.0), np.float64(0.0))"]},"metadata":{},"execution_count":85}],"execution_count":null},{"cell_type":"markdown","source":"### Publish our trained model on the Hub ๐Ÿ”ฅ\nNow that we saw we got good results after the training, we can publish our trained model on the hub ๐Ÿค— with one line of code.\n\nHere's an example of a Model Card:\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/unit6/modelcard.png\"/>","metadata":{"id":"7CoeLkQ7TpO8"}},{"cell_type":"markdown","source":"### Push to the Hub\n#### Do not modify this code","metadata":{"id":"Jmhs1k-cftIq"}},{"cell_type":"code","source":"from huggingface_hub import HfApi, snapshot_download\nfrom huggingface_hub.repocard import metadata_eval_result, metadata_save\n\nfrom pathlib import Path\nimport datetime\nimport json\nimport imageio\n\nimport tempfile\n\nimport os","metadata":{"id":"LIVsvlW_8tcw","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:42.990223Z","iopub.execute_input":"2025-04-24T21:22:42.990546Z","iopub.status.idle":"2025-04-24T21:22:42.995167Z","shell.execute_reply.started":"2025-04-24T21:22:42.990519Z","shell.execute_reply":"2025-04-24T21:22:42.994378Z"}},"outputs":[],"execution_count":34},{"cell_type":"code","source":"def record_video(env, policy, out_directory, fps=30):\n \"\"\"\n Generate a replay video of the agent\n :param env\n :param Qtable: Qtable of our agent\n :param out_directory\n :param fps: how many frame per seconds (with taxi-v3 and frozenlake-v1 we use 1)\n \"\"\"\n images = []\n done = False\n state = env.reset()\n img = env.render(mode='rgb_array')\n images.append(img)\n while not done:\n # Take the action (index) that have the maximum expected future reward given that state\n action, _ = policy.act(state)\n state, reward, done, info = env.step(action) # We directly put next_state = state for recording logic\n img = env.render(mode='rgb_array')\n images.append(img)\n imageio.mimsave(out_directory, [np.array(img) for i, img in enumerate(images)], fps=fps)","metadata":{"id":"Lo4JH45if81z","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:43.250298Z","iopub.execute_input":"2025-04-24T21:22:43.250587Z","iopub.status.idle":"2025-04-24T21:22:43.256076Z","shell.execute_reply.started":"2025-04-24T21:22:43.250568Z","shell.execute_reply":"2025-04-24T21:22:43.255322Z"}},"outputs":[],"execution_count":35},{"cell_type":"code","source":"def push_to_hub(repo_id,\n model,\n hyperparameters,\n eval_env,\n video_fps=30\n ):\n \"\"\"\n Evaluate, Generate a video and Upload a model to Hugging Face Hub.\n This method does the complete pipeline:\n - It evaluates the model\n - It generates the model card\n - It generates a replay video of the agent\n - It pushes everything to the Hub\n\n :param repo_id: repo_id: id of the model repository from the Hugging Face Hub\n :param model: the pytorch model we want to save\n :param hyperparameters: training hyperparameters\n :param eval_env: evaluation environment\n :param video_fps: how many frame per seconds to record our video replay\n \"\"\"\n\n _, repo_name = repo_id.split(\"/\")\n api = HfApi()\n\n # Step 1: Create the repo\n repo_url = api.create_repo(\n repo_id=repo_id,\n exist_ok=True,\n )\n\n with tempfile.TemporaryDirectory() as tmpdirname:\n local_directory = Path(tmpdirname)\n\n # Step 2: Save the model\n torch.save(model, local_directory / \"model.pt\")\n\n # Step 3: Save the hyperparameters to JSON\n with open(local_directory / \"hyperparameters.json\", \"w\") as outfile:\n json.dump(hyperparameters, outfile)\n\n # Step 4: Evaluate the model and build JSON\n mean_reward, std_reward = evaluate_agent(eval_env,\n hyperparameters[\"max_t\"],\n hyperparameters[\"n_evaluation_episodes\"],\n model)\n # Get datetime\n eval_datetime = datetime.datetime.now()\n eval_form_datetime = eval_datetime.isoformat()\n\n evaluate_data = {\n \"env_id\": hyperparameters[\"env_id\"],\n \"mean_reward\": mean_reward,\n \"n_evaluation_episodes\": hyperparameters[\"n_evaluation_episodes\"],\n \"eval_datetime\": eval_form_datetime,\n }\n\n # Write a JSON file\n with open(local_directory / \"results.json\", \"w\") as outfile:\n json.dump(evaluate_data, outfile)\n\n # Step 5: Create the model card\n env_name = hyperparameters[\"env_id\"]\n\n metadata = {}\n metadata[\"tags\"] = [\n env_name,\n \"reinforce\",\n \"reinforcement-learning\",\n \"custom-implementation\",\n \"deep-rl-class\"\n ]\n\n # Add metrics\n eval = metadata_eval_result(\n model_pretty_name=repo_name,\n task_pretty_name=\"reinforcement-learning\",\n task_id=\"reinforcement-learning\",\n metrics_pretty_name=\"mean_reward\",\n metrics_id=\"mean_reward\",\n metrics_value=f\"{mean_reward:.2f} +/- {std_reward:.2f}\",\n dataset_pretty_name=env_name,\n dataset_id=env_name,\n )\n\n # Merges both dictionaries\n metadata = {**metadata, **eval}\n\n model_card = f\"\"\"\n # **Reinforce** Agent playing **{env_id}**\n This is a trained model of a **Reinforce** agent playing **{env_id}** .\n To learn to use this model and train yours check Unit 4 of the Deep Reinforcement Learning Course: https://huggingface.co/deep-rl-course/unit4/introduction\n \"\"\"\n\n readme_path = local_directory / \"README.md\"\n readme = \"\"\n if readme_path.exists():\n with readme_path.open(\"r\", encoding=\"utf8\") as f:\n readme = f.read()\n else:\n readme = model_card\n\n with readme_path.open(\"w\", encoding=\"utf-8\") as f:\n f.write(readme)\n\n # Save our metrics to Readme metadata\n metadata_save(readme_path, metadata)\n\n # Step 6: Record a video\n video_path = local_directory / \"replay.mp4\"\n record_video(env, model, video_path, video_fps)\n\n # Step 7. Push everything to the Hub\n api.upload_folder(\n repo_id=repo_id,\n folder_path=local_directory,\n path_in_repo=\".\",\n )\n\n print(f\"Your model is pushed to the Hub. You can view your model here: {repo_url}\")","metadata":{"id":"_TPdq47D7_f_","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:22:45.794736Z","iopub.execute_input":"2025-04-24T21:22:45.795434Z","iopub.status.idle":"2025-04-24T21:22:45.805913Z","shell.execute_reply.started":"2025-04-24T21:22:45.795409Z","shell.execute_reply":"2025-04-24T21:22:45.805125Z"}},"outputs":[],"execution_count":36},{"cell_type":"markdown","source":"### .\n\nBy using `push_to_hub` **you evaluate, record a replay, generate a model card of your agent and push it to the Hub**.\n\nThis way:\n- You can **showcase our work** ๐Ÿ”ฅ\n- You can **visualize your agent playing** ๐Ÿ‘€\n- You can **share with the community an agent that others can use** ๐Ÿ’พ\n- You can **access a leaderboard ๐Ÿ† to see how well your agent is performing compared to your classmates** ๐Ÿ‘‰ https://huggingface.co/spaces/huggingface-projects/Deep-Reinforcement-Learning-Leaderboard\n","metadata":{"id":"w17w8CxzoURM"}},{"cell_type":"markdown","source":"To be able to share your model with the community there are three more steps to follow:\n\n1๏ธโƒฃ (If it's not already done) create an account to HF โžก https://huggingface.co/join\n\n2๏ธโƒฃ Sign in and then, you need to store your authentication token from the Hugging Face website.\n- Create a new token (https://huggingface.co/settings/tokens) **with write role**\n\n\n<img src=\"https://huggingface.co/datasets/huggingface-deep-rl-course/course-images/resolve/main/en/notebooks/create-token.jpg\" alt=\"Create HF Token\">\n","metadata":{"id":"cWnFC0iZooTw"}},{"cell_type":"code","source":"notebook_login()","metadata":{"id":"QB5nIcxR8paT","colab":{"base_uri":"https://localhost:8080/","height":17,"referenced_widgets":["18d34bd634cf49849812778ce46d6db0","f201d5a775af4946827895215bf822bc","fd85a618a03f438da4ac9b19eda777ba","699364a499904296b63878a4531f2eb1","450382dce34b4e5f9e479387484ecace","34b6565d6ed24ea795a92956a8db6017","c1320b6f80b04f71a0e03c4909e59940","ed8451f203ac4ea1a3a2897b139f46d5","62356dff90f44a7a90f063f9facff457","b2f43eb0cfda4ae88e20d380aad711cf","b2bb36ffe34f494a811eff587b0f1834","dccfe2431bf4460d9262a2d8650c5f20","e2915c3e083143e1822f990cbc837fc5","5d2505175dce4d2ebbae612af271b93b","0668087c715745b6aeb0cd618b917b8e","14e99f4ce2e14cdebd6c7c2a1306603d","e847d4725ed1472c9ecc8710c0c26ae8","520893b1710f45f69840ead1cb5c0cec","a166a338a8674bfeaf26fd2925534f56","df1fd92758dd4a2b96b34e576e120bb2"]},"outputId":"53bb2e6b-763c-42a4-c569-620cb5fd81a8","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:23:38.438607Z","iopub.execute_input":"2025-04-24T21:23:38.439231Z","iopub.status.idle":"2025-04-24T21:23:38.454223Z","shell.execute_reply.started":"2025-04-24T21:23:38.439189Z","shell.execute_reply":"2025-04-24T21:23:38.453279Z"}},"outputs":[{"output_type":"display_data","data":{"text/plain":"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.svโ€ฆ","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"7090eab43a27426db4a79f679a3f66fc"}},"metadata":{}}],"execution_count":39},{"cell_type":"markdown","source":"If you don't want to use a Google Colab or a Jupyter Notebook, you need to use this command instead: `huggingface-cli login` (or `login`)","metadata":{"id":"GyWc1x3-o3xG"}},{"cell_type":"markdown","source":"3๏ธโƒฃ We're now ready to push our trained agent to the ๐Ÿค— Hub ๐Ÿ”ฅ using `package_to_hub()` function","metadata":{"id":"F-D-zhbRoeOm"}},{"cell_type":"code","source":"repo_id = \"Anish13/Reinforce-cartpole_policy\" #TODO Define your repo id {username/Reinforce-{model-id}}\npush_to_hub(repo_id,\n cartpole_policy, # The model we want to save\n cartpole_hyperparameters, # Hyperparameters\n eval_env, # Evaluation environment\n video_fps=30\n )","metadata":{"id":"UNwkTS65Uq3Q","colab":{"base_uri":"https://localhost:8080/","height":515,"referenced_widgets":["28119533120c4595a31e13fab5dcb97d","0775c017861845efa934dc7d6149d221","7989b07a863f4383934fe7ed0903658e","27d869b037f94c2fbb914876e346c118","7de189f08d3e4b5db2a44dc182e79d7e","11fe33de898d4b19bc8b3ebe737ef5ed","e09537e88867428ab7a6992e10ec77d6","f9cdd3b7d68a4e82b9e98d6e3dd87183","95c3279bd69b436092073186b9313ae8","268df11068fc451a8310e229318a9cfd","c9fb622fbdba4b63b6c3dafc39a916ce"]},"outputId":"d58a01ae-f3c1-4964-e9cd-0edd56ff68ed"},"outputs":[{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: 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.11/dist-packages/gym/core.py:43: DeprecationWarning: \u001b[33mWARN: The argument mode in render method is deprecated; use render_mode during environment initialization instead.\n","See here for more information: https://www.gymlibrary.ml/content/api/\u001b[0m\n"," deprecation(\n","/usr/local/lib/python3.11/dist-packages/pygame/pkgdata.py:25: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html\n"," from pkg_resources import resource_stream, resource_exists\n","/usr/local/lib/python3.11/dist-packages/pkg_resources/__init__.py:3154: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.\n","Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n"," declare_namespace(pkg)\n","/usr/local/lib/python3.11/dist-packages/pkg_resources/__init__.py:3154: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.cloud')`.\n","Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n"," declare_namespace(pkg)\n","/usr/local/lib/python3.11/dist-packages/pkg_resources/__init__.py:3154: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.\n","Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n"," declare_namespace(pkg)\n","/usr/local/lib/python3.11/dist-packages/gym/core.py:43: DeprecationWarning: \u001b[33mWARN: The argument mode in render method is deprecated; use render_mode during environment initialization instead.\n","See here for more information: https://www.gymlibrary.ml/content/api/\u001b[0m\n"," deprecation(\n","WARNING:imageio_ffmpeg:IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (600, 400) to (608, 400) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).\n"]},{"output_type":"display_data","data":{"text/plain":["model.pt: 0%| | 0.00/3.26k [00:00<?, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"28119533120c4595a31e13fab5dcb97d"}},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Your model is pushed to the Hub. You can view your model here: https://huggingface.co/Anish13/Reinforce-cartpole_policy\n"]}],"execution_count":null},{"cell_type":"markdown","source":"Now that we try the robustness of our implementation, let's try a more complex environment: PixelCopter ๐Ÿš\n\n\n","metadata":{"id":"jrnuKH1gYZSz"}},{"cell_type":"markdown","source":"## Second agent: PixelCopter ๐Ÿš\n\n### Study the PixelCopter environment ๐Ÿ‘€\n- [The Environment documentation](https://pygame-learning-environment.readthedocs.io/en/latest/user/games/pixelcopter.html)\n","metadata":{"id":"JNLVmKKVKA6j"}},{"cell_type":"code","source":"env_id = \"Pixelcopter-PLE-v0\"\nenv = gym.make(env_id)\neval_env = gym.make(env_id)\ns_size = env.observation_space.shape[0]\na_size = env.action_space.n","metadata":{"id":"JBSc8mlfyin3","colab":{"base_uri":"https://localhost:8080/"},"outputId":"a85429ae-c9cd-4185-e4ce-58119a2a12ca","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:23:49.764399Z","iopub.execute_input":"2025-04-24T21:23:49.764717Z","iopub.status.idle":"2025-04-24T21:23:49.776776Z","shell.execute_reply.started":"2025-04-24T21:23:49.764695Z","shell.execute_reply":"2025-04-24T21:23:49.776064Z"}},"outputs":[{"name":"stderr","text":"/usr/local/lib/python3.11/dist-packages/gym/core.py:317: DeprecationWarning: \u001b[33mWARN: Initializing wrapper in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.\u001b[0m\n deprecation(\n/usr/local/lib/python3.11/dist-packages/gym/wrappers/step_api_compatibility.py:39: DeprecationWarning: \u001b[33mWARN: Initializing environment in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.\u001b[0m\n deprecation(\n","output_type":"stream"}],"execution_count":40},{"cell_type":"code","source":"print(\"_____OBSERVATION SPACE_____ \\n\")\nprint(\"The State Space is: \", s_size)\nprint(\"Sample observation\", env.observation_space.sample()) # Get a random observation","metadata":{"id":"L5u_zAHsKBy7","colab":{"base_uri":"https://localhost:8080/"},"outputId":"45755829-d24c-4816-db1b-f175c6a96b50","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:23:53.528067Z","iopub.execute_input":"2025-04-24T21:23:53.528352Z","iopub.status.idle":"2025-04-24T21:23:53.534474Z","shell.execute_reply.started":"2025-04-24T21:23:53.528331Z","shell.execute_reply":"2025-04-24T21:23:53.533704Z"}},"outputs":[{"name":"stdout","text":"_____OBSERVATION SPACE_____ \n\nThe State Space is: 7\nSample observation [-0.9404288 -1.331887 -3.1826525 1.539585 -1.2508159 -0.5069579\n 0.30212688]\n","output_type":"stream"}],"execution_count":41},{"cell_type":"code","source":"print(\"\\n _____ACTION SPACE_____ \\n\")\nprint(\"The Action Space is: \", a_size)\nprint(\"Action Space Sample\", env.action_space.sample()) # Take a random action","metadata":{"id":"D7yJM9YXKNbq","colab":{"base_uri":"https://localhost:8080/"},"outputId":"775861f0-f4f5-4e22-e29d-2e49fc64f409","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:23:53.846395Z","iopub.execute_input":"2025-04-24T21:23:53.847075Z","iopub.status.idle":"2025-04-24T21:23:53.852143Z","shell.execute_reply.started":"2025-04-24T21:23:53.847052Z","shell.execute_reply":"2025-04-24T21:23:53.851094Z"}},"outputs":[{"name":"stdout","text":"\n _____ACTION SPACE_____ \n\nThe Action Space is: 2\nAction Space Sample 0\n","output_type":"stream"}],"execution_count":42},{"cell_type":"markdown","source":"The observation space (7) ๐Ÿ‘€:\n- player y position\n- player velocity\n- player distance to floor\n- player distance to ceiling\n- next block x distance to player\n- next blocks top y location\n- next blocks bottom y location\n\nThe action space(2) ๐ŸŽฎ:\n- Up (press accelerator)\n- Do nothing (don't press accelerator)\n\nThe reward function ๐Ÿ’ฐ:\n- For each vertical block it passes through it gains a positive reward of +1. Each time a terminal state reached it receives a negative reward of -1.","metadata":{"id":"NNWvlyvzalXr"}},{"cell_type":"markdown","source":"### Define the new Policy ๐Ÿง \n- We need to have a deeper neural network since the environment is more complex","metadata":{"id":"aV1466QP8crz"}},{"cell_type":"code","source":"class Policy(nn.Module):\n def __init__(self, s_size, a_size, h_size):\n super(Policy, self).__init__()\n # Define the three layers here\n self.fc1 = nn.Linear(s_size, h_size)\n self.fc2 = nn.Linear(h_size, h_size*2)\n self.fc3 = nn.Linear(h_size*2, a_size)\n\n def forward(self, x):\n # Define the forward process here\n x = F.relu(self.fc1(x))\n x = F.relu(self.fc2(x))\n x = self.fc3(x)\n return F.softmax(x, dim=1)\n\n def act(self, state):\n state = torch.from_numpy(state).float().unsqueeze(0).to(device)\n probs = self.forward(state).cpu()\n m = Categorical(probs)\n action = m.sample()\n return action.item(), m.log_prob(action)","metadata":{"id":"I1eBkCiX2X_S","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:24:00.013576Z","iopub.execute_input":"2025-04-24T21:24:00.014274Z","iopub.status.idle":"2025-04-24T21:24:00.020238Z","shell.execute_reply.started":"2025-04-24T21:24:00.014250Z","shell.execute_reply":"2025-04-24T21:24:00.019408Z"}},"outputs":[],"execution_count":43},{"cell_type":"markdown","source":"### Define the hyperparameters โš™๏ธ\n- Because this environment is more complex.\n- Especially for the hidden size, we need more neurons.","metadata":{"id":"SM1QiGCSbBkM"}},{"cell_type":"code","source":"pixelcopter_hyperparameters = {\n \"h_size\": 64,\n \"n_training_episodes\": 50000,\n \"n_evaluation_episodes\": 10,\n \"max_t\": 10000,\n \"gamma\": 0.99,\n \"lr\": 1e-4,\n \"env_id\": env_id,\n \"state_space\": s_size,\n \"action_space\": a_size,\n}","metadata":{"id":"y0uujOR_ypB6","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:24:01.868728Z","iopub.execute_input":"2025-04-24T21:24:01.868979Z","iopub.status.idle":"2025-04-24T21:24:01.873091Z","shell.execute_reply.started":"2025-04-24T21:24:01.868964Z","shell.execute_reply":"2025-04-24T21:24:01.872197Z"}},"outputs":[],"execution_count":44},{"cell_type":"markdown","source":"### Train it\n- We're now ready to train our agent ๐Ÿ”ฅ.","metadata":{"id":"wyvXTJWm9GJG"}},{"cell_type":"code","source":"!pip install numpy==1.23.5","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_i-FSSN9ivBj","outputId":"f5bff738-06b8-4121-8d3e-206b6350175c","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:24:05.038274Z","iopub.execute_input":"2025-04-24T21:24:05.039034Z","iopub.status.idle":"2025-04-24T21:24:07.894180Z","shell.execute_reply.started":"2025-04-24T21:24:05.039011Z","shell.execute_reply":"2025-04-24T21:24:07.893237Z"}},"outputs":[{"name":"stdout","text":"Requirement already satisfied: numpy==1.23.5 in /usr/local/lib/python3.11/dist-packages (1.23.5)\n","output_type":"stream"}],"execution_count":45},{"cell_type":"code","source":"# Create policy and place it to the device\n# torch.manual_seed(50)\npixelcopter_policy = Policy(pixelcopter_hyperparameters[\"state_space\"], pixelcopter_hyperparameters[\"action_space\"], pixelcopter_hyperparameters[\"h_size\"]).to(device)\npixelcopter_optimizer = optim.Adam(pixelcopter_policy.parameters(), lr=pixelcopter_hyperparameters[\"lr\"])","metadata":{"id":"7mM2P_ckysFE","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:24:07.895918Z","iopub.execute_input":"2025-04-24T21:24:07.896224Z","iopub.status.idle":"2025-04-24T21:24:07.904671Z","shell.execute_reply.started":"2025-04-24T21:24:07.896191Z","shell.execute_reply":"2025-04-24T21:24:07.903828Z"}},"outputs":[],"execution_count":46},{"cell_type":"code","source":"scores = reinforce(pixelcopter_policy,\n pixelcopter_optimizer,\n pixelcopter_hyperparameters[\"n_training_episodes\"],\n pixelcopter_hyperparameters[\"max_t\"],\n pixelcopter_hyperparameters[\"gamma\"],\n 1000)","metadata":{"id":"v1HEqP-fy-Rf","colab":{"base_uri":"https://localhost:8080/"},"outputId":"22ab9360-272a-4068-9120-7950b27e6016","trusted":true,"execution":{"iopub.status.busy":"2025-04-24T21:24:46.030376Z","iopub.execute_input":"2025-04-24T21:24:46.030896Z","iopub.status.idle":"2025-04-25T00:37:43.929688Z","shell.execute_reply.started":"2025-04-24T21:24:46.030871Z","shell.execute_reply":"2025-04-25T00:37:43.928819Z"}},"outputs":[{"name":"stderr","text":"/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:174: UserWarning: \u001b[33mWARN: Future gym versions will require that `Env.reset` can be passed a `seed` instead of using `Env.seed` for resetting the environment random number generator.\u001b[0m\n logger.warn(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:190: UserWarning: \u001b[33mWARN: Future gym versions will require that `Env.reset` can be passed `return_info` to return information from the environment resetting.\u001b[0m\n logger.warn(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:195: UserWarning: \u001b[33mWARN: Future gym versions will require that `Env.reset` can be passed `options` to allow the environment initialisation to be passed additional information.\u001b[0m\n logger.warn(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:141: UserWarning: \u001b[33mWARN: The obs returned by the `reset()` method was expecting numpy array dtype to be float32, actual type: float64\u001b[0m\n logger.warn(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:165: UserWarning: \u001b[33mWARN: The obs returned by the `reset()` method is not within the observation space.\u001b[0m\n logger.warn(f\"{pre} is not within the observation space.\")\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:227: DeprecationWarning: \u001b[33mWARN: Core environment is written in old step API which returns one bool instead of two. It is recommended to rewrite the environment with new step API. \u001b[0m\n logger.deprecation(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:233: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`. (Deprecated NumPy 1.24)\n if not isinstance(done, (bool, np.bool8)):\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:141: UserWarning: \u001b[33mWARN: The obs returned by the `step()` method was expecting numpy array dtype to be float32, actual type: float64\u001b[0m\n logger.warn(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:165: UserWarning: \u001b[33mWARN: The obs returned by the `step()` method is not within the observation space.\u001b[0m\n logger.warn(f\"{pre} is not within the observation space.\")\n","output_type":"stream"},{"name":"stdout","text":"Episode 1000\tAverage Score: 3.16\nEpisode 2000\tAverage Score: 7.76\nEpisode 3000\tAverage Score: 7.78\nEpisode 4000\tAverage Score: 10.09\nEpisode 5000\tAverage Score: 12.50\nEpisode 6000\tAverage Score: 16.76\nEpisode 7000\tAverage Score: 17.91\nEpisode 8000\tAverage Score: 17.19\nEpisode 9000\tAverage Score: 17.06\nEpisode 10000\tAverage Score: 21.10\nEpisode 11000\tAverage Score: 21.68\nEpisode 12000\tAverage Score: 19.71\nEpisode 13000\tAverage Score: 23.58\nEpisode 14000\tAverage Score: 30.17\nEpisode 15000\tAverage Score: 16.66\nEpisode 16000\tAverage Score: 24.02\nEpisode 17000\tAverage Score: 28.97\nEpisode 18000\tAverage Score: 23.41\nEpisode 19000\tAverage Score: 30.41\nEpisode 20000\tAverage Score: 27.78\nEpisode 21000\tAverage Score: 28.84\nEpisode 22000\tAverage Score: 26.78\nEpisode 23000\tAverage Score: 29.44\nEpisode 24000\tAverage Score: 23.74\nEpisode 25000\tAverage Score: 29.06\nEpisode 26000\tAverage Score: 26.27\nEpisode 27000\tAverage Score: 18.11\nEpisode 28000\tAverage Score: 29.74\nEpisode 29000\tAverage Score: 31.83\nEpisode 30000\tAverage Score: 36.56\nEpisode 31000\tAverage Score: 35.11\nEpisode 32000\tAverage Score: 35.67\nEpisode 33000\tAverage Score: 29.23\nEpisode 34000\tAverage Score: 31.82\nEpisode 35000\tAverage Score: 40.29\nEpisode 36000\tAverage Score: 38.99\nEpisode 37000\tAverage Score: 24.31\nEpisode 38000\tAverage Score: 35.27\nEpisode 39000\tAverage Score: 31.68\nEpisode 40000\tAverage Score: 36.56\nEpisode 41000\tAverage Score: 21.56\nEpisode 42000\tAverage Score: 44.01\nEpisode 43000\tAverage Score: 38.02\nEpisode 44000\tAverage Score: 39.32\nEpisode 45000\tAverage Score: 49.01\nEpisode 46000\tAverage Score: 30.89\nEpisode 47000\tAverage Score: 43.08\nEpisode 48000\tAverage Score: 49.96\nEpisode 49000\tAverage Score: 42.97\nEpisode 50000\tAverage Score: 55.44\n","output_type":"stream"}],"execution_count":47},{"cell_type":"markdown","source":"### Publish our trained model on the Hub ๐Ÿ”ฅ","metadata":{"id":"8kwFQ-Ip85BE"}},{"cell_type":"code","source":"repo_id = \"Anish13/Reinforce-Pixelcopter-PLE-v0_1\" #TODO Define your repo id {username/Reinforce-{model-id}}\npush_to_hub(repo_id,\n pixelcopter_policy, # The model we want to save\n pixelcopter_hyperparameters, # Hyperparameters\n eval_env, # Evaluation environment\n video_fps=30\n )","metadata":{"id":"6PtB7LRbTKWK","trusted":true,"execution":{"iopub.status.busy":"2025-04-25T00:37:43.931509Z","iopub.execute_input":"2025-04-25T00:37:43.931748Z","iopub.status.idle":"2025-04-25T00:37:49.287882Z","execution_failed":"2025-04-25T01:20:00.393Z"}},"outputs":[{"name":"stderr","text":"/usr/local/lib/python3.11/dist-packages/gym/core.py:43: DeprecationWarning: \u001b[33mWARN: The argument mode in render method is deprecated; use render_mode during environment initialization instead.\nSee here for more information: https://www.gymlibrary.ml/content/api/\u001b[0m\n deprecation(\n/usr/local/lib/python3.11/dist-packages/gym/utils/passive_env_checker.py:280: UserWarning: \u001b[33mWARN: No render modes was declared in the environment (env.metadata['render_modes'] is None or not defined), you may have trouble when calling `.render()`.\u001b[0m\n logger.warn(\n","output_type":"stream"},{"output_type":"display_data","data":{"text/plain":"model.pt: 0%| | 0.00/39.7k [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"c7dec08aa6df40298c2f39df76c3b639"}},"metadata":{}},{"name":"stdout","text":"Your model is pushed to the Hub. You can view your model here: https://huggingface.co/Anish13/Reinforce-Pixelcopter-PLE-v0_1\n","output_type":"stream"}],"execution_count":null},{"cell_type":"markdown","source":"## Some additional challenges ๐Ÿ†\nThe best way to learn **is to try things on your own**! As you saw, the current agent is not doing great. As a first suggestion, you can train for more steps. But also trying to find better parameters.\n\nIn the [Leaderboard](https://huggingface.co/spaces/huggingface-projects/Deep-Reinforcement-Learning-Leaderboard) you will find your agents. Can you get to the top?\n\nHere are some ideas to achieve so:\n* Train more steps\n* Try different hyperparameters by looking at what your classmates have done ๐Ÿ‘‰ https://huggingface.co/models?other=reinforce\n* **Push your new trained model** on the Hub ๐Ÿ”ฅ\n* **Improving the implementation for more complex environments** (for instance, what about changing the network to a Convolutional Neural Network to handle\nframes as observation)?","metadata":{"id":"7VDcJ29FcOyb"}},{"cell_type":"markdown","source":"________________________________________________________________________\n\n**Congrats on finishing this unit**!ย There was a lot of information.\nAnd congrats on finishing the tutorial. You've just coded your first Deep Reinforcement Learning agent from scratch using PyTorch and shared it on the Hub ๐Ÿฅณ.\n\nDon't hesitate to iterate on this unit **by improving the implementation for more complex environments** (for instance, what about changing the network to a Convolutional Neural Network to handle\nframes as observation)?\n\nIn the next unit, **we're going to learn more about Unity MLAgents**, by training agents in Unity environments. This way, you will be ready to participate in the **AI vs AI challenges where you'll train your agents\nto compete against other agents in a snowball fight and a soccer game.**\n\nSounds fun? See you next time!\n\nFinally, we would love **to hear what you think of the course and how we can improve it**. If you have some feedback then, please ๐Ÿ‘‰ [fill this form](https://forms.gle/BzKXWzLAGZESGNaE9)\n\nSee you in Unit 5! ๐Ÿ”ฅ\n\n### Keep Learning, stay awesome ๐Ÿค—\n\n","metadata":{"id":"x62pP0PHdA-y"}}]}