Skip to content

Commit 5ea29cb

Browse files
authored
Merge pull request #8 from manujosephv/develop
Develop
2 parents 10dbb12 + 6f66be2 commit 5ea29cb

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
![PyTorch Tabular](docs/imgs/pytorch_tabular_logo.png)
1+
![PyTorch Tabular](docs/imgs/pytorch_tabular_logo.png)
2+
23
[![pypi](https://img.shields.io/pypi/v/pytorch_tabular.svg)](https://pypi.python.org/pypi/pytorch_tabular)
34
[![travis](https://img.shields.io/travis/manujosephv/pytorch_tabular.svg)](https://travis-ci.com/manujosephv/pytorch_tabular)
45
[![documentation status](https://readthedocs.org/projects/pytorch_tabular/badge/?version=latest)](https://pytorch_tabular.readthedocs.io/en/latest/?badge=latest)
@@ -62,9 +63,11 @@ For complete Documentation with tutorials visit []
6263

6364
## Available Models
6465

65-
* FeedForward Network with Category Embedding is a simple FF network, but with and Embedding layers for the categorical columns.
66+
* FeedForward Network with Category Embedding is a simple FF network, but with an Embedding layers for the categorical columns.
6667
* [Neural Oblivious Decision Ensembles for Deep Learning on Tabular Data](https://arxiv.org/abs/1909.06312) is a model presented in ICLR 2020 and according to the authors have beaten well-tuned Gradient Boosting models on many datasets.
6768
* [TabNet: Attentive Interpretable Tabular Learning](https://arxiv.org/abs/1908.07442) is another model coming out of Google Research which uses Sparse Attention in multiple steps of decision making to model the output.
69+
* [Mixture Density Networks](https://publications.aston.ac.uk/id/eprint/373/1/NCRG_94_004.pdf) is a regression model which uses gaussian components to approximate the target function and provide a probabilistic prediction out of the box.
70+
* [AutoInt: Automatic Feature Interaction Learning via Self-Attentive Neural Networks](https://arxiv.org/abs/1810.11921) is a model which tries to learn interactions between the features in an automated way and create a better representation and then use this representation in downstream task
6871

6972
To implement new models, see the [How to implement new models tutorial](https://github.com/manujosephv/pytorch_tabular/blob/main/docs/04-Implementing%20New%20Architectures.ipynb). It covers basic as well as advanced architectures.
7073

pytorch_tabular/models/mixture_density/mdn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ def unpack_input(self, x: Dict):
378378
class NODEMDN(BaseMDN):
379379
def __init__(self, config: DictConfig, **kwargs):
380380
super().__init__(config, **kwargs)
381+
382+
def subset(self, x):
383+
return x[..., :].mean(dim=-2)
381384

382385
def _build_network(self):
383386
self.hparams.node_input_dim = (
@@ -387,10 +390,7 @@ def _build_network(self):
387390
# average first n channels of every tree, where n is the number of output targets for regression
388391
# and number of classes for classification
389392

390-
def subset(x):
391-
return x[..., :].mean(dim=-2)
392-
393-
output_response = utils.Lambda(subset)
393+
output_response = utils.Lambda(self.subset)
394394
self.backbone = nn.Sequential(backbone, output_response)
395395
# Adding the last layer
396396
self.hparams.mdn_config.input_dim = backbone.output_dim

pytorch_tabular/models/node/node_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def __init__(self, config: DictConfig, **kwargs):
6060
if config.embed_categorical:
6161
self.embedding_cat_dim = sum([y for x, y in config.embedding_dims])
6262
super().__init__(config, **kwargs)
63+
64+
def subset(self, x):
65+
return x[..., : self.hparams.output_dim].mean(dim=-2)
6366

6467
def _build_network(self):
6568
if self.hparams.embed_categorical:
@@ -79,10 +82,7 @@ def _build_network(self):
7982
# average first n channels of every tree, where n is the number of output targets for regression
8083
# and number of classes for classification
8184

82-
def subset(x):
83-
return x[..., : self.hparams.output_dim].mean(dim=-2)
84-
85-
self.output_response = utils.Lambda(subset)
85+
self.output_response = utils.Lambda(self.subset)
8686

8787
def unpack_input(self, x: Dict):
8888
if self.hparams.embed_categorical:

pytorch_tabular/models/node/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ def _threshold_and_support(input, dim=-1):
9797
return tau, support_size
9898

9999

100-
sparsemax = lambda input, dim=-1: SparsemaxFunction.apply(input, dim)
101-
sparsemoid = lambda input: (0.5 * input + 0.5).clamp_(0, 1)
100+
def sparsemax(input, dim=-1):
101+
return SparsemaxFunction.apply(input, dim)
102+
103+
104+
def sparsemoid(input):
105+
return (0.5 * input + 0.5).clamp_(0, 1)
106+
# sparsemax = lambda input, dim=-1: SparsemaxFunction.apply(input, dim)
107+
# sparsemoid = lambda input: (0.5 * input + 0.5).clamp_(0, 1)
102108

103109

104110
class Entmax15Function(Function):
@@ -184,7 +190,9 @@ def _backward(output, grad_output):
184190
return grad_input
185191

186192

187-
entmax15 = lambda input, dim=-1: Entmax15Function.apply(input, dim)
193+
def entmax15(input, dim=-1):
194+
return Entmax15Function.apply(input, dim)
195+
# entmax15 = lambda input, dim=-1: Entmax15Function.apply(input, dim)
188196
entmoid15 = Entmoid15.apply
189197

190198

tests/test_common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
)
1616

1717
MODEL_CONFIG_SAVE_TEST = [
18-
CategoryEmbeddingModelConfig,
19-
AutoIntConfig,
20-
TabNetModelConfig,
18+
(CategoryEmbeddingModelConfig, dict(layers="10-20")),
19+
(AutoIntConfig, dict(num_heads=1,num_attn_blocks=1,)),
20+
(NodeConfig, dict(num_trees=100, depth=2)),
21+
(TabNetModelConfig, dict(n_a=2, n_d=2)),
2122
]
2223

2324
MODEL_CONFIG_FEATURE_EXT_TEST = [
@@ -67,7 +68,8 @@ def test_save_load(
6768
continuous_cols=continuous_cols,
6869
categorical_cols=categorical_cols,
6970
)
70-
model_config_params = dict(task="regression")
71+
model_config_class, model_config_params = model_config_class
72+
model_config_params['task']="regression"
7173
model_config = model_config_class(**model_config_params)
7274
trainer_config = TrainerConfig(
7375
max_epochs=3, checkpoints=None, early_stopping=None, gpus=0, fast_dev_run=True

0 commit comments

Comments
 (0)