Downloads · 30 days
11
5% of all-time downloads
keras-io/neural-decision-forest
neural-decision-forest is a machine learning model from keras-io. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for tf-keras. The card lists the license as apache-2.0.
Classification with Neural Decision Forests This is an example notebook for Keras sprint prepared by Hugging Face. Keras Sprint aims to reproduce Keras examples and build interactive demos to them. The markdown parts…
Downloads · 30 days
11
5% of all-time downloads
All-time downloads
233
Public
Repo size
7.2 MB
Likes
2
Public
Click a slice to open those files.
.pb4 MB · 56%
From the Hugging Face model README
Classification with Neural Decision Forests This is an example notebook for Keras sprint prepared by Hugging Face. Keras Sprint aims to reproduce Keras examples and build interactive demos to them. The markdown parts beginning with 🤗 and the following code snippets are the parts added by Hugging Face team to give you an example of how to host your model and build a demo.
Original Author of the Neural Decision Forests Example: Khalid Salama
This example provides an implementation of the Deep Neural Decision Forest model introduced by P. Kontschieder et al. for structured data classification. It demonstrates how to build a stochastic and differentiable decision tree model, train it end-to-end, and unify decision trees with deep representation learning.
| Numerical Features | Categorical Features |
|---|---|
| age | workclass |
| education-num | education |
| capital-gain | marital-status |
| capital-loss | occupation |
| hours-per-week | relationship |
| race | |
| gender | |
| native-country |
Dropped Feature: fnlwgt
Labelled Feature: income_bracket
The dataset comes in two parts meant for training and testing. The training dataset has 32561 samples whereas the test dataset has 16282 samples.
We create an input function to read and parse the file, and convert features and labels into a tf.data.Dataset for training and validation. We also preprocess the input by mapping the target label to an index. We also use layers.StringLookup to prepare categorical data.
Encode Features: We encode the categorical and numerical features as follows:
Create a lookup to convert a string values to an integer indices. Since we are not using a mask token, nor expecting any out of vocabulary (oov) token, we set mask-token to None and num-oov-indices to 0.
Categorical Features: Create an embedding layer with the specified dimensions.
Numerical Features: Use tf.expand_dims on Numerical feature as it is.
Create Model:
A neural decision tree model has two sets of weights to learn. The first set is pi, which represents the probability distribution of the classes in the tree leaves. The second set is the weights of the routing layer decision-fn, which represents the probability of going to each leave. The forward pass of the model works as follows:
SparseCategoricalCrossentropy.SparseCategoricalAccuracy.Adam with a learning rate of 0.001.The following hyperparameters were used during training:
| Hyperparameters | Value |
|---|---|
| name | Adam |
| learning-rate | 0.01 |
| batch-size | 265 |
| num-epochs | 5 |
| num-trees | 10 |
| depth | 10 |
| used-features-rate | 1.0 |
| num-classes | 2 |