Skip to content

Commit 9e6be3f

Browse files
authored
v 0.7.5
- Fix numerical instability in `LayerNormalization` - update `PNN` api
1 parent df06f25 commit 9e6be3f

File tree

15 files changed

+67
-47
lines changed

15 files changed

+67
-47
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
timeout-minutes: 120
1818
strategy:
1919
matrix:
20-
python-version: [3.5,3.6,3.7]
21-
tf-version: [1.4.0,1.15.0,2.0.0]
20+
python-version: [3.6,3.7]
21+
tf-version: [1.4.0,1.15.0,2.1.0,2.2.0]
2222

2323
exclude:
2424
- python-version: 3.7

deepctr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .utils import check_version
22

3-
__version__ = '0.7.4'
3+
__version__ = '0.7.5'
44
check_version(__version__)

deepctr/layers/normalization.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313

1414
class LayerNormalization(Layer):
15-
def __init__(self, axis=-1, eps=1e-9, **kwargs):
15+
def __init__(self, axis=-1, eps=1e-9, center=True,
16+
scale=True, **kwargs):
1617
self.axis = axis
1718
self.eps = eps
19+
self.center = center
20+
self.scale = scale
1821
super(LayerNormalization, self).__init__(**kwargs)
1922

2023
def build(self, input_shape):
@@ -24,15 +27,21 @@ def build(self, input_shape):
2427
initializer=Zeros(), trainable=True)
2528
super(LayerNormalization, self).build(input_shape)
2629

27-
def call(self, x):
28-
mean = K.mean(x, axis=self.axis, keepdims=True)
29-
std = K.std(x, axis=self.axis, keepdims=True)
30-
return self.gamma * (x - mean) / (std + self.eps) + self.beta
30+
def call(self, inputs):
31+
mean = K.mean(inputs, axis=self.axis, keepdims=True)
32+
variance = K.mean(K.square(inputs - mean), axis=-1, keepdims=True)
33+
std = K.sqrt(variance + self.eps)
34+
outputs = (inputs - mean) / std
35+
if self.scale:
36+
outputs *= self.gamma
37+
if self.center:
38+
outputs += self.beta
39+
return outputs
3140

3241
def compute_output_shape(self, input_shape):
3342
return input_shape
3443

3544
def get_config(self, ):
36-
config = {'axis': self.axis, 'eps': self.eps}
45+
config = {'axis': self.axis, 'eps': self.eps, 'center': self.center, 'scale': self.scale}
3746
base_config = super(LayerNormalization, self).get_config()
3847
return dict(list(base_config.items()) + list(config.items()))

deepctr/models/pnn.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from ..layers.utils import concat_func
1616

1717

18-
def PNN(dnn_feature_columns, embedding_size=8, dnn_hidden_units=(128, 128), l2_reg_embedding=1e-5, l2_reg_dnn=0,
19-
init_std=0.0001, seed=1024, dnn_dropout=0, dnn_activation='relu', use_inner=True, use_outter=False,
20-
kernel_type='mat', task='binary'):
18+
def PNN(dnn_feature_columns, dnn_hidden_units=(128, 128), l2_reg_embedding=1e-5, l2_reg_dnn=0, init_std=0.0001,
19+
seed=1024, dnn_dropout=0, dnn_activation='relu', use_inner=True, use_outter=False, kernel_type='mat',
20+
task='binary'):
2121
"""Instantiates the Product-based Neural Network architecture.
2222
2323
:param dnn_feature_columns: An iterable containing all the features used by deep part of the model.
24-
:param embedding_size: positive integer,sparse feature embedding_size
2524
:param dnn_hidden_units: list,list of positive integer or empty list, the layer number and units in each layer of deep net
2625
:param l2_reg_embedding: float . L2 regularizer strength applied to embedding vector
2726
:param l2_reg_dnn: float. L2 regularizer strength applied to DNN
@@ -51,7 +50,7 @@ def PNN(dnn_feature_columns, embedding_size=8, dnn_hidden_units=(128, 128), l2_r
5150

5251
# ipnn deep input
5352
linear_signal = tf.keras.layers.Reshape(
54-
[len(sparse_embedding_list) * embedding_size])(concat_func(sparse_embedding_list))
53+
[sum(map(lambda x:int(x.shape[-1]) ,sparse_embedding_list))])(concat_func(sparse_embedding_list))
5554

5655
if use_inner and use_outter:
5756
deep_input = tf.keras.layers.Concatenate()(

docs/source/History.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# History
2+
3+
- 05/17/2020 : [v0.7.5](https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.5) released.Fix numerical instability in `LayerNormalization`.
24
- 03/15/2020 : [v0.7.4](https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.4) released.Add [FLEN](./Features.html#flen-field-leveraged-embedding-network) and `FieldWiseBiInteraction`.
35
- 03/04/2020 : [v0.7.3](https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.3) released.Fix the inconsistency of prediction results when the model is loaded with trained weights.
46
- 02/08/2020 : [v0.7.2](https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.2) released.Fix some bugs.

docs/source/Quick-Start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ fixlen_feature_columns = [SparseFeat(feat, vocabulary_size=1e6,embedding_dim=4,
9292
```
9393
- generate feature columns
9494
```python
95-
dnn_feature_columns = sparse_feature_columns + dense_feature_columns
96-
linear_feature_columns = sparse_feature_columns + dense_feature_columns
95+
dnn_feature_columns = fixlen_feature_columns
96+
linear_feature_columns = fixlen_feature_columns
9797

9898
feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns)
9999

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# The short X.Y version
2727
version = ''
2828
# The full version, including alpha/beta/rc tags
29-
release = '0.7.4'
29+
release = '0.7.5'
3030

3131

3232
# -- General configuration ---------------------------------------------------

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ You can read the latest code at https://github.com/shenweichen/DeepCTR
3535
News
3636
-----
3737

38+
05/17/2020 : Fix numerical instability in ``LayerNormalization``. `Changelog <https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.5>`_
39+
3840
03/15/2020 : Add `FLEN <./Features.html#flen-field-leveraged-embedding-network>`_ (`中文介绍 <https://zhuanlan.zhihu.com/p/92787577>`_) and ``FieldWiseBiInteraction``. `Changelog <https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.4>`_
3941

4042
03/04/2020 : Fix the inconsistency of prediction results when the model is loaded with trained weights. `Changelog <https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.3>`_
4143

42-
02/08/2020 : Fix some bugs. `Changelog <https://github.com/shenweichen/DeepCTR/releases/tag/v0.7.2>`_
43-
4444
DisscussionGroup
4545
-----------------------
4646

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setuptools.setup(
1111
name="deepctr",
12-
version="0.7.4",
12+
version="0.7.5",
1313
author="Weichen Shen",
1414
author_email="[email protected]",
1515
description="Easy-to-use,Modular and Extendible package of deep learning based CTR(Click Through Rate) prediction models with tensorflow 1.x and 2.x .",

tests/layers/activations_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from deepctr.layers import activation
2-
from tensorflow.python.keras.utils import CustomObjectScope
2+
try:
3+
from tensorflow.python.keras.utils import CustomObjectScope
4+
except:
5+
from tensorflow.keras.utils import CustomObjectScope
36
from tests.utils import layer_test
47

58

0 commit comments

Comments
 (0)