{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "pytorchtext_bucketiterator.ipynb",
      "provenance": [],
      "collapsed_sections": [
        "qSuUpkj1UuUa"
      ],
      "toc_visible": true,
      "authorship_tag": "ABX9TyOasYmgukutco4EIPI5HLTz"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "fd87896dd32b41b892cd0f468154bb6f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_6d0fc0fd85d945e79cbd8ac80b6910ca",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_0a8156f448b74d3386f7a1e6042a2f0e",
              "IPY_MODEL_8661dabeb6024fa8b01932e4433fbf73"
            ]
          }
        },
        "6d0fc0fd85d945e79cbd8ac80b6910ca": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "0a8156f448b74d3386f7a1e6042a2f0e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_8a928a6e61174170b891b91bc894de84",
            "_dom_classes": [],
            "description": "pos Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_d36961822dfe43e18109f3da20eb2732"
          }
        },
        "8661dabeb6024fa8b01932e4433fbf73": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_26730d758541463f8fe943e518c2df3c",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [01:21&lt;00:00, 152.61it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_d91b607ecd26422195fb887df5878548"
          }
        },
        "8a928a6e61174170b891b91bc894de84": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "d36961822dfe43e18109f3da20eb2732": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "26730d758541463f8fe943e518c2df3c": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "d91b607ecd26422195fb887df5878548": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "c7516d9f9e564a6ca26cbb30ee92f5f2": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_59af03aa117b41a6aea527c8c46ff586",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_39087527adcf498b98f555f248dfbc9c",
              "IPY_MODEL_4a4d6a3f8f944649a9ce1f8966f22bd6"
            ]
          }
        },
        "59af03aa117b41a6aea527c8c46ff586": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "39087527adcf498b98f555f248dfbc9c": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_2c3937b4941f478686a18b8e357caa12",
            "_dom_classes": [],
            "description": "neg Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_0879ae8d1745496ba1537e2196be755d"
          }
        },
        "4a4d6a3f8f944649a9ce1f8966f22bd6": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_80e91e98cd1a4a22ad12967908434edb",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [01:09&lt;00:00, 179.63it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_09b85dcf05a64a289fb5da2ac5d85a98"
          }
        },
        "2c3937b4941f478686a18b8e357caa12": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "0879ae8d1745496ba1537e2196be755d": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "80e91e98cd1a4a22ad12967908434edb": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "09b85dcf05a64a289fb5da2ac5d85a98": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "9f5a6252f4e642c8b81c2200138afd27": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_f67f63144dee439ca0fe010856a7b4fb",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_a8ec07375c5843fe8c8dbd45e234c7c7",
              "IPY_MODEL_7c75e67a17d34de59fcba6518dd1b7b3"
            ]
          }
        },
        "f67f63144dee439ca0fe010856a7b4fb": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "a8ec07375c5843fe8c8dbd45e234c7c7": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_4486de755a8540e1bd16dae05f14f90a",
            "_dom_classes": [],
            "description": "pos Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_e1486c2135ca4a8b957623747867e20f"
          }
        },
        "7c75e67a17d34de59fcba6518dd1b7b3": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_78d99075a4e04ba19cdab29b1d7d0d88",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:57&lt;00:00, 216.64it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_f7ff16c4cc3544918475dd98f0b577e2"
          }
        },
        "4486de755a8540e1bd16dae05f14f90a": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "e1486c2135ca4a8b957623747867e20f": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "78d99075a4e04ba19cdab29b1d7d0d88": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "f7ff16c4cc3544918475dd98f0b577e2": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "6d3b1ff475f2497eb45937e7830c02be": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_6fbdbbfcd48d4ea289cfcd1a3b414b45",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_cd348e06b9474f5aaea7ec3d587c9204",
              "IPY_MODEL_d7170ed37bc643279bd62f8f8d429f89"
            ]
          }
        },
        "6fbdbbfcd48d4ea289cfcd1a3b414b45": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "cd348e06b9474f5aaea7ec3d587c9204": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_7bae6099679b44399246d3cf495950ea",
            "_dom_classes": [],
            "description": "neg Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_537fae09a43c4141ad24e4b7e5a6e82f"
          }
        },
        "d7170ed37bc643279bd62f8f8d429f89": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_4d0649974a3943ada892d260b8218bb8",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:46&lt;00:00, 271.18it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_f03aa5965ae74dc9bc072b75d010070e"
          }
        },
        "7bae6099679b44399246d3cf495950ea": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "537fae09a43c4141ad24e4b7e5a6e82f": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "4d0649974a3943ada892d260b8218bb8": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "f03aa5965ae74dc9bc072b75d010070e": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "7337cbb5a8fe4bef8fd6e85a27b81d01": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_07787387599a41bd9df21278245d2d9c",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_1700e903ef1e46b09cd672acdb451745",
              "IPY_MODEL_c1ba110337a645f0821fe9935e85e24c"
            ]
          }
        },
        "07787387599a41bd9df21278245d2d9c": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "1700e903ef1e46b09cd672acdb451745": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_053525250fe94cd1b598cbc7f71e49ad",
            "_dom_classes": [],
            "description": "pos Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_893820321ad44f2fa3aba895b6ccdf53"
          }
        },
        "c1ba110337a645f0821fe9935e85e24c": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_21f2e4177e4c42b2bd5cb2960990de8a",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:34&lt;00:00, 367.60it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_8bbe378fe6e943b1b9872658f251ef04"
          }
        },
        "053525250fe94cd1b598cbc7f71e49ad": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "893820321ad44f2fa3aba895b6ccdf53": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "21f2e4177e4c42b2bd5cb2960990de8a": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "8bbe378fe6e943b1b9872658f251ef04": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "88bb6e124c774e8bac4b9245dee6880e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_4b0d4e6031fc4fe1bdf0fa325ed18a7f",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_16e91ec757f14808b25e0618fa65df68",
              "IPY_MODEL_22a0163514f54a4691663bef242fbec4"
            ]
          }
        },
        "4b0d4e6031fc4fe1bdf0fa325ed18a7f": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "16e91ec757f14808b25e0618fa65df68": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_1d6dc95dd31d43fcae74890ebac524fd",
            "_dom_classes": [],
            "description": "neg Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_09a77b9159254c68b6f00b43bffa2435"
          }
        },
        "22a0163514f54a4691663bef242fbec4": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_e8821c09e7614e138bd6bf9ddafc6609",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:21&lt;00:00, 575.77it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_704100474fec491995ef8c15223a9b3f"
          }
        },
        "1d6dc95dd31d43fcae74890ebac524fd": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "09a77b9159254c68b6f00b43bffa2435": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "e8821c09e7614e138bd6bf9ddafc6609": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "704100474fec491995ef8c15223a9b3f": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "2c84d51c92b74d3fa1ceef47a8ef8fd8": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_6b9c28d148af4109892dec18860c02bb",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_351e024e62e44648a643eea623a1da5b",
              "IPY_MODEL_ca93c630ad174b66bec8be4039098974"
            ]
          }
        },
        "6b9c28d148af4109892dec18860c02bb": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "351e024e62e44648a643eea623a1da5b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_ba96d175fd074e69ac62d348297bc2a2",
            "_dom_classes": [],
            "description": "pos Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_865ffb5a4f30405b9b519c2c637ad782"
          }
        },
        "ca93c630ad174b66bec8be4039098974": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_d993f1ec95f845f8a4ca8bb01976ad68",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:24&lt;00:00, 518.72it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_3f0fb71a1e6d45e0b325eef00477d8e3"
          }
        },
        "ba96d175fd074e69ac62d348297bc2a2": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "865ffb5a4f30405b9b519c2c637ad782": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "d993f1ec95f845f8a4ca8bb01976ad68": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "3f0fb71a1e6d45e0b325eef00477d8e3": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "200318d052bc437eb0b9364fc6f02ba2": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_0433aca88eeb4e86b98dcdc4725b6e65",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_0157b666d127421eab3a3d56e61d93a9",
              "IPY_MODEL_fa617c29e8ef4af5bea17fa3757f2d56"
            ]
          }
        },
        "0433aca88eeb4e86b98dcdc4725b6e65": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "0157b666d127421eab3a3d56e61d93a9": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_eb6ccb7f9ce24c0cad494bc82bf16810",
            "_dom_classes": [],
            "description": "neg Files: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 12500,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 12500,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_c8618e75905042a9a9bea34c53da003e"
          }
        },
        "fa617c29e8ef4af5bea17fa3757f2d56": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_57a8a0a2ac2142eaaab24c17f98afc39",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 12500/12500 [00:12&lt;00:00, 1002.31it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_17d5df20cf3f407abf7dfef920b4613d"
          }
        },
        "eb6ccb7f9ce24c0cad494bc82bf16810": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "c8618e75905042a9a9bea34c53da003e": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "57a8a0a2ac2142eaaab24c17f98afc39": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "17d5df20cf3f407abf7dfef920b4613d": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qSuUpkj1UuUa"
      },
      "source": [
        "##### © Copyright 2020 [George Mihaila](https://github.com/gmihaila).\n",
        "\n",
        "Licensed under the Apache License, Version 2.0 (the \"License\");"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FkXPZsPbT2aV"
      },
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aP1zAHX4S70e"
      },
      "source": [
        "# **Better Batches with PyTorchText BucketIterator**\n",
        "\n",
        "## **How to use PyTorchText BucketIterator to sort text data for better batching.**\n",
        "\n",
        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gmihaila/ml_things/blob/master/notebooks/pytorch/pytorchtext_bucketiterator.ipynb) &nbsp;\n",
        "[![Generic badge](https://img.shields.io/badge/GitHub-Source-greensvg)](https://github.com/gmihaila/ml_things/blob/master/notebooks/pytorch/pytorchtext_bucketiterator.ipynb)\n",
        "[![Generic badge](https://img.shields.io/badge/Article-Medium-black.svg)](https://gmihaila.medium.com/better-batches-with-pytorchtext-bucketiterator-12804a545e2a)\n",
        "[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "**Disclaimer:** *The format of this tutorial notebook is very similar with my other tutorial notebooks. This is done intentionally in order to keep readers familiar with my format.*\n",
        "\n",
        "<br>\n",
        "\n",
        "This notebook is a simple tutorial on how to use the powerful **PytorchText**  **BucketIterator** functionality to group examples (**I use examples and sequences interchangeably**) of similar lengths into batches. This allows us to provide the most optimal batches when training models with text data.\n",
        "\n",
        "Having batches with similar length examples provides a lot of gain for recurrent models (RNN, GRU, LSTM) and transformers models (bert, roBerta, gpt2, xlnet, etc.) where padding will be minimal.\n",
        "\n",
        "Basically any model that takes as input variable text data sequences will benefit from this tutorial.\n",
        "\n",
        "**I will not train any models in this notebook!** I will release a tutorial where I use this implementation to train a transformer model.\n",
        "\n",
        "The purpose is to use an example text datasets and batch it using **PyTorchText** with **BucketIterator** and show how it groups text sequences of similar length in batches.\n",
        "\n",
        "This tutorial has two main parts:\n",
        "\n",
        "* **Using PyTorch Dataset with PyTorchText Bucket Iterator**: Here I implemented a standard PyTorch Dataset class that reads in the example text datasets and use PyTorch Bucket Iterator to group similar length examples in same batches. I want to show how easy it is to use this powerful functionality form PyTorchText on a regular PyTorch Dataset workflow which you already have setup.\n",
        "\n",
        "* **Using PyTorch Text TabularDataset with PyTorchText Bucket Iterator**: Here I use the built-in PyTorchText TabularDataset that reads data straight from local files without the need to create a PyTorch Dataset class. Then I follow same steps as in the previous part to show how nicely text examples are grouped together.\n",
        "\n",
        "*This notebooks is a code adaptation and implementation inspired from a few sources:* [torchtext_translation_tutorial](https://pytorch.org/tutorials/beginner/torchtext_translation_tutorial.html), [pytorch/text - GitHub](https://github.com/pytorch/text), [torchtext documentation](https://torchtext.readthedocs.io/en/latest/index.html#) and [A Comprehensive Introduction to Torchtext](https://mlexplained.com/2018/02/08/a-comprehensive-tutorial-to-torchtext/).\n",
        "\n",
        "<br>\n",
        "\n",
        "## **What should I know for this notebook?**\n",
        "\n",
        "Some basic PyTorch regarding Dataset class and using DataLoaders. Some knowledge of PyTorchText is helpful but not critical in understanding this tutorial. The BucketIterator is similar in applying Dataloader to a PyTorch Dataset.\n",
        "\n",
        "<br>\n",
        "\n",
        "## **How to use this notebook?**\n",
        "\n",
        "The code is made with reusability in mind. It can be easily adapted for other text datasets and other NLP tasks in order to achieve optimal batching. \n",
        "\n",
        "Comments should provide enough guidance to easily adapt this notebook to your needs.\n",
        "\n",
        "This code is designed mostly for **classification tasks** in mind, but it can be adapted for any other Natural Language Processing tasks where batching text data is needed.\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "\n",
        "## **Dataset**\n",
        "\n",
        "I will use the well known movies reviews positive - negative labeled [Large Movie Review Dataset](https://ai.stanford.edu/~amaas/data/sentiment/).\n",
        "\n",
        "The description provided on the Stanford website:\n",
        "\n",
        "*This is a dataset for binary sentiment classification containing substantially more data than previous benchmark datasets. We provide a set of 25,000 highly polar movie reviews for training, and 25,000 for testing. There is additional unlabeled data for use as well. Raw text and already processed bag of words formats are provided. See the README file contained in the release for more details.*\n",
        "\n",
        "**Why this dataset?** I believe is an easy to understand and use dataset for classification. I think sentiment data is always fun to work with.\n",
        "\n",
        "<br>\n",
        "\n",
        "## **Coding**\n",
        "\n",
        "Now let's do some coding! We will go through each coding cell in the notebook and describe what it does, what's the code, and when is relevant - show the output.\n",
        "\n",
        "I made this format to be easy to follow if you decide to run each code cell in your own python notebook.\n",
        "\n",
        "When I learn from a tutorial I always try to replicate the results. I believe it's easy to follow along if you have the code next to the explanations.\n",
        "\n",
        "<br>\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8ppW60cUXZQK"
      },
      "source": [
        "## Downloads\n",
        "\n",
        "Download the IMDB Movie Reviews sentiment dataset and unzip it locally."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6l_gehghXapy"
      },
      "source": [
        "# download the dataset\n",
        "!wget -q -nc http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz\n",
        "# unzip it\n",
        "!tar -zxf /content/aclImdb_v1.tar.gz"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UCLtm5BiXona"
      },
      "source": [
        "## **Installs**\n",
        "\n",
        "* **[ml_things](https://github.com/gmihaila/ml_things)** library used for various machine learning related tasks. I created this library to reduce the amount of code I need to write for each machine learning project.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1JQhmThRXp7b",
        "outputId": "ae033cc9-6406-4482-fda0-f37156868b6a",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Install helper functions.\n",
        "!pip install -q git+https://github.com/gmihaila/ml_things.git"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[?25l\r\u001b[K     |█████▏                          | 10kB 14.0MB/s eta 0:00:01\r\u001b[K     |██████████▎                     | 20kB 17.2MB/s eta 0:00:01\r\u001b[K     |███████████████▍                | 30kB 14.6MB/s eta 0:00:01\r\u001b[K     |████████████████████▌           | 40kB 10.6MB/s eta 0:00:01\r\u001b[K     |█████████████████████████▋      | 51kB 4.6MB/s eta 0:00:01\r\u001b[K     |██████████████████████████████▊ | 61kB 5.2MB/s eta 0:00:01\r\u001b[K     |████████████████████████████████| 71kB 3.7MB/s \n",
            "\u001b[?25h  Building wheel for ml-things (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for ftfy (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "X5IO8-xrXvWY"
      },
      "source": [
        "## **Imports**\n",
        "\n",
        "Import all needed libraries for this notebook.\n",
        "\n",
        "Declare basic parameters used for this notebook:\n",
        "\n",
        "* `device` - Device to use by torch: GPU/CPU. I use CPU as default since I will not perform any costly operations.\n",
        "\n",
        "* `train_batch_size` - Batch size used on train data.\n",
        "\n",
        "* `valid_batch_size` - Batch size used for validation data. It usually is greater than `train_batch_size` since the model would only need to make prediction and no gradient calculations is needed."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "J42h802BXwTe"
      },
      "source": [
        "import io\n",
        "import os\n",
        "import torchtext\n",
        "from tqdm.notebook import tqdm\n",
        "from ml_things import fix_text\n",
        "from torch.utils.data import Dataset, DataLoader\n",
        "\n",
        "# Will use `cpu` for simplicity.\n",
        "device = 'cpu'\n",
        "\n",
        "# Number of batches for training\n",
        "train_batch_size = 10\n",
        "\n",
        "# Number of batches for validation. Use a larger value than training.\n",
        "# It helps speed up the validation process.\n",
        "valid_batch_size = 20"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9biWe-OhS4Wo"
      },
      "source": [
        "## Using PyTorch Dataset\n",
        "\n",
        "This is where I create the PyTorch Dataset objects for training and validation that **can** be used to feed data into a model. This is standard procedure when using PyTorch.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ChQWVc4IUUPb"
      },
      "source": [
        "### Dataset Class\n",
        "\n",
        "Implementation of the PyTorch Dataset class.\n",
        "\n",
        "Most important components in a PyTorch Dataset class are:\n",
        "* `__len__(self, )` where it returns the number of examples in our dataset that we read in `__init__(self, )`. This will ensure that `len()` will return the number of examples.\n",
        "* `__getitem__(self, item)` where given an index `item` will return the example corresponding to the `item` position."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-Fo_0qq_S_Zf"
      },
      "source": [
        "class MovieReviewsTextDataset(Dataset):\n",
        "  r\"\"\"PyTorch Dataset class for loading data.\n",
        "\n",
        "  This is where the data parsing happens.\n",
        "\n",
        "  This class is built with reusability in mind.\n",
        "\n",
        "  Arguments:\n",
        "\n",
        "    path (:obj:`str`):\n",
        "        Path to the data partition.\n",
        "\n",
        "  \"\"\"\n",
        "\n",
        "  def __init__(self, path):\n",
        "\n",
        "    # Check if path exists.\n",
        "    if not os.path.isdir(path):\n",
        "      # Raise error if path is invalid.\n",
        "      raise ValueError('Invalid `path` variable! Needs to be a directory')\n",
        "    \n",
        "    self.texts = []\n",
        "    self.labels = []\n",
        "    # Since the labels are defined by folders with data we loop \n",
        "    # through each label.\n",
        "    for label  in ['pos', 'neg']:\n",
        "      sentiment_path = os.path.join(path, label)\n",
        "\n",
        "      # Get all files from path.\n",
        "      files_names = os.listdir(sentiment_path)#[:10] # Sample for debugging.\n",
        "      # Go through each file and read its content.\n",
        "      for file_name in tqdm(files_names, desc=f'{label} Files'):\n",
        "        file_path = os.path.join(sentiment_path, file_name)\n",
        "\n",
        "        # Read content.\n",
        "        content = io.open(file_path, mode='r', encoding='utf-8').read()\n",
        "        # Fix any unicode issues.\n",
        "        content = fix_text(content)\n",
        "        # Save content.\n",
        "        self.texts.append(content)\n",
        "        # Save labels.\n",
        "        self.labels.append(label)\n",
        "\n",
        "    # Number of examples.\n",
        "    self.n_examples = len(self.labels)\n",
        "\n",
        "    return\n",
        "\n",
        "\n",
        "  def __len__(self):\n",
        "    r\"\"\"When used `len` return the number of examples.\n",
        "\n",
        "    \"\"\"\n",
        "    \n",
        "    return self.n_examples\n",
        "\n",
        "\n",
        "  def __getitem__(self, item):\n",
        "    r\"\"\"Given an index return an example from the position.\n",
        "    \n",
        "    Arguments:\n",
        "\n",
        "      item (:obj:`int`):\n",
        "          Index position to pick an example to return.\n",
        "\n",
        "    Returns:\n",
        "      :obj:`Dict[str, str]`: Dictionary of inputs that are used to feed \n",
        "      to a model.\n",
        "\n",
        "    \"\"\"\n",
        "\n",
        "    return {'text':self.texts[item], 'label':self.labels[item]}"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "52b7iTASUYAZ"
      },
      "source": [
        "### Train - Validation Datasets\n",
        "\n",
        "Create PyTorch Dataset for train and validation partitions."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EQ-HrjdOUcK6",
        "outputId": "c8a2ae8f-bacf-4724-f0d3-a5c2d3dc0e5e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 298,
          "referenced_widgets": [
            "fd87896dd32b41b892cd0f468154bb6f",
            "6d0fc0fd85d945e79cbd8ac80b6910ca",
            "0a8156f448b74d3386f7a1e6042a2f0e",
            "8661dabeb6024fa8b01932e4433fbf73",
            "8a928a6e61174170b891b91bc894de84",
            "d36961822dfe43e18109f3da20eb2732",
            "26730d758541463f8fe943e518c2df3c",
            "d91b607ecd26422195fb887df5878548",
            "c7516d9f9e564a6ca26cbb30ee92f5f2",
            "59af03aa117b41a6aea527c8c46ff586",
            "39087527adcf498b98f555f248dfbc9c",
            "4a4d6a3f8f944649a9ce1f8966f22bd6",
            "2c3937b4941f478686a18b8e357caa12",
            "0879ae8d1745496ba1537e2196be755d",
            "80e91e98cd1a4a22ad12967908434edb",
            "09b85dcf05a64a289fb5da2ac5d85a98",
            "9f5a6252f4e642c8b81c2200138afd27",
            "f67f63144dee439ca0fe010856a7b4fb",
            "a8ec07375c5843fe8c8dbd45e234c7c7",
            "7c75e67a17d34de59fcba6518dd1b7b3",
            "4486de755a8540e1bd16dae05f14f90a",
            "e1486c2135ca4a8b957623747867e20f",
            "78d99075a4e04ba19cdab29b1d7d0d88",
            "f7ff16c4cc3544918475dd98f0b577e2",
            "6d3b1ff475f2497eb45937e7830c02be",
            "6fbdbbfcd48d4ea289cfcd1a3b414b45",
            "cd348e06b9474f5aaea7ec3d587c9204",
            "d7170ed37bc643279bd62f8f8d429f89",
            "7bae6099679b44399246d3cf495950ea",
            "537fae09a43c4141ad24e4b7e5a6e82f",
            "4d0649974a3943ada892d260b8218bb8",
            "f03aa5965ae74dc9bc072b75d010070e"
          ]
        }
      },
      "source": [
        "print('Dealing with Train...')\n",
        "# Create pytorch dataset.\n",
        "train_dataset = MovieReviewsTextDataset(path='/content/aclImdb/train')\n",
        "\n",
        "print(f'Created `train_dataset` with {len(train_dataset)} examples!')\n",
        "\n",
        "print()\n",
        "\n",
        "print('Dealing with Validation...')\n",
        "# Create pytorch dataset.\n",
        "valid_dataset =  MovieReviewsTextDataset(path='/content/aclImdb/test')\n",
        "                               \n",
        "print(f'Created `valid_dataset` with {len(valid_dataset)} examples!')"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Dealing with Train...\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "fd87896dd32b41b892cd0f468154bb6f",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='pos Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "c7516d9f9e564a6ca26cbb30ee92f5f2",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='neg Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n",
            "Created `train_dataset` with 25000 examples!\n",
            "\n",
            "Dealing with Validation...\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "9f5a6252f4e642c8b81c2200138afd27",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='pos Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "6d3b1ff475f2497eb45937e7830c02be",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='neg Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n",
            "Created `valid_dataset` with 25000 examples!\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OuXCNfZLUeJJ"
      },
      "source": [
        "### PyTorch DataLoader\n",
        "\n",
        "In order to group examples from the PyTorch Dataset into batches we use PyTorch DataLoader. This is standard when using PyTorch."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vW8mE9wYTfLJ",
        "outputId": "9ecc0b24-dc67-4f86-c6d8-ab17a971abe8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Move pytorch dataset into dataloader.\n",
        "torch_train_dataloader = DataLoader(train_dataset, batch_size=train_batch_size, shuffle=True)\n",
        "print(f'Created `torch_train_dataloader` with {len(torch_train_dataloader)} batches!')\n",
        "\n",
        "# Move pytorch dataset into dataloader.\n",
        "torch_valid_dataloader = DataLoader(valid_dataset, batch_size=valid_batch_size, shuffle=False)\n",
        "print(f'Created `torch_valid_dataloader` with {len(torch_valid_dataloader)} batches!')"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Created `torch_train_dataloader` with 2500 batches!\n",
            "Created `torch_valid_dataloader` with 1250 batches!\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6IAuKwSvIbxe"
      },
      "source": [
        "### PyTorchText Bucket Iterator Dataloader\n",
        "\n",
        "Here is where the magic happens! We pass in the **train_dataset** and **valid_dataset** PyTorch Dataset splits into **BucketIterator** to create the actual batches.\n",
        "\n",
        "It's very nice that PyTorchText can handle splits! No need to write same line of code again for train and validation split.\n",
        "\n",
        "**The `sort_key` parameter is very important!** It is used to order text sequences in batches. Since we want to batch sequences of text with similar length, we will use a simple function that returns the length of an data example (`len(x['text')`). This function needs to follow the format of the PyTorch Dataset we created in order to return the length of an example, in my case I return a dictionary with `text` key for an example.\n",
        "\n",
        "**It is important to keep `sort=False` and `sort_with_batch=True` to only sort the examples in each batch and not the examples in the whole dataset!**\n",
        "\n",
        "Find more details in the PyTorchText **BucketIterator** documentation [here](https://torchtext.readthedocs.io/en/latest/data.html#bucketiterator) - look at the **BPTTIterator** because it has same parameters except the **bptt_len** argument.\n",
        "\n",
        "**Note:**\n",
        "*If you want just a single DataLoader use `torchtext.data.BucketIterator` instead of `torchtext.data.BucketIterator.splits` and make sure to provide just one PyTorch Dataset instead of tuple of PyTorch Datasets and change the parameter `batch_sizes` and its tuple values to `batch_size` with single value: `dataloader = torchtext.data.BucketIterator(dataset, batch_size=batch_size, )`*"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OKfYOod_LQrs",
        "outputId": "1a44781f-5a3a-40b0-803d-ac169aae7486",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Group similar length text sequences together in batches.\n",
        "torchtext_train_dataloader, torchtext_valid_dataloader = torchtext.data.BucketIterator.splits(\n",
        "    \n",
        "                              # Datasets for iterator to draw data from\n",
        "                              (train_dataset, valid_dataset),\n",
        "\n",
        "                              # Tuple of train and validation batch sizes.\n",
        "                              batch_sizes=(train_batch_size, valid_batch_size),\n",
        "\n",
        "                              # Device to load batches on.\n",
        "                              device=device, \n",
        "\n",
        "                              # Function to use for sorting examples.\n",
        "                              sort_key=lambda x: len(x['text']),\n",
        "\n",
        "\n",
        "                              # Repeat the iterator for multiple epochs.\n",
        "                              repeat=True, \n",
        "\n",
        "                              # Sort all examples in data using `sort_key`.\n",
        "                              sort=False, \n",
        "\n",
        "                              # Shuffle data on each epoch run.\n",
        "                              shuffle=True,\n",
        "\n",
        "                              # Use `sort_key` to sort examples in each batch.\n",
        "                              sort_within_batch=True,\n",
        "                              )\n",
        "\n",
        "# Print number of batches in each split.\n",
        "print('Created `torchtext_train_dataloader` with %d batches!'%len(torchtext_train_dataloader))\n",
        "print('Created `torchtext_valid_dataloader` with %d batches!'%len(torchtext_valid_dataloader))"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Created `torchtext_train_dataloader` with 2500 batches!\n",
            "Created `torchtext_valid_dataloader` with 1250 batches!\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gHQaFJvYNkKJ"
      },
      "source": [
        "### Compare DataLoaders\n",
        "\n",
        "Let's compare the PyTorch DataLoader batches with the PyTorchText BucketIterator batches. We can see how nicely examples of similar length are grouped in same batch with PyTorchText.\n",
        "\n",
        "**Note:** *When using the PyTorchText BucketIterator, make sure to call `create_batches()` before looping through each batch! Else you won't get any output form the iterator.*"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hevDHd2uNn3K",
        "outputId": "1e918d07-b028-4939-c522-1418ac1748c2",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Loop through regular dataloader.\n",
        "print('PyTorch DataLoader\\n')\n",
        "for batch in torch_train_dataloader:\n",
        "  \n",
        "  # Let's check batch size.\n",
        "  print('Batch size: %d\\n'% len(batch['text']))\n",
        "  print('LABEL\\tLENGTH\\tTEXT'.ljust(10))\n",
        "\n",
        "  # Print each example.\n",
        "  for text, label in zip(batch['text'], batch['label']):\n",
        "    print('%s\\t%d\\t%s'.ljust(10) % (label, len(text), text))\n",
        "  print('\\n')\n",
        "  \n",
        "  # Only look at first batch. Reuse this code in training models.\n",
        "  break\n",
        "  \n",
        "\n",
        "# Create batches - needs to be called before each loop.\n",
        "torchtext_train_dataloader.create_batches()\n",
        "\n",
        "# Loop through BucketIterator.\n",
        "print('PyTorchText BuketIterator\\n')\n",
        "for batch in torchtext_train_dataloader.batches:\n",
        "\n",
        "  # Let's check batch size.\n",
        "  print('Batch size: %d\\n'% len(batch))\n",
        "  print('LABEL\\tLENGTH\\tTEXT'.ljust(10))\n",
        "  \n",
        "  # Print each example.\n",
        "  for example in batch:\n",
        "    print('%s\\t%d\\t%s'.ljust(10) % (example['label'], len(example['text']), example['text']))\n",
        "  print('\\n')\n",
        "  \n",
        "  # Only look at first batch. Reuse this code in training models.\n",
        "  break"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "PyTorch DataLoader\n",
            "\n",
            "Batch size: 10\n",
            "\n",
            "LABEL\tLENGTH\tTEXT\n",
            "pos\t1037\tFascinating movie, based on a true story, about an Australian woman, Lindy Chamberlain (Meryl Streep) accused of killing her baby daughter. She insists that a dingo took her baby, but the story is highly suspicious. The film is actually about the media circus that took place around the case, the way Australians interpreted what was presented in the media, and the lynch mob mentality that ultimately led to the woman's conviction, based on barely any hard evidence. I love films that question the media, and also films that take a hard look on how people are railroaded by the justice system. I've always thought that juries ought to be showed 12 Angry Men before they go through with their duties. It's not, as has often been said, a liberal movie, but a clinical look at how we as human beings interpret events based so much on our prejudices and a desire for revenge. A Cry in the Dark is likewise clinical. Schepisi is careful not to make the film at all melodramatic. Some may find the film boring or dry, but I found it engaging.  \n",
            "neg\t1406\tOr maybe that's what it feels like. Anyway, \"The Bat People\" is about as flat as a rug, bland as a sack of flour and as exciting as a rock...and as intelligent as all three combined.<br /><br />Okay, plot in a nutshell (fitting vessel, that...): a doctor (Moss) gets bitten by a bat while checking out a cave with his wife (McAndrew) and subsequently turns into a bat - well, not exactly a bat but a bat-like creature that looks more like a werewolf who kills his victims in a first-person camera viewpoint....<br /><br />But then there's the business of the sheriff (Pataki), who is about the WORST kind of sheriff: the hick kind. He hassles people, he leers at married women, he steals handkerchiefs from haberdasheries (the FIEND!), he smokes with one of those cigarette holders in his mouth and talks at the same time, making him look and sound like Buford T. Justice in \"Smokey and the Bandit\" and (this is the worst part)... HE'S THE MOST LIKEABLE CHARACTER IN THE WHOLE FILM!<br /><br />The whole film, though, is just TV movie-of-the-week-like crapola (guano, in this case). It's an AIP, for crying out loud! What did you expect, Oscar caliber stuff?<br /><br />And what else can you say about a film that not even MST3K can save?<br /><br />How about...no stars for \"The Bat People\", full version OR MST3K version!<br /><br />By the way, if there's ever a sequel for this movie, I'm burying my TV.  \n",
            "pos\t679\tFar by my most second favourite cartoon Spielberg did, after Animaniacs. Even if the ratings were low, so what, I still enjoyed it and loved it, was so funny and I adored the cast, wow Jess Harnell and Tress Macneille were in there and were just fantastic, the whole cast were brilliant, especially the legendary Frank Welker.<br /><br />I'd love to see this cartoon again, was so awesome and the jokes were brilliant. Also I can remember the hilarious moment where Brain cameos in it, you hear his voice and it played the PATB theme instrumental, that was just fantastic, I love it in those cartoons when cameos pop in. I wish this cartoon and Animaniacs came back, i loved them  \n",
            "neg\t922\tThis movie reminds me of \"Irréversible (2002)\", another art-work movie with is a violent and radical approach of human nature. I did not like the movie but I cannot say that it is a bad movie, it is just special. I reminds me also of \"Camping Cosmos (1996)\" where a bunch of low-class figures are residents of a camp at the sea in Belgium. The same description of people living together, side by side against their wills and with all the confrontation of characters that do not match together. I also thought about the books by the French writer Emile Zola who was a writer of the style that is naturalism. I did not like the movie and I also do not like the people who are in it. They all seem so vulgar, without any basic good taste. One could ask the question why do they live, they all seem to be on this planet a a member of a big farce, forced to live against their will. Or you could say: the hell is on this world.  \n",
            "pos\t214\tThere's never a dull moment in this movie. Wonderful visuals, good actors, and a classical story of the fight of good and evil. Mostly very funny, sometimes even scary. A true classic, a movie everybody should see.  \n",
            "neg\t1288\tI don't think any player in Hollywood history lasted as long as David Niven did given most of the weak films he had to carry by dint of his incredible charm. He could act, got an Oscar for it, but most of the material he did was as light as one ply of two ply tissue paper.<br /><br />Happy Go Lovely is a case in point. It's a musical and for the most part you'll remember Vera-Ellen's dancing. You'll remember that they are in Scot's costume as the film is set in Edinburgh during their festival. But if you can recall a single song from it you must have a photographic memory.<br /><br />The plot is light. Vera-Ellen is the American lead in a musical that apparently is getting its out of town tryout in Edinburgh. She starts in the chorus and runs late one day. She gets a lift from the chauffeur of a millionaire greeting card king. Everybody now assumes she's the main squeeze of the millionaire. Doors open up as they've never opened before.<br /><br />The millionaire is David Niven and he goes along with it and the various situations that are engendered by the mistake. Cesar Romero has some good moments here as the frantic producer of this musical.<br /><br />In the end though Happy Go Lovely is light and harmless fluff which David Niven did so much of and got so tired of.  \n",
            "pos\t605\tThe thing I remember most about this film is that it used to air on local KTLA TV (Ch. 5) during every Christmas season during the mid to late 70s, mainly due to the fact that the true story took place on or near Christmas Eve. It was always a bit disturbing to see the hell that this girl goes through, being the lone survivor of a plane crash in the Peruvian jungle. The graphic scene of this young girl pulling leeches out of her infected leg made quite an impression on this young viewer. Not quite the kind of Christmas cheer I was used to seeing at the time. Definitely not a Rankin-Bass production.  \n",
            "pos\t1411\tFabulous, fantastic, probably Disney's best musical adventure. I have loved this film for over 35 years because it is so imaginative, clever and fun. Even despite the silly \"flying bed\" scenes, the other scenes and dialog are magical and funny. Could they have picked anyone better than Angela Lansbury to play Eglantine? I cannot think of anyone more suited to the role. Remaking this classic would be as stupid as remaking Mary Poppins.<br /><br />David Tomlinson, though he had few quality movie roles, absolutely shines in this adventure. He was a comic genius who is often forgotten nowadays. Blustering, prim and proper Englishman -- nobody could really do slapstick and pull it off as gracefully as he does. It would be tragic to remake this film because Tomlinson has been deceased for a few years and nobody could step into his shoes and do his character justice.<br /><br />The dancing nightgowns and armor have a magical aura about them that other movies with witches just don't capture. I particularly enjoy the parts where the Germans invade Eglantine's house and she must defend it in any way she can.<br /><br />Bobbing along, bobbing along on the bottom of the beautiful briny, sea. Richard and Robert Sherman outdid themselves on the musical numbers. All of them are fantastic and worth remembering, Portobello Road being one of my favorites.<br /><br />A great film that still holds up today!!  \n",
            "neg\t604\tJust another film that exploits gratuitous frontal male nudity; awful acting, plus, the lovemaking scenes are the most un-sexy I've ever seen (and this is not about me not linking the idea of two young men making love, since I'm gay).<br /><br />Again, as in Mil nubes de paz, Julian Hernandez directed an incredibly pretentious film with a story that makes enough argument for a short film of about five minutes but manages to make a 2 hour film with it... And this time, there isn't even the issue of racism and commodification in the Mexican gay community to talk about! God gracious have mercy on us!  \n",
            "pos\t368\tWhat can i say about the first film ever?<br /><br />You can't rate this, because it's not supposed to be entertaining. But if you HAVE to rate it, you should give it a 10. It is stunning to see moving images from the year 1895. This was one of the most important movies in history. I wonder how it was to be one of the people who saw the first movie ever!<br /><br />  \n",
            "\n",
            "\n",
            "PyTorchText BuketIterator\n",
            "\n",
            "Batch size: 10\n",
            "\n",
            "LABEL\tLENGTH\tTEXT\n",
            "pos\t609\tThat's My Bush is a live action project made by South Park creators Trey Parker and Matt Stone.The show was cancelled after one season, not because of bad reviews(it actually got good reviews), but because it was very expensive.That's my bush is a pretty funny spoof of an average network TV sitcom.It is also a political satire.Now, this is nowhere near as good as South Park, but it is a very funny spoof of a sitcom and also a pretty good political satire.The guy who plays in that's my bush looks a lot like him! If you can find the show, check it out.There are plenty of laughs to be had!<br /><br />9/10  \n",
            "neg\t610\tTerminus Paradis was exceptional, but \"Niki ardelean\" comes too late. We already have enough of this and we want something new.<br /><br />Big directors should have no problems seeing beyond their time, not behind. Why people see Romania only as a postrevolutionary country?<br /><br />We are just born not reincarnated, and nobody gives a s**t anymore about old times. Most people dont remember or dont want to remember, and the new generation of movie consumers dont understand a bit. This should be the first day of romanian movie not the final song - priveghi! Maybe younger directors should make the move.  \n",
            "neg\t612\tAwesomely improbable and foolish potboiler that at least has some redeeming, crisp location photography, but it's too unbelievable to generate much in the way of tension. I was kinda hoping that Stanwyck wouldn't make it back in time because, really, she was saddled with the wet, in more ways than one, husband,and she had an idiot child as well..why NOT run off with Meeker? But the nagging question remains..what sort of wood was that pier support made of if a rotten piece of it pulled off didn't float? Stanwyck, always impeccably professional, does the best she could with the material but it's threadbare.  \n",
            "pos\t613\tThe events of September 11 2001 do not need extra human interest in the shape of following the training of the rookie fireman or the progress of the two French brothers. In my view it would have been better to leave this out. I think the directors tried too hard, perhaps they felt that the events of the day needed a story as a backdrop. The comment of one of a policemen - \"this aint f***ing Disneyworld\" is apt.<br /><br />Nevertheless it is compelling viewing for the depiction of the events. The filmakers were in all the right places at the right times, no other footage from the day matches what they shot.  \n",
            "pos\t613\tOkay, first of all I got this movie as a Christmas present so it was FREE! FIRST - This movie was meant to be in stereoscopic 3D. It is for the most part, but whenever the main character is in her car the movie falls flat to 2D! What!!?!?! It's not that hard to film in a car!!! SECOND - The story isn't very good. There are a lot of things wrong with it.<br /><br />THIRD - Why are they showing all of the deaths in the beginning of the film! It made the movie suck whenever some was going to get killed!!! Watch it for a good laugh , but don't waste your time buying it. Just download it or something for cheap.  \n",
            "neg\t617\tI have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.  \n",
            "pos\t625\tFragglerock is excellent in the way that Schindler's List was excellent. A Great watch for children and adults of all genders. Big noses can be seen as hinting towards phallic symbols, in the same way that H.R. Puff N Stuff had hinted towards marijuana smoking. Your kids will love this movie. I enjoyed it very much as a child. My father showed me this movie as a child. He enjoyed it as well and pointed out that the exaggerated noses were phallic symbols. Although at the time I had no clue about what those were. The movie is comedy and adventure. The storyline is wacky and cheerful. I and you shall enjoy this together.  \n",
            "neg\t625\tSure I've seen bad movies in my life, but this one was so bad that I actually became angry in the theater. I wanted my money back. I wrote to the director asking him to refund my movie ticket, of course I didn't receive a refund (or even a reply) but it's the point that matters. On a scale of 1-10 I give this movie a -42. Why did the \"Jeep\" (Chevy Blazer??) stop running from being hit with a bat? Why did they hit the \"Jeep\"(Chevy Blazer?????) with the bat in the first place instead of cracking the bum's skull? The plot was thin, the movie filled with obvious clichés, and certain parts of it just didn't make any sense.  \n",
            "neg\t626\tEven 20+ years later, Ninja Mission stands out as the worst movie I ever managed to sit through. Scandanavian ninjas silently enter a scene, fire their obnoxiously noisy sub-machine guns with wild abandon, and then silently leave. Wow, how will we find those silent invisible assassins? Just follow the shell casings and smoke!Painfully bad dialog (or was it brilliant and just poorly translated?), not an Asian in sight in the cast, and a whopping total of 3 Asians among the stunt crew. The plot is ridiculous, the acting pretty much non-existent - then again, ninja can't act! Save yourselves - avoid watching at all costs!  \n",
            "pos\t626\tThis film is excellently paced, you never have to wait for a belly laugh to come up for more than about a minute and there's much more going on than the initial premise of the film. Throughout it there are mockeries of the traditional schmaltzy local-boys-done-good-overcoming-adversity genre of which this parodies. Don't let anyone tell you that they're trying to get cheap laughs just by using obscenities;- sure, there's plenty of that but it's all contextual, not gratuitous. I loved this film and it only cost me £2.99 on DVD , so in terms of entertainment value for money, it has been the best film I've seen this year.  \n",
            "\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2IEb5wL9Qudr"
      },
      "source": [
        "### Train Loop Examples\n",
        "\n",
        "Now let's look at a model training loop would look like. I printed the first 10 batches list of examples lengths to show how nicely they are grouped throughout the dataset!"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5oCIpdJCQwqZ",
        "outputId": "841c31a3-d81a-43b3-bfa2-ed446d7c8c19",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Example of number of epochs\n",
        "epochs = 1\n",
        "\n",
        "# Example of loop through each epoch\n",
        "for epoch in range(epochs):\n",
        "\n",
        "  # Create batches - needs to be called before each loop.\n",
        "  torchtext_train_dataloader.create_batches()\n",
        "\n",
        "  # Loop through BucketIterator.\n",
        "  for sample_id, batch in enumerate(torchtext_train_dataloader.batches):\n",
        "    print('Batch examples lengths: %s'.ljust(20) % str([len(example['text']) for example in batch]))\n",
        "\n",
        "    # Let's break early, you get the idea.\n",
        "    if sample_id == 10:\n",
        "      break"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Batch examples lengths: [848, 848, 849, 849, 850, 852, 853, 854, 856, 857]\n",
            "Batch examples lengths: [779, 780, 780, 781, 781, 782, 782, 782, 783, 784]\n",
            "Batch examples lengths: [2100, 2103, 2104, 2109, 2114, 2135, 2147, 2151, 2158, 2164]\n",
            "Batch examples lengths: [903, 905, 910, 910, 910, 910, 914, 915, 916, 919]\n",
            "Batch examples lengths: [968, 968, 970, 970, 971, 972, 973, 975, 981, 982]\n",
            "Batch examples lengths: [806, 806, 807, 807, 808, 809, 810, 810, 811, 811]\n",
            "Batch examples lengths: [731, 733, 734, 735, 736, 736, 737, 737, 738, 739]\n",
            "Batch examples lengths: [357, 357, 358, 361, 362, 362, 362, 364, 366, 371]\n",
            "Batch examples lengths: [2330, 2335, 2337, 2350, 2351, 2353, 2367, 2374, 2376, 2383]\n",
            "Batch examples lengths: [1916, 1920, 1921, 1936, 1951, 1953, 1967, 1970, 1981, 1985]\n",
            "Batch examples lengths: [1395, 1398, 1399, 1402, 1403, 1412, 1412, 1413, 1414, 1414]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "POrx0_EuImpM"
      },
      "source": [
        "## Using PyTorchText TabularDataset\n",
        "\n",
        "Now I will use the TabularDataset functionality which creates the PyTorchDataset object right from our local files. \n",
        "\n",
        "We don't need to create a custom PyTorch Dataset class to load our dataset as long as we have tabular files of our data."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SGNgKXkq5X8f"
      },
      "source": [
        "### Data to Files\n",
        "\n",
        "Since our dataset is scattered into multiple files, I created a function `files_to_tsv` which puts our dataset into a `.tsv` file (Tab-Separated Values).\n",
        "\n",
        "Since I'll use the **TabularDataset** from `pytorch.data` I need to pass tabular format files.\n",
        "\n",
        "For text data I find the Tab Separated Values format easier to deal with.\n",
        "\n",
        "I will call the `files_to_tsv` function for each of the two partitions **train** and **test**. \n",
        "\n",
        "The function will return the name of the `.tsv` file saved so we can use it later in PyTorchText."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sn8cBvTx0NLr",
        "outputId": "c62fb5cd-0b02-4d93-f0d8-bd9e565b8a37",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 247,
          "referenced_widgets": [
            "7337cbb5a8fe4bef8fd6e85a27b81d01",
            "07787387599a41bd9df21278245d2d9c",
            "1700e903ef1e46b09cd672acdb451745",
            "c1ba110337a645f0821fe9935e85e24c",
            "053525250fe94cd1b598cbc7f71e49ad",
            "893820321ad44f2fa3aba895b6ccdf53",
            "21f2e4177e4c42b2bd5cb2960990de8a",
            "8bbe378fe6e943b1b9872658f251ef04",
            "88bb6e124c774e8bac4b9245dee6880e",
            "4b0d4e6031fc4fe1bdf0fa325ed18a7f",
            "16e91ec757f14808b25e0618fa65df68",
            "22a0163514f54a4691663bef242fbec4",
            "1d6dc95dd31d43fcae74890ebac524fd",
            "09a77b9159254c68b6f00b43bffa2435",
            "e8821c09e7614e138bd6bf9ddafc6609",
            "704100474fec491995ef8c15223a9b3f",
            "2c84d51c92b74d3fa1ceef47a8ef8fd8",
            "6b9c28d148af4109892dec18860c02bb",
            "351e024e62e44648a643eea623a1da5b",
            "ca93c630ad174b66bec8be4039098974",
            "ba96d175fd074e69ac62d348297bc2a2",
            "865ffb5a4f30405b9b519c2c637ad782",
            "d993f1ec95f845f8a4ca8bb01976ad68",
            "3f0fb71a1e6d45e0b325eef00477d8e3",
            "200318d052bc437eb0b9364fc6f02ba2",
            "0433aca88eeb4e86b98dcdc4725b6e65",
            "0157b666d127421eab3a3d56e61d93a9",
            "fa617c29e8ef4af5bea17fa3757f2d56",
            "eb6ccb7f9ce24c0cad494bc82bf16810",
            "c8618e75905042a9a9bea34c53da003e",
            "57a8a0a2ac2142eaaab24c17f98afc39",
            "17d5df20cf3f407abf7dfef920b4613d"
          ]
        }
      },
      "source": [
        "def files_to_tsv(partition_path, save_path='./'):\n",
        "  \"\"\"Parse each file in partition and keep track of sentiments.\n",
        "  Create a list of pairs [tag, text]\n",
        "\n",
        "  Arguments:\n",
        "\n",
        "    partition_path (:obj:`str`):\n",
        "      Partition used: train or test.\n",
        "\n",
        "    save_path (:obj:`str`):\n",
        "      Path where to save the final .tsv file.\n",
        "\n",
        "  Returns:\n",
        "\n",
        "    :obj:`str`: Filename of created .tsv file.\n",
        "\n",
        "  \"\"\"\n",
        "\n",
        "  # List of all examples in format [tag, text].\n",
        "  examples = []\n",
        "\n",
        "  # Print partition.\n",
        "  print(partition_path)\n",
        "\n",
        "  # Loop through each sentiment.\n",
        "  for sentiment in ['pos', 'neg']:\n",
        "\n",
        "    # Find path for sentiment.\n",
        "    sentiment_path = os.path.join(partition_path, sentiment)\n",
        "\n",
        "    # Get all files from path sentiment.\n",
        "    files_names = os.listdir(sentiment_path)\n",
        "\n",
        "    # For each file in path sentiment.\n",
        "    for file_name in tqdm(files_names, desc=f'{sentiment} Files'):\n",
        "\n",
        "      # Get file content.\n",
        "      file_content = io.open(os.path.join(sentiment_path, file_name), mode='r', encoding='utf-8').read()\n",
        "\n",
        "      # Fix any format errors.\n",
        "      file_content = fix_text(file_content)\n",
        "\n",
        "      # Append sentiment and file content.\n",
        "      examples.append([sentiment, file_content])\n",
        "\n",
        "  # Create a TSV file with same format `sentiment  text`.\n",
        "  examples = [\"%s\\t%s\"%(example[0], example[1]) for example in examples]\n",
        "\n",
        "  # Create file name.\n",
        "  tsv_filename = os.path.basename(partition_path) + '_pos_neg_%d.tsv'%len(examples)\n",
        "\n",
        "  # Write to TSV file.\n",
        "  io.open(os.path.join(save_path, tsv_filename), mode='w', encoding='utf-8').write('\\n'.join(examples))\n",
        "\n",
        "  # Return TSV file name.\n",
        "  return tsv_filename\n",
        "  \n",
        "\n",
        "# Path where to save tsv file.\n",
        "data_path = '/content'\n",
        "\n",
        "# Convert train files to tsv file.\n",
        "train_filename = files_to_tsv(partition_path='/content/aclImdb/train', save_path=data_path)\n",
        "\n",
        "# Convert test files to tsv file.\n",
        "test_filename = files_to_tsv(partition_path='/content/aclImdb/test', save_path=data_path)"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/aclImdb/train\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "7337cbb5a8fe4bef8fd6e85a27b81d01",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='pos Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "88bb6e124c774e8bac4b9245dee6880e",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='neg Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n",
            "/content/aclImdb/test\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "2c84d51c92b74d3fa1ceef47a8ef8fd8",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='pos Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "200318d052bc437eb0b9364fc6f02ba2",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='neg Files', max=12500.0, style=ProgressStyle(description_…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "l8rfZyyp4tGR"
      },
      "source": [
        "### TabularDataset\n",
        "\n",
        "Here I setup the data fields for PyTorchText. We have to tell the library how to handle each column of the `.tsv` file. For this we need to create `data.Field` objects for each column.\n",
        "\n",
        "`text_tokenizer`: \n",
        "For this example I don't use an actual tokenizer for the `text` column but I need to create one because it requires as input. I created a dummy tokenizer that returns same value. Depending on the project, here is where you will have your own tokenizer. It needs to take as input text and output a list.\n",
        "\n",
        "`label_tokenizer`\n",
        "The label tokenizer is also a dummy tokenizer. This is where you will have a encoder to transform labels to ids.\n",
        "\n",
        "Since we have two `.tsv` files it's great that we can use the `.split` function from **TabularDataset** to handle two files at the same time one for train and the other one for test.\n",
        "\n",
        "Find more details about **torchtext.data** functionality [here](https://torchtext.readthedocs.io/en/latest/data.html#dataset-batch-and-example)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dhaX2V5N3Y4V"
      },
      "source": [
        "# Text tokenizer function - dummy tokenizer to return same text.\n",
        "# Here you will use your own tokenizer.\n",
        "text_tokenizer = lambda x : x\n",
        "\n",
        "# Label tokenizer - dummy label encoder that returns same label.\n",
        "# Here you will add your own label encoder.\n",
        "label_tokenizer = lambda x: x\n",
        "\n",
        "# Data field for text column - invoke tokenizer.\n",
        "TEXT = torchtext.data.Field(sequential=True, tokenize=text_tokenizer, lower=False)\n",
        "\n",
        "# Data field for labels - invoke tokenize label encoder.\n",
        "LABEL = torchtext.data.Field(sequential=True, tokenize=label_tokenizer, use_vocab=False)\n",
        "\n",
        "# Create data fields as tuples of description variable and data field.\n",
        "datafields = [(\"label\", LABEL),\n",
        "              (\"text\", TEXT)]\n",
        "\n",
        "# Since we have have tab separated data we use TabularDataset\n",
        "train_dataset, valid_dataset = torchtext.data.TabularDataset.splits(\n",
        "    \n",
        "                                                # Path to train and validation.\n",
        "                                                path=data_path,\n",
        "\n",
        "                                                # Train data filename.\n",
        "                                                train=train_filename,\n",
        "\n",
        "                                                # Validation file name.\n",
        "                                                validation=test_filename,\n",
        "\n",
        "                                                # Format of local files.\n",
        "                                                format='tsv',\n",
        "\n",
        "                                                # Check if we have header.\n",
        "                                                skip_header=False,\n",
        "\n",
        "                                                # How to handle fields.\n",
        "                                                fields=datafields)"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fsmI67Ly4zkc"
      },
      "source": [
        "### PyTorchText Bucket Iterator Dataloader\n",
        "\n",
        "I'm using same setup as in the **PyTorchText Bucket Iterator Dataloader** code cell section. The only difference is in the `sort_key` since there is different way to access example attributes (we had dictionary format before)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "50Uno-i7Pwor",
        "outputId": "43e4ce91-aec9-411f-967e-5ddb96a6d1a0",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Group similar length text sequences together in batches.\n",
        "torchtext_train_dataloader, torchtext_valid_dataloader = torchtext.data.BucketIterator.splits(\n",
        "    \n",
        "                              # Datasets for iterator to draw data from\n",
        "                              (train_dataset, valid_dataset),\n",
        "\n",
        "                              # Tuple of train and validation batch sizes.\n",
        "                              batch_sizes=(train_batch_size, valid_batch_size),\n",
        "\n",
        "                              # Device to load batches on.\n",
        "                              device=device, \n",
        "\n",
        "                              # Function to use for sorting examples.\n",
        "                              sort_key=lambda x: len(x.text),\n",
        "\n",
        "\n",
        "                              # Repeat the iterator for multiple epochs.\n",
        "                              repeat=True, \n",
        "\n",
        "                              # Sort all examples in data using `sort_key`.\n",
        "                              sort=False, \n",
        "\n",
        "                              # Shuffle data on each epoch run.\n",
        "                              shuffle=True,\n",
        "\n",
        "                              # Use `sort_key` to sort examples in each batch.\n",
        "                              sort_within_batch=True,\n",
        "                              )\n",
        "\n",
        "# Print number of batches in each split.\n",
        "print('Created `torchtext_train_dataloader` with %d batches!'%len(torchtext_train_dataloader))\n",
        "print('Created `torchtext_valid_dataloader` with %d batches!'%len(torchtext_valid_dataloader))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Created `torchtext_train_dataloader` with 2500 batches!\n",
            "Created `torchtext_valid_dataloader` with 1250 batches!\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "h2bJtSlW42Fo"
      },
      "source": [
        "### Compare DataLoaders\n",
        "\n",
        "Let's compare the PyTorch DataLoader batches with the PyTorchText BucketIterator batches created with TabularDataset. We can see how nicely examples of similar length are grouped in same batch with PyTorchText.\n",
        "\n",
        "**Note:** *When using the PyTorchText BucketIterator, make sure to call `create_batches()` before looping through each batch! Else you won't get any output form the iterator.*"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "U7oII00Xz7e5",
        "outputId": "2cd017d5-6bd6-4f5d-a7fe-14d66041cc42",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Loop through regular dataloader.\n",
        "print('PyTorch DataLoader\\n')\n",
        "for batch in torch_train_dataloader:\n",
        "  \n",
        "  # Let's check batch size.\n",
        "  print('Batch size: %d\\n'% len(batch['text']))\n",
        "  print('LABEL\\tLENGTH\\tTEXT'.ljust(10))\n",
        "\n",
        "  # Print each example.\n",
        "  for text, label in zip(batch['text'], batch['label']):\n",
        "    print('%s\\t%d\\t%s'.ljust(10) % (label, len(text), text))\n",
        "  print('\\n')\n",
        "  \n",
        "  # Only look at first batch. Reuse this code in training models.\n",
        "  break\n",
        "  \n",
        "\n",
        "# Create batches - needs to be called before each loop.\n",
        "torchtext_train_dataloader.create_batches()\n",
        "\n",
        "# Loop through BucketIterator.\n",
        "print('PyTorchText BuketIterator\\n')\n",
        "for batch in torchtext_train_dataloader.batches:\n",
        "\n",
        "  # Let's check batch size.\n",
        "  print('Batch size: %d\\n'% len(batch))\n",
        "  print('LABEL\\tLENGTH\\tTEXT'.ljust(10))\n",
        "  \n",
        "  # Print each example.\n",
        "  for example in batch:\n",
        "    print('%s\\t%d\\t%s'.ljust(10) % (example.label, len(example.text), example.text))\n",
        "  print('\\n')\n",
        "  \n",
        "  # Only look at first batch. Reuse this code in training models.\n",
        "  break"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "PyTorch DataLoader\n",
            "\n",
            "Batch size: 10\n",
            "\n",
            "LABEL\tLENGTH\tTEXT\n",
            "neg\t1205\tThis movie is bad news and I'm really surprised at the level of big name talent who would ever agree to appear in such a piece of junk as this. I imagine there were a few strangled agents sprawled across Hollywood Blvd. as a result of this fiasco. What really gets you is that it could have been good. The directors star appeal and the subject matter was sufficient fodder to spark interest and ticket sales, but this is a flop. The multiple story lines all go from bad to silly by the pictures end, and you end up feeling like a mouse in a maze looking for a piece of cheese that turns out to be rotten. What Spike is able to achieve is revenge against any Italians who may have beat him up when he was a kid or insulted him, as the movie does quite a number on perpetuating outdated and probably offensive Italian stereotypes. As with any Spike Lee film there is some really thought provoking and magical camerawork. He does have the gift of grabbing your psyche and transporting you into his vision if only for a few memorable scenes. But the question remains...can you endure the other 2 hours of head scratching and clock watching as you wonder and wait for the ending that has to be there somewhere.  \n",
            "pos\t762\tMicro-phonies is a classic Stooge short. The guys are inept repairmen working at a radio station, and during some horsing around in a broadcast booth, Curly's perfect mimic of a recording of \"Voices of Spring\" is mistaken for the real thing, leading to a radio contract and a zany musical party. The trio's mock rendition of the quintet from \"Lucia de L'Amamore\" is especially entertaining. No doubt this is essential viewing for Stooge fans.<br /><br />Although the evidence of Curly's failing health is visible in his face and voice, his performance is amazing, and it is probably the last glimpse of the old Curly. Some fans think that \"A Bird in the Hand\" is the last great Curly short, but his coarse voice and slow movement are just too difficult to watch.  \n",
            "pos\t782\tAfter becoming completely addicted to Six Feet Under, I didn't think there would ever be another show that would come close to being as good as this show. Well, I was wrong! Lost is spellbinding!! I absolutely love this show and cannot turn it off. The richness of the characters, the intricacies of the plot, the beautiful setting are all amazing. I am totally and completely hooked. I don't know how the creators do it, but each character touches me very deeply. I feel their joy, their pain, everything, right down to my core!!! I don't have cable so I've been renting the series on Netflix. When I put it on I watch all the episodes at once and feel sad when it is over. I can't wait for the next disc to arrive at my house. This is probably the best TV show I have ever seen!!!  \n",
            "neg\t1708\tYou do realize that you've been watching the EXACT SAME SHOW for eight years, right? I could understand the initial curiosity of seeing strangers co-exist on an Island, but you'd think that after watching unkempt, stink-ladened heroes run roughshod through the bush with an egg on a spoon for half a decade would be enough to get you to commit to something a little more original (and interesting).<br /><br />And I'm not even speaking of the shows validity which for the record I find questionable. It's just hard to suspend disbelief for \"Bushy Bill\" eating a rat when the entire crew of producers and camera people are housed in an air conditioned make-shift bio-dome sipping frosty mochcinno's with moxy.<br /><br />What's the appeal here? I don't care about these people or their meandering lives. I just don't get it. But if you DO find yourself being captivated by hairy, unwashed people, I suggest you turn off your TV and just take a trip to your local bus station where you can see people like this in their TRUE habitat. They call them HOMELESS PEOPLE, and free of charge, you can sit back and marvel in their uncanny ability to retrieve various cigarette debris from a plethora of garbage canisters, eventually striking \"pay-dirt\" and fashioning a homemade Dr. Frankenstein-styled cancer-stick, all the while begging people for change for food when the stink of \"Aqua Velva\" on their breath is enough to suggest otherwise. And the best part? Much like Survivor, every week one member of the tribe \"Leaves\" the \"Island\" when they are unceremoniously sent packing to the local Institution when the frightening unmedicated state of full-blown schizophrenia kicks into gear! Now THAT'S ENTERTAINMENT!  \n",
            "neg\t2341\tOkay, as a long time Disney fan, I really -hate- direct-to-video Disney sequels. Walt HIMSELF didn't believe in them. He believed in \"AND THEY LIVED HAPPILY EVER AFTER\" being the end of it. But this one...REALLY ticked the taco. There were so many ripoffs of other Disney films in this, it wasn't funny. Quick summary, if you don't already know...: Melody, the daughter of Ariel and Prince Eric, is born. Ursula's sister, Morganna (who basically looks like Ursula, if she were to dye herself green and go on the Ally Macbeal starvation diet) shows up and, after trying to do the newborn tyke in, and failing, prophesizes doom for the characters. After that ordeal, Ariel goes into a lapse of being like her father, and refuses to tell Melody about her mermaid heritage, and later on, forbids her to go near the sea. Well surprise surprise. Melody finds out, being the stubborn brat she is, and runs away, then makes a deal with Morgana to become a mermaid, in exchange for something. (Gee does THAT sound familiar?) She becomes one, but in her half of the bargain, has to retrieve her granddaddy's Trident and bring it back to the sea witch. While doing THIS, she runs into a couple of outcast animals, a penguin and a walrus named Timon and Pumb--huh? wait...no! that's not Timon and Pumbaa! or is it? Could of fooled me. Anyway, i'd like to reveal more, but pretty much anything that could be guessed to happen does. OK so...long story short. This movie \"borrows\" too much from other (better) Disney films...and does it horribly. Come on...Tip and Dash? Why not just make Dash obscenely flatulent and make it an even more obvious ripoff! Ugh. Not to mention, the total character butchery of Ariel's persona. She's gone from being a freespirited, headstrong woman, to a clone of her father. Not good at all...they're basically telling us the sweet, firey little mermaid we've known to grow and love is dead. Plus Melody herself isn't such a great character either...she's damned annoying! And bratty! Not to mention what they've done to Flounder. Ugh...anyway if you decide to see this piece of created-mainly-for-profit-reasons, no-imagination, Eisner-sponsored c******t, I suggest maybe waiting 'till its on the Disney channel or some other tv station. Because, it's not even worth the price of a rental.<br /><br /> * out of ***** stars.  \n",
            "neg\t705\tThis movie is simply not worth the time or money spent. Full of clichés and a plot that makes absolutely no sense ! I cant believe that so many people have given this awful movie a 10. My guess is they are stooges of the movie maker. <br /><br />If I could give this movie a zero, I would. Too bad IMDb doesn't allow that. <br /><br />The only reason I watched it because I went with a friend who really wanted to see it. Whats sad is that I never had great expectations from this movie to begin with and yet I felt short changed. Take my word, don't waste your $8 on this piece of trash. The only entertainment I got out of the movie was making fun of the directors name. In all, highly NOT RECOMMENDED !  \n",
            "neg\t1370\tI'm sorry to say that there isn't really any way, in my opinion, that an Enzo would really be able to keep up with a Saleen S7 Twin Turbo. The power to weight advantage possessed by the S7 would just be too great. The S7 has a power:weight ratio of 3.93 lbs/hp while the Enzo has 4.61 lbs/hp. The S7s low end is much better too. Sorry Ferrari fans but the Saleen just gets it done so much better.<br /><br />As for other parts of this film, I just have to say it's so substandard as to be pathetic. The story is way too weak. The acting in this lemon is worse than daytime soaps.<br /><br />I can say that as far as it being a treatise on negative psychology its kind of a gem. This film is nothing if not a glaring definition as to what narcissism and sociopathy are all about. Its all about these rich punks getting their rocks off while showing only traces of feigned remorse for all the innocent road users they cause injury or death too.<br /><br />I can't give the film a \"1 Star\" rating because it didn't compel me to actually walk out of the theater. I also think that having an amazingly beautiful brunette with killer blue eyes as the leading female saves it from being completely abysmal....although there is no way her singing would put her on the cover of 'Variety'.<br /><br />ps: the guy who plays Jason is SOOOOO the skid row version of James Vanderbeek.  \n",
            "pos\t681\tSomething about \"Paulie\" touched my heart as few movies do. It is a witty, funny yet emotional movie. I'm a late comer in becoming a fan of this movie. I didn't see \"Paulie\" until May, 2004 and have since ordered the Widescreen DVD from a seller at eBay.<br /><br />The special effects of showing Paulie talking are superb. My son asked me how the bird knew so many phrases.Probably my favorite part of the movie is when Paulie is in Gena Rowlands (Ivy's) company followed by Cheech Marin (Ignacio). Tony Shalhoub (Misha) plays an excellent part as the good hearted human. You root for him all the way through the movie.<br /><br />You can't go wrong renting or buying this movie!!  \n",
            "neg\t1401\tIt really is that bad of a movie. My buddy rented it because he, well, is an idiot. But then again, I must be an idiot too because I watched the whole damn thing! The actors were on par with high school drama geeks who think that are going places. The only place they will be going is back to waiting tables at Luby's. All I could think of while I was watching this \"gem\" was how it actually got made. I mean, some \"screenwriter\" actually thought that this premise was fresh, original and lucrative. Then some moron with money believed in the script so much that he decided to fork some cash over with the naive misconception that he was going to make a return on it. Actors were cast, locations were scouted, make-up artists were hired, computer animators fresh out of Al Collins graphic Design School were brought in and this turd started to take form.<br /><br />There obviously were a ton of things that I hated about this move but the one thing the drove me the craziest was the overuse of music. Every single minute of this flick was scored. There was not a single break in music. And at times it was mixed higher than the dialogue, not that it made you miss some vital plot point or anything.<br /><br />After it was over, we decided to watch Mystic River. It was like driving a 1980 VW Diesel Rabbit then switching to a BMW 740il. You couldn't get two more opposite movies in terms of quality.  \n",
            "neg\t656\tmy friend bought the movie for 5€ (its is not even 1 cent worth), because they wrote it was like American pie. but we would soon find out that there is a long way from American pie to that piece of crap. it is not even a comedy, its more like a really really really bad documentary. not only the story is bad, the picture and sound also sucks to. they put in some alcohol, chicks, dwarfs and drunken teens. and the result is a disaster. if you see this movie don't buy it, rather spend your money on something else, and better. if you are gonna torture yourself, then don't invite your friend/s, unless you hate really much and you want to get rid of them.  \n",
            "\n",
            "\n",
            "PyTorchText BuketIterator\n",
            "\n",
            "Batch size: 10\n",
            "\n",
            "LABEL\tLENGTH\tTEXT\n",
            "pos\t609\tThat's My Bush is a live action project made by South Park creators Trey Parker and Matt Stone.The show was cancelled after one season, not because of bad reviews(it actually got good reviews), but because it was very expensive.That's my bush is a pretty funny spoof of an average network TV sitcom.It is also a political satire.Now, this is nowhere near as good as South Park, but it is a very funny spoof of a sitcom and also a pretty good political satire.The guy who plays in that's my bush looks a lot like him! If you can find the show, check it out.There are plenty of laughs to be had!<br /><br />9/10  \n",
            "neg\t610\tTerminus Paradis was exceptional, but \"Niki ardelean\" comes too late. We already have enough of this and we want something new.<br /><br />Big directors should have no problems seeing beyond their time, not behind. Why people see Romania only as a postrevolutionary country?<br /><br />We are just born not reincarnated, and nobody gives a s**t anymore about old times. Most people dont remember or dont want to remember, and the new generation of movie consumers dont understand a bit. This should be the first day of romanian movie not the final song - priveghi! Maybe younger directors should make the move.  \n",
            "neg\t612\tAwesomely improbable and foolish potboiler that at least has some redeeming, crisp location photography, but it's too unbelievable to generate much in the way of tension. I was kinda hoping that Stanwyck wouldn't make it back in time because, really, she was saddled with the wet, in more ways than one, husband,and she had an idiot child as well..why NOT run off with Meeker? But the nagging question remains..what sort of wood was that pier support made of if a rotten piece of it pulled off didn't float? Stanwyck, always impeccably professional, does the best she could with the material but it's threadbare.  \n",
            "pos\t613\tThe events of September 11 2001 do not need extra human interest in the shape of following the training of the rookie fireman or the progress of the two French brothers. In my view it would have been better to leave this out. I think the directors tried too hard, perhaps they felt that the events of the day needed a story as a backdrop. The comment of one of a policemen - \"this aint f***ing Disneyworld\" is apt.<br /><br />Nevertheless it is compelling viewing for the depiction of the events. The filmakers were in all the right places at the right times, no other footage from the day matches what they shot.  \n",
            "pos\t613\tOkay, first of all I got this movie as a Christmas present so it was FREE! FIRST - This movie was meant to be in stereoscopic 3D. It is for the most part, but whenever the main character is in her car the movie falls flat to 2D! What!!?!?! It's not that hard to film in a car!!! SECOND - The story isn't very good. There are a lot of things wrong with it.<br /><br />THIRD - Why are they showing all of the deaths in the beginning of the film! It made the movie suck whenever some was going to get killed!!! Watch it for a good laugh , but don't waste your time buying it. Just download it or something for cheap.  \n",
            "neg\t617\tI have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.  \n",
            "pos\t625\tFragglerock is excellent in the way that Schindler's List was excellent. A Great watch for children and adults of all genders. Big noses can be seen as hinting towards phallic symbols, in the same way that H.R. Puff N Stuff had hinted towards marijuana smoking. Your kids will love this movie. I enjoyed it very much as a child. My father showed me this movie as a child. He enjoyed it as well and pointed out that the exaggerated noses were phallic symbols. Although at the time I had no clue about what those were. The movie is comedy and adventure. The storyline is wacky and cheerful. I and you shall enjoy this together.  \n",
            "neg\t625\tSure I've seen bad movies in my life, but this one was so bad that I actually became angry in the theater. I wanted my money back. I wrote to the director asking him to refund my movie ticket, of course I didn't receive a refund (or even a reply) but it's the point that matters. On a scale of 1-10 I give this movie a -42. Why did the \"Jeep\" (Chevy Blazer??) stop running from being hit with a bat? Why did they hit the \"Jeep\"(Chevy Blazer?????) with the bat in the first place instead of cracking the bum's skull? The plot was thin, the movie filled with obvious clichés, and certain parts of it just didn't make any sense.  \n",
            "neg\t626\tEven 20+ years later, Ninja Mission stands out as the worst movie I ever managed to sit through. Scandanavian ninjas silently enter a scene, fire their obnoxiously noisy sub-machine guns with wild abandon, and then silently leave. Wow, how will we find those silent invisible assassins? Just follow the shell casings and smoke!Painfully bad dialog (or was it brilliant and just poorly translated?), not an Asian in sight in the cast, and a whopping total of 3 Asians among the stunt crew. The plot is ridiculous, the acting pretty much non-existent - then again, ninja can't act! Save yourselves - avoid watching at all costs!  \n",
            "pos\t626\tThis film is excellently paced, you never have to wait for a belly laugh to come up for more than about a minute and there's much more going on than the initial premise of the film. Throughout it there are mockeries of the traditional schmaltzy local-boys-done-good-overcoming-adversity genre of which this parodies. Don't let anyone tell you that they're trying to get cheap laughs just by using obscenities;- sure, there's plenty of that but it's all contextual, not gratuitous. I loved this film and it only cost me £2.99 on DVD , so in terms of entertainment value for money, it has been the best film I've seen this year.  \n",
            "\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "d2QsZ5yN8iDi"
      },
      "source": [
        "### Train Loop Examples\n",
        "\n",
        "Now let's look at a model training loop would look like. I printed the first 10 batches list of examples lengths to show how nicely they are grouped throughout the dataset!\n",
        "\n",
        "We see that we get same exact behavior as we did when using PyTorch Dataset. Now it depends on which way is easier for you to use PyTorchText BucketIterator: with PyTorch Dataset or with PyTorchText TabularDataset"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "M9WOC2Xe0MQs",
        "outputId": "b7b7fe84-d062-44fa-8f7e-9c582c7b5141",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Example of number of epochs.\n",
        "epochs = 1\n",
        "\n",
        "# Example of loop through each epoch.\n",
        "for epoch in range(epochs):\n",
        "\n",
        "  # Create batches - needs to be called before each loop.\n",
        "  torchtext_train_dataloader.create_batches()\n",
        "\n",
        "  # Loop through BucketIterator.\n",
        "  for sample_id, batch in enumerate(torchtext_train_dataloader.batches):\n",
        "    # Put all example.text of batch in single array.\n",
        "    batch_text = [example.text for example in batch]\n",
        "\n",
        "    print('Batch examples lengths: %s'.ljust(20) % str([len(text) for text in batch_text]))\n",
        "\n",
        "    # Let's break early, you get the idea.\n",
        "    if sample_id == 10:\n",
        "      break"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Batch examples lengths: [848, 848, 849, 849, 850, 852, 853, 854, 856, 857]\n",
            "Batch examples lengths: [779, 780, 780, 781, 781, 782, 782, 782, 783, 784]\n",
            "Batch examples lengths: [2100, 2103, 2104, 2109, 2114, 2135, 2147, 2151, 2158, 2164]\n",
            "Batch examples lengths: [903, 905, 910, 910, 910, 910, 914, 915, 916, 919]\n",
            "Batch examples lengths: [968, 968, 970, 970, 971, 972, 973, 975, 981, 981]\n",
            "Batch examples lengths: [806, 806, 807, 807, 808, 809, 810, 810, 811, 811]\n",
            "Batch examples lengths: [731, 733, 734, 735, 736, 736, 737, 737, 738, 739]\n",
            "Batch examples lengths: [357, 357, 358, 361, 362, 362, 362, 364, 366, 371]\n",
            "Batch examples lengths: [2330, 2335, 2337, 2350, 2351, 2353, 2367, 2374, 2376, 2381]\n",
            "Batch examples lengths: [1916, 1920, 1921, 1936, 1951, 1953, 1967, 1970, 1981, 1985]\n",
            "Batch examples lengths: [1395, 1398, 1399, 1402, 1403, 1412, 1412, 1413, 1414, 1414]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1YnDV4IQWF2v"
      },
      "source": [
        "## **Final Note**\n",
        "\n",
        "If you made it this far **Congrats!** 🎊 and **Thank you!** 🙏 for your interest in my tutorial!\n",
        "\n",
        "I've been using this code for a while now and I feel it got to a point where is nicely documented and easy to follow.\n",
        "\n",
        "Of course is easy for me to follow because I built it. That is why any feedback is welcome and it helps me improve my future tutorials!\n",
        "\n",
        "If you see something wrong please let me know by opening an issue on my [ml_things GitHub repository](https://github.com/gmihaila/ml_things/issues)!\n",
        "\n",
        "A lot of tutorials out there are mostly a one-time thing and are not being maintained. I plan on keeping my tutorials up to date as much as I can.\n",
        "\n",
        "## **Contact** 🎣\n",
        "\n",
        "🦊 GitHub: [gmihaila](https://github.com/gmihaila)\n",
        "\n",
        "🌐 Website: [gmihaila.github.io](https://gmihaila.github.io/)\n",
        "\n",
        "👔 LinkedIn: [mihailageorge](https://medium.com/r/?url=https%3A%2F%2Fwww.linkedin.com%2Fin%2Fmihailageorge)\n",
        "\n",
        "📬 Email: [georgemihaila@my.unt.edu.com](mailto:georgemihaila@my.unt.edu.com?subject=GitHub%20Website)"
      ]
    }
  ]
}