{ "info": { "author": "Somshubra Majumdar", "author_email": "titu1994@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "\n# TabNet for Tensorflow 2.0\nA Tensorflow 2.0 port for the paper [TabNet: Attentive Interpretable Tabular Learning](https://arxiv.org/abs/1908.07442), whose original codebase is available at https://github.com/google-research/google-research/blob/master/tabnet.\n\n\n\nThe above image is obtained from the paper, where the model is built of blocks in two stages - one to attend to the input features and anither to construct the output of the model. \n\n# Differences from Paper\nThere are two major differences from the paper and the official implementation.\n\n1) This implementation offers a choice in the normalization method, between the regular `Batch Normalization` from the paper and `Group Normalization`.\n - It has been observed that the paper uses very large batch sizes to stabilie Batch Normalization and obtain good generalization. An issue with this is computational cost. \n - Therefore Group Normalization (with number of groups set as 1, aka Instance Normalization) offers a reasonable alternative which is independent of the batch size.\n - One can set `num_groups` to 1 for `Instance Normalization` type behaviour, or to -1 for `Layer Normalization` type behaviour.\n\n2) This implementation does not strictly need feature columns as input. \n - While this model was originally developed for tabulur data, there is no hard requirement for that to be the only type of input it accepts.\n - By passing `feature_columns=None` and explicitly specifying the input dimensionality of the data (using `num_features`), we can get a semi-interpretable result from even image data (after flattening it into a long vector).\n\n# Installation\n\n - For latest release branch\n```bash\n$ pip install --upgrade tabnet\n```\n\n - For Master branch.\n```bash\n$ pip install git+https://github.com/titu1994/tf-TabNet.git\n```\n\nAs Tensorflow can be used with either a CPU or GPU, the package can be installed with the conditional requirements using `[cpu]` or `[gpu]` as follows.\n\n```bash\n$ pip install tabnet[cpu]\n$ pip install tabnet[gpu]\n```\n\n# Usage\n\nThe script `tabnet.py` can be imported to yield either the `TabNet` building block, or the `TabNetClassification` and `TabNetRegression` models, which add appropriate heads for the basic `TabNet` model. If the classification or regression head is to be customized, it is recommended to compose a new model with the `TabNet` as the base of the model.\n\n```python\nfrom tabnet import TabNet, TabNetClassification\n\nmodel = TabNetClassification(feature_list, num_classes, ...)\n```\n\nAs the models use custom objects, it is necessary to import `custom_objects.py` in an evaluation only script.\n\n# Mask Visualization\nThe masks of the TabNet can be obtained by using the TabNet class properties\n - `feature_selection_masks`: Returns a list of 1 or more masks at intermediate decision steps. Number of masks = number of decision steps - 1\n - `aggregate_feature_selection_mask`: Returns a single tensor which is the average activation of the masks over that batch of training samples.\n\n These masks can be obtained as `TabNet.feature_selection_masks`. Since the `TabNetClassification` and `TabNetRegression` models are composed of `TabNet`, the masks can be obtained as `model.tabnet.*`\n\n ## Mask Generation must be in Eager Execution Mode\n Note: Due to autograph, the outputs of the model when using `fit()` or `predict()` Keras APIs will \n generally be graph based Tensors, not EagerTensors. Since the masks are generated inside the `Model.call()` method,\n it is necessary to force the model to behave in Eager execution mode, not in Graph mode.\n\n Therefore there are two ways to force the model into eager mode:\n\n 1) Get tensor data samples, and directly `call` the model using this data as below :\n\n ```python\nx, _ = next(iter(tf_dataset)) # Assuming it generates an (x, y) tuple.\n_ = model(x) # This forces eager execution.\n ```\n\n 2) Or another choice is to build a seperate model (but here you will pass the `dynamic=True` flag to the model constructor),\n load the weights and parameters in this model, and call `model.predict(x)`. This should also force eager execution mode.\n\n ```python\nnew_model = TabNetClassification(..., dynamic=True)\nnew_model.load_weights('path/to/weights)')\n\nx, _ = next(iter(tf_dataset)) # Assuming it generates an (x, y) tuple.\nmodel.predict(x)\n ```\n\n ---\n\nAfter the model has been forced into Eager Execution mode, the masks can be visualized in Tensorboard as follows - \n```python\nwriter = tf.summary.create_file_writer(\"logs/\")\nwith writer.as_default():\n for i, mask in enumerate(model.tabnet.feature_selection_masks):\n print(\"Saving mask {} of shape {}\".format(i + 1, mask.shape))\n tf.summary.image('mask_at_iter_{}'.format(i + 1), step=0, data=mask, max_outputs=1)\n writer.flush()\n\n agg_mask = model.tabnet.aggregate_feature_selection_mask\n print(\"Saving aggregate mask of shape\", agg_mask.shape)\n tf.summary.image(\"Aggregate Mask\", step=0, data=agg_mask, max_outputs=1)\n writer.flush()\nwriter.close()\n```\n\n# Requirements\n- Tensorflow 2.0+ (1.14+ with V2 compat enabled may be sufficient for 1.x)\n- Tensorflow-datasets (Only required for evaluating `train_iris.py`)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/titu1994/tf-TabNet", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/titu1994/tf-TabNet", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "tabnet", "package_url": "https://pypi.org/project/tabnet/", "platform": "", "project_url": "https://pypi.org/project/tabnet/", "project_urls": { "Download": "https://github.com/titu1994/tf-TabNet", "Homepage": "https://github.com/titu1994/tf-TabNet" }, "release_url": "https://pypi.org/project/tabnet/0.1.3/", "requires_dist": [ "tensorflow ; extra == 'cpu'", "tensorflow-gpu ; extra == 'gpu'" ], "requires_python": ">=3.0.0", "summary": "Tensorflow 2.0 implementation of TabNet of any configuration.", "version": "0.1.3" }, "last_serial": 5957522, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "7d8703c96ff4097da99a48e0f90e9c69", "sha256": "5a7eed09b7fc3bca107b2d6fae8ac804d6bbb67913302922eb3b6cf763d4d16b" }, "downloads": -1, "filename": "tabnet-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7d8703c96ff4097da99a48e0f90e9c69", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.0.0", "size": 12916, "upload_time": "2019-10-09T02:22:29", "url": "https://files.pythonhosted.org/packages/e9/f3/86af359b9ad97067f15ceda274b01d35a6e93565c7b2e377d3b1ed5d651a/tabnet-0.1.0-py2.py3-none-any.whl" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "4ca72add46e56969397ef6f9f23622fb", "sha256": "11d9fcd59e4069376acc5a867e3c0cc6336c34d8441a94c4d81bd4c8134d6f84" }, "downloads": -1, "filename": "tabnet-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4ca72add46e56969397ef6f9f23622fb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.0.0", "size": 12954, "upload_time": "2019-10-09T02:35:31", "url": "https://files.pythonhosted.org/packages/0c/0b/36ebbecb381e104bbcf7d95fe3058db13e072f1e8f0eeaa13d1837e6134a/tabnet-0.1.1-py2.py3-none-any.whl" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "8d35f7129edb2da0ea1a866df758d217", "sha256": "c81201ffa267db0ed7d7c8feb93d7c83753bdf639b70d88a9f818cdeae4ba34e" }, "downloads": -1, "filename": "tabnet-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8d35f7129edb2da0ea1a866df758d217", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.0.0", "size": 12970, "upload_time": "2019-10-09T06:09:19", "url": "https://files.pythonhosted.org/packages/d8/70/a3ecf48575f68f61d417e7d208928a0bd6b9859f38ac4d11336b3e1b5cbc/tabnet-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0528239545423f9295bd305ac937c8fa", "sha256": "78fde0612d0c67ad3265eb053a5d91134aeddec401ea7c24d68c9a277c876ae4" }, "downloads": -1, "filename": "tabnet-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0528239545423f9295bd305ac937c8fa", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0.0", "size": 14598, "upload_time": "2019-10-09T06:09:21", "url": "https://files.pythonhosted.org/packages/55/1e/64fba7964460ca449eac6c33dc9ad91d52e253adf68a8b2fdfe28b5fd8c7/tabnet-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "4640ba61d0e84f94b4287f49f88662c7", "sha256": "ff013ac049711f2654f5e42b10003036a68e0be212e247ff1a4d1e97156d033c" }, "downloads": -1, "filename": "tabnet-0.1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4640ba61d0e84f94b4287f49f88662c7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.0.0", "size": 12974, "upload_time": "2019-10-10T23:32:32", "url": "https://files.pythonhosted.org/packages/95/2e/fc30ad2f5aa88243daddb3a72efe1952e51fab4e5d342f3866a50fe1f8c7/tabnet-0.1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b454f1b9d0f59d49f40698b5aff3c9e", "sha256": "7d702fafc1bcec90917a1b2eb43bf128ffd16954eff354ef2dd45e6006800377" }, "downloads": -1, "filename": "tabnet-0.1.3.tar.gz", "has_sig": false, "md5_digest": "2b454f1b9d0f59d49f40698b5aff3c9e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0.0", "size": 14603, "upload_time": "2019-10-10T23:32:34", "url": "https://files.pythonhosted.org/packages/ea/4d/8b55493dffe885eb2065ab275d18c4c5cbe46549a718be86a3a71331e7df/tabnet-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4640ba61d0e84f94b4287f49f88662c7", "sha256": "ff013ac049711f2654f5e42b10003036a68e0be212e247ff1a4d1e97156d033c" }, "downloads": -1, "filename": "tabnet-0.1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4640ba61d0e84f94b4287f49f88662c7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.0.0", "size": 12974, "upload_time": "2019-10-10T23:32:32", "url": "https://files.pythonhosted.org/packages/95/2e/fc30ad2f5aa88243daddb3a72efe1952e51fab4e5d342f3866a50fe1f8c7/tabnet-0.1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b454f1b9d0f59d49f40698b5aff3c9e", "sha256": "7d702fafc1bcec90917a1b2eb43bf128ffd16954eff354ef2dd45e6006800377" }, "downloads": -1, "filename": "tabnet-0.1.3.tar.gz", "has_sig": false, "md5_digest": "2b454f1b9d0f59d49f40698b5aff3c9e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0.0", "size": 14603, "upload_time": "2019-10-10T23:32:34", "url": "https://files.pythonhosted.org/packages/ea/4d/8b55493dffe885eb2065ab275d18c4c5cbe46549a718be86a3a71331e7df/tabnet-0.1.3.tar.gz" } ] }