Skip to content

Commit 627caf4

Browse files
authored
Merge pull request #20 from jrzaurin/wide_embedding
Wide embedding
2 parents 65465a4 + e40a088 commit 627caf4

37 files changed

+686
-385
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
[![Build Status](https://travis-ci.org/jrzaurin/pytorch-widedeep.svg?branch=master)](https://travis-ci.org/jrzaurin/pytorch-widedeep)
77
[![Documentation Status](https://readthedocs.org/projects/pytorch-widedeep/badge/?version=latest)](https://pytorch-widedeep.readthedocs.io/en/latest/?badge=latest)
8+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/jrzaurin/pytorch-widedeep/graphs/commit-activity)
9+
10+
Platform | Version Support
11+
---------|:---------------
12+
OSX | [![Python 3.6 3.7](https://img.shields.io/badge/python-3.6%20%203.7-blue.svg)](https://www.python.org/)
13+
Linux | [![Python 3.6 3.7 3.8](https://img.shields.io/badge/python-3.6%20%203.7%203.8-blue.svg)](https://www.python.org/)
814

915
# pytorch-widedeep
1016

@@ -34,11 +40,11 @@ few lines of code.
3440
<img width="600" src="docs/figures/architecture_1.png">
3541
</p>
3642

37-
Architecture 1 combines the `Wide`, one-hot encoded features with the outputs
38-
from the `DeepDense`, `DeepText` and `DeepImage` components connected to a
39-
final output neuron or neurons, depending on whether we are performing a
40-
binary classification or regression, or a multi-class classification. The
41-
components within the faded-pink rectangles are concatenated.
43+
Architecture 1 combines the `Wide`, Linear model with the outputs from the
44+
`DeepDense`, `DeepText` and `DeepImage` components connected to a final output
45+
neuron or neurons, depending on whether we are performing a binary
46+
classification or regression, or a multi-class classification. The components
47+
within the faded-pink rectangles are concatenated.
4248

4349
In math terms, and following the notation in the
4450
[paper](https://arxiv.org/abs/1606.07792), Architecture 1 can be formulated
@@ -65,10 +71,10 @@ otherwise".*
6571
<img width="600" src="docs/figures/architecture_2.png">
6672
</p>
6773

68-
Architecture 2 combines the `Wide` one-hot encoded features with the Deep
69-
components of the model connected to the output neuron(s), after the different
70-
Deep components have been themselves combined through a FC-Head (that I refer
71-
as `deephead`).
74+
Architecture 2 combines the `Wide`, Linear model with the Deep components of
75+
the model connected to the output neuron(s), after the different Deep
76+
components have been themselves combined through a FC-Head (that I refer as
77+
`deephead`).
7278

7379
In math terms, and following the notation in the
7480
[paper](https://arxiv.org/abs/1606.07792), Architecture 2 can be formulated
@@ -84,7 +90,8 @@ and `DeepImage` are optional. `pytorch-widedeep` includes standard text (stack
8490
of LSTMs) and image (pre-trained ResNets or stack of CNNs) models. However,
8591
the user can use any custom model as long as it has an attribute called
8692
`output_dim` with the size of the last layer of activations, so that
87-
`WideDeep` can be constructed. See the examples folder for more information.
93+
`WideDeep` can be constructed. See the examples folder or the docs for more
94+
information.
8895

8996

9097
### Installation
@@ -112,14 +119,6 @@ cd pytorch-widedeep
112119
pip install -e .
113120
```
114121

115-
### Examples
116-
117-
There are a number of notebooks in the `examples` folder plus some additional
118-
files. These notebooks cover most of the utilities of this package and can
119-
also act as documentation. In the case that github does not render the
120-
notebooks, or it renders them missing some parts, they are saved as markdown
121-
files in the `docs` folder.
122-
123122
### Quick start
124123

125124
Binary classification with the [adult
@@ -128,6 +127,7 @@ using `Wide` and `DeepDense` and defaults settings.
128127

129128
```python
130129
import pandas as pd
130+
import numpy as np
131131
from sklearn.model_selection import train_test_split
132132

133133
from pytorch_widedeep.preprocessing import WidePreprocessor, DensePreprocessor
@@ -166,7 +166,7 @@ target = df_train[target_col].values
166166
# wide
167167
preprocess_wide = WidePreprocessor(wide_cols=wide_cols, crossed_cols=cross_cols)
168168
X_wide = preprocess_wide.fit_transform(df_train)
169-
wide = Wide(wide_dim=X_wide.shape[1], pred_dim=1)
169+
wide = Wide(wide_dim=np.unique(X_wide).shape[0], pred_dim=1)
170170

171171
# deepdense
172172
preprocess_deep = DensePreprocessor(embed_cols=embed_cols, continuous_cols=cont_cols)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.2
1+
0.4.5
File renamed without changes.

docs/figures/architecture_1.png

-917 Bytes
Loading

docs/figures/architecture_2.png

-913 Bytes
Loading

docs/index.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ Documentation
1818
Utilities <utils/index>
1919
Preprocessing <preprocessing>
2020
Model Components <model_components>
21-
Wide and Deep Models <wide_deep/index>
21+
Metrics <metrics>
22+
Callbacks <callbacks>
23+
Focal Loss <losses>
24+
Wide and Deep Models <wide_deep>
2225
Examples <examples>
2326

2427

@@ -45,12 +48,11 @@ Architectures
4548
:width: 600px
4649
:align: center
4750

48-
Architecture 1 combines the ``Wide``, one-hot encoded features with the
49-
outputs from the ``DeepDense``, ``DeepText`` and ``DeepImage`` components
50-
connected to a final output neuron or neurons, depending on whether we are
51-
performing a binary classification or regression, or a multi-class
52-
classification. The components within the faded-pink rectangles are
53-
concatenated.
51+
Architecture 1 combines the `Wide`, Linear model with the outputs from the
52+
`DeepDense`, `DeepText` and `DeepImage` components connected to a final output
53+
neuron or neurons, depending on whether we are performing a binary
54+
classification or regression, or a multi-class classification. The components
55+
within the faded-pink rectangles are concatenated.
5456

5557
In math terms, and following the notation in the `paper
5658
<https://arxiv.org/abs/1606.07792>`_, Architecture 1 can be formulated as:
@@ -76,10 +78,10 @@ is the activation function.
7678
:width: 600px
7779
:align: center
7880

79-
Architecture 2 combines the ``Wide`` one-hot encoded features with the Deep
80-
components of the model connected to the output neuron(s), after the different
81-
Deep components have been themselves combined through a FC-Head (referred as
82-
as ``deephead``).
81+
Architecture 2 combines the `Wide`, Linear model with the Deep components of
82+
the model connected to the output neuron(s), after the different Deep
83+
components have been themselves combined through a FC-Head (that I refer as
84+
`deephead`).
8385

8486
In math terms, and following the notation in the `paper
8587
<https://arxiv.org/abs/1606.07792>`_, Architecture 2 can be formulated as:
File renamed without changes.
File renamed without changes.

docs/model_components.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
The ``models`` module
2-
=====================
2+
======================
33

44
This module contains the four main Wide and Deep model component. These are:
55
``Wide``, ``DeepDense``, ``DeepText`` and ``DeepImage``.
66

7-
87
.. autoclass:: pytorch_widedeep.models.wide.Wide
98
:members:
109
:undoc-members:

docs/quick_start.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The following code snippet is not directly related to ``pytorch-widedeep``.
1515
.. code-block:: python
1616
1717
import pandas as pd
18+
import numpy as np
1819
from sklearn.model_selection import train_test_split
1920
2021
df = pd.read_csv("data/adult/adult.csv.zip")
@@ -23,6 +24,7 @@ The following code snippet is not directly related to ``pytorch-widedeep``.
2324
df_train, df_test = train_test_split(df, test_size=0.2, stratify=df.income_label)
2425
2526
27+
2628
Prepare the wide and deep columns
2729
---------------------------------
2830

@@ -63,7 +65,7 @@ Preprocessing and model components definition
6365
# wide
6466
preprocess_wide = WidePreprocessor(wide_cols=wide_cols, crossed_cols=cross_cols)
6567
X_wide = preprocess_wide.fit_transform(df_train)
66-
wide = Wide(wide_dim=X_wide.shape[1], pred_dim=1)
68+
wide = Wide(wide_dim=np.unique(X_wide).shape[0], pred_dim=1)
6769
6870
# deepdense
6971
preprocess_deep = DensePreprocessor(embed_cols=embed_cols, continuous_cols=cont_cols)

0 commit comments

Comments
 (0)