Skip to content

Commit d5f6647

Browse files
authored
Dev swc (#377)
- enhance the compatibility for tf 2.5 - add training param to activation layer - add PositionEncoding Layer
1 parent ef3eff6 commit d5f6647

36 files changed

+276
-187
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ assignees: ''
88
---
99

1010
**Describe the bug(问题描述)**
11-
A clear and concise description of what the bug is.
11+
A clear and concise description of what the bug is.Better with standalone code to reproduce the issue.
1212

1313
**To Reproduce(复现步骤)**
1414
Steps to reproduce the behavior:
@@ -18,9 +18,9 @@ Steps to reproduce the behavior:
1818
4. See error
1919

2020
**Operating environment(运行环境):**
21-
- python version [e.g. 3.5, 3.7]
22-
- tensorflow version [e.g. 1.4.0, 1.15.0, 2.4.0]
23-
- deepctr version [e.g. 0.8.3,]
21+
- python version [e.g. 3.6, 3.7]
22+
- tensorflow version [e.g. 1.4.0, 1.15.0, 2.5.0]
23+
- deepctr version [e.g. 0.8.6,]
2424

2525
**Additional context**
2626
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/question.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Add any other context about the problem here.
1616

1717
**Operating environment(运行环境):**
1818
- python version [e.g. 3.6]
19-
- tensorflow version [e.g. 1.4.0, 1.5.0, 2.4.0]
20-
- deepctr version [e.g. 0.8.3,]
19+
- tensorflow version [e.g. 1.4.0, 1.15.0, 2.5.0]
20+
- deepctr version [e.g. 0.8.6,]

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ jobs:
1414
build:
1515

1616
runs-on: ubuntu-latest
17-
timeout-minutes: 120
17+
timeout-minutes: 180
1818
strategy:
1919
matrix:
2020
python-version: [3.6,3.7]
21-
tf-version: [1.4.0,1.15.0,2.1.0,2.4.0]
21+
tf-version: [1.4.0,1.15.0,2.1.0,2.5.0]
2222

2323
exclude:
2424
- python-version: 3.7
2525
tf-version: 1.4.0
26+
- python-version: 3.7
27+
tf-version: 1.15.0
2628

2729
steps:
2830

@@ -40,7 +42,7 @@ jobs:
4042
pip install -q requests
4143
pip install -e .
4244
- name: Test with pytest
43-
timeout-minutes: 120
45+
timeout-minutes: 180
4446
run: |
4547
pip install -q pytest
4648
pip install -q pytest-cov

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
[![Documentation Status](https://readthedocs.org/projects/deepctr-doc/badge/?version=latest)](https://deepctr-doc.readthedocs.io/)
1313
![CI status](https://github.com/shenweichen/deepctr/workflows/CI/badge.svg)
14-
[![Coverage Status](https://coveralls.io/repos/github/shenweichen/DeepCTR/badge.svg?branch=master)](https://coveralls.io/github/shenweichen/DeepCTR?branch=master)
14+
[![codecov](https://codecov.io/gh/shenweichen/DeepCTR/branch/master/graph/badge.svg)](https://codecov.io/gh/shenweichen/DeepCTR)
1515
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d4099734dc0e4bab91d332ead8c0bdd0)](https://www.codacy.com/gh/shenweichen/DeepCTR?utm_source=github.com&utm_medium=referral&utm_content=shenweichen/DeepCTR&utm_campaign=Badge_Grade)
1616
[![Disscussion](https://img.shields.io/badge/chat-wechat-brightgreen?style=flat)](./README.md#DisscussionGroup)
1717
[![License](https://img.shields.io/github/license/shenweichen/deepctr.svg)](https://github.com/shenweichen/deepctr/blob/master/LICENSE)
@@ -81,7 +81,7 @@ If you find this code useful in your research, please cite it using the followin
8181
## DisscussionGroup
8282

8383
- [Discussions](https://github.com/shenweichen/DeepCTR/discussions)
84-
- 公众号:**浅梦的学习笔记**
84+
- 公众号:**浅梦学习笔记**
8585
- wechat ID: **deepctrbot**
8686

8787
![wechat](./docs/pics/code.png)
@@ -115,7 +115,7 @@ If you find this code useful in your research, please cite it using the followin
115115
</td>
116116
<td>
117117
​ <a href="https://github.com/TanTingyi"><img width="70" height="70" src="https://github.com/TanTingyi.png?s=40" alt="pic"></a><br>
118-
<a href="https://github.com/TanTingyi">LeoCai</a>
118+
<a href="https://github.com/TanTingyi">Tan Tingyi</a>
119119
<p> Chongqing University <br> of Posts and <br> Telecommunications </p>​
120120
</td>
121121
</tr>

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.8.5'
3+
__version__ = '0.8.6'
44
check_version(__version__)

deepctr/estimator/models/deepfefm.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
from ...layers.utils import concat_func, add_func, combined_dnn_input, reduce_sum
1919

2020

21-
def DeepFEFMEstimator(linear_feature_columns, dnn_feature_columns, embedding_size=48,
22-
dnn_hidden_units=(1024, 1024, 1024), l2_reg_linear=0.000001, l2_reg_embedding_feat=0.00001,
23-
l2_reg_embedding_field=0.0000001, l2_reg_dnn=0, seed=1024, dnn_dropout=0.2,
21+
def DeepFEFMEstimator(linear_feature_columns, dnn_feature_columns,
22+
dnn_hidden_units=(128, 128), l2_reg_linear=0.00001, l2_reg_embedding_feat=0.00001,
23+
l2_reg_embedding_field=0.00001, l2_reg_dnn=0, seed=1024, dnn_dropout=0.0,
2424
dnn_activation='relu', dnn_use_bn=False, task='binary', model_dir=None,
2525
config=None, linear_optimizer='Ftrl', dnn_optimizer='Adagrad', training_chief_hooks=None):
2626
"""Instantiates the DeepFEFM Network architecture or the shallow FEFM architecture (Ablation support not provided
2727
as estimator is meant for production, Ablation support provided in DeepFEFM implementation in models
2828
2929
:param linear_feature_columns: An iterable containing all the features used by linear part of the model.
3030
:param dnn_feature_columns: An iterable containing all the features used by deep part of the model.
31-
:param embedding_size: positive integer,sparse feature embedding_size
3231
:param dnn_hidden_units: list,list of positive integer or empty list, the layer number and units in each layer of DNN
3332
:param l2_reg_linear: float. L2 regularizer strength applied to linear part
3433
:param l2_reg_embedding_feat: float. L2 regularizer strength applied to embedding vector of features
@@ -62,10 +61,11 @@ def _model_fn(features, labels, mode, config):
6261
sparse_embedding_list, dense_value_list = input_from_feature_columns(features, dnn_feature_columns,
6362
l2_reg_embedding=l2_reg_embedding_feat)
6463

65-
fefm_interaction_embedding = FEFMLayer(num_fields=len(sparse_embedding_list), embedding_size=embedding_size,
66-
regularizer=l2_reg_embedding_field)(concat_func(sparse_embedding_list, axis=1))
64+
fefm_interaction_embedding = FEFMLayer(
65+
regularizer=l2_reg_embedding_field)(concat_func(sparse_embedding_list, axis=1))
6766

68-
fefm_logit = tf.keras.layers.Lambda(lambda x: reduce_sum(x, axis=1, keep_dims=True))(fefm_interaction_embedding)
67+
fefm_logit = tf.keras.layers.Lambda(lambda x: reduce_sum(x, axis=1, keep_dims=True))(
68+
fefm_interaction_embedding)
6969

7070
final_logit_components.append(fefm_logit)
7171

@@ -87,6 +87,3 @@ def _model_fn(features, labels, mode, config):
8787
training_chief_hooks=training_chief_hooks)
8888

8989
return tf.estimator.Estimator(_model_fn, model_dir=model_dir, config=config)
90-
91-
92-

deepctr/estimator/utils.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,29 @@ def _eval_metric_ops(self,
4444
_summary_key(self._name, "prediction/mean"): metrics.mean(predictions, weights=weights),
4545
_summary_key(self._name, "label/mean"): metrics.mean(labels, weights=weights),
4646
}
47-
tf.summary.scalar("prediction/mean", metric_ops[_summary_key(self._name, "prediction/mean")][1])
48-
tf.summary.scalar("label/mean", metric_ops[_summary_key(self._name, "label/mean")][1])
47+
48+
summary_scalar("prediction/mean", metric_ops[_summary_key(self._name, "prediction/mean")][1])
49+
summary_scalar("label/mean", metric_ops[_summary_key(self._name, "label/mean")][1])
50+
4951

5052
mean_loss = losses.compute_weighted_loss(
5153
unweighted_loss, weights=1.0, reduction=losses.Reduction.MEAN)
5254

5355
if self._task == "binary":
5456
metric_ops[_summary_key(self._name, "LogLoss")] = metrics.mean(mean_loss, weights=weights, )
55-
tf.summary.scalar("LogLoss", mean_loss)
57+
summary_scalar("LogLoss", mean_loss)
5658

5759
metric_ops[_summary_key(self._name, "AUC")] = metrics.auc(labels, predictions, weights=weights)
58-
tf.summary.scalar("AUC", metric_ops[_summary_key(self._name, "AUC")][1])
60+
summary_scalar("AUC", metric_ops[_summary_key(self._name, "AUC")][1])
5961
else:
6062

6163
metric_ops[_summary_key(self._name, "MSE")] = metrics.mean_squared_error(labels, predictions,
6264
weights=weights)
63-
tf.summary.scalar("MSE", mean_loss)
65+
summary_scalar("MSE", mean_loss)
6466

6567
metric_ops[_summary_key(self._name, "MAE")] = metrics.mean_absolute_error(labels, predictions,
6668
weights=weights)
67-
tf.summary.scalar("MAE", metric_ops[_summary_key(self._name, "MAE")][1])
69+
summary_scalar("MAE", metric_ops[_summary_key(self._name, "MAE")][1])
6870

6971
return metric_ops
7072

@@ -206,3 +208,10 @@ def to_float(x, name="ToFloat"):
206208
return tf.to_float(x, name)
207209
except AttributeError:
208210
return tf.compat.v1.to_float(x, name)
211+
212+
213+
def summary_scalar(name, data):
214+
try:
215+
tf.summary.scalar(name, data)
216+
except AttributeError: # tf version 2.5.0+:AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'scalar'
217+
tf.compat.v1.summary.scalar(name, data)

deepctr/feature_column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .inputs import create_embedding_matrix, embedding_lookup, get_dense_input, varlen_embedding_lookup, \
1010
get_varlen_pooling_list, mergeDict
1111
from .layers import Linear
12-
from .layers.utils import concat_func, add_func
12+
from .layers.utils import concat_func
1313

1414
DEFAULT_GROUP_NAME = "default_group"
1515

deepctr/layers/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .normalization import LayerNormalization
1010
from .sequence import (AttentionSequencePoolingLayer, BiasEncoding, BiLSTM,
1111
KMaxPooling, SequencePoolingLayer, WeightedSequenceLayer,
12-
Transformer, DynamicGRU)
12+
Transformer, DynamicGRU,PositionEncoding)
1313

1414
from .utils import NoMask, Hash, Linear, Add, combined_dnn_input, softmax, reduce_sum
1515

@@ -47,5 +47,6 @@
4747
'FwFMLayer': FwFMLayer,
4848
'softmax': softmax,
4949
'FEFMLayer': FEFMLayer,
50-
'reduce_sum': reduce_sum
50+
'reduce_sum': reduce_sum,
51+
'PositionEncoding':PositionEncoding
5152
}

deepctr/layers/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ def call(self, inputs, training=None, **kwargs):
189189

190190
if self.use_bn:
191191
fc = self.bn_layers[i](fc, training=training)
192-
193-
fc = self.activation_layers[i](fc)
192+
try:
193+
fc = self.activation_layers[i](fc, training=training)
194+
except TypeError as e: # TypeError: call() got an unexpected keyword argument 'training'
195+
print("make sure the activation function use training flag properly", e)
196+
fc = self.activation_layers[i](fc)
194197

195198
fc = self.dropout_layers[i](fc, training=training)
196199
deep_input = fc

0 commit comments

Comments
 (0)