Skip to content

Commit 4762e85

Browse files
author
浅梦
authored
fix error in dcn-mix (#326)
fix error in dcn-mix
1 parent 43b971c commit 4762e85

27 files changed

+45
-64
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- name: Install dependencies
3737
run: |
3838
pip3 install -q tensorflow==${{ matrix.tf-version }}
39+
pip install -q numpy==1.19.5
3940
pip install -q requests
4041
pip install -e .
4142
- name: Test with pytest

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ If you
77
- have spare time to learn and develop
88
- familiar with git
99

10-
please send a brief introduction of your background and experience to wcshen1994@163.com, welcome to join us!
10+
please send a brief introduction of your background and experience to weichenswc@163.com, welcome to join us!
1111

1212
# Creating a pull request
13-
1. **Become a collaborator**: Send an email with introduction and your github account name to wcshen1994@163.com and waiting for invitation to become a collaborator.
14-
2. **Fork&Dev**: Fork your own branch(`dev_yourname`) in `DeepCTR` from the `master` branch for development.If the `master` is updated during the development process, remember to merge and update to `dev_yourname` regularly.
15-
3. **Testing**: Test logical correctness and effect when finishing the code development of the `dev_yourname` branch.
16-
4. **Pre-release** : After testing contact wcshen1994@163.com for pre-release integration, usually your branch `dev_yourname` will be merged into `release` branch by squash merge.
17-
5. **Release a new version**: After confirming that the change is no longer needed, `release` branch will be merged into `master` and a new python package will be released on pypi.
13+
1. **Become a collaborator**: Send an email with introduction and your github account name to weichenswc@163.com and waiting for invitation to become a collaborator.
14+
2. **Fork&Dev**: Fork your own branch(`dev_yourname`) in `DeepCTR` from the `master` branch for development.If the `master` is updated during the development process, remember to merge and update to `dev_yourname` regularly.
15+
3. **Testing**: Test logical correctness and effect when finishing the code development of the `dev_yourname` branch.
16+
4. **Pre-release** : After testing contact weichenswc@163.com for pre-release integration, usually your branch `dev_yourname` will be merged into `release` branch by squash merge.
17+
5. **Release a new version**: After confirming that the change is no longer needed, `release` branch will be merged into `master` and a new python package will be released on pypi.
1818

1919
# Discussions
2020

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
![CI status](https://github.com/shenweichen/deepctr/workflows/CI/badge.svg)
1414
[![Coverage Status](https://coveralls.io/repos/github/shenweichen/DeepCTR/badge.svg?branch=master)](https://coveralls.io/github/shenweichen/DeepCTR?branch=master)
1515
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d4099734dc0e4bab91d332ead8c0bdd0)](https://www.codacy.com/app/wcshen1994/DeepCTR?utm_source=github.com&utm_medium=referral&utm_content=shenweichen/DeepCTR&utm_campaign=Badge_Grade)
16-
[![Disscussion](https://img.shields.io/badge/chat-wechat-brightgreen?style=flat)](./README.md#disscussiongroup)
16+
[![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)
1818
<!-- [![Gitter](https://badges.gitter.im/DeepCTR/community.svg)](https://gitter.im/DeepCTR/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -->
1919

@@ -24,7 +24,7 @@ DeepCTR is a **Easy-to-use**,**Modular** and **Extendible** package of deep-lear
2424
- Provide `tensorflow estimator` interface for **large scale data** and **distributed training**. [example](https://deepctr-doc.readthedocs.io/en/latest/Quick-Start.html#getting-started-4-steps-to-deepctr-estimator-with-tfrecord)
2525
- It is compatible with both `tf 1.x` and `tf 2.x`.
2626

27-
Some related project:
27+
Some related projects:
2828
- DeepMatch: https://github.com/shenweichen/DeepMatch
2929
- DeepCTR-Torch: https://github.com/shenweichen/DeepCTR-Torch
3030

@@ -74,19 +74,11 @@ If you find this code useful in your research, please cite it using the followin
7474
}
7575
```
7676

77-
## DisscussionGroup 交流群
77+
## DisscussionGroup
7878

7979
- [Discussions](https://github.com/shenweichen/DeepCTR/discussions)
8080
- 公众号:**浅梦的学习笔记**
8181
- wechat ID: **deepctrbot**
8282

8383
![wechat](./docs/pics/code.png)
8484

85-
## Cooperative promotion 合作推广
86-
For more information about the recommendation system, such as **feature engineering, user profile, matching, ranking and multi-objective optimization, online learning and real-time computing, and more cutting-edge technologies and practical projects**:
87-
88-
更多关于推荐系统的内容,如**特征工程,用户画像,召回,排序和多目标优化,在线学习与实时计算以及更多前沿技术和实战项目**等可参考:
89-
90-
- [推荐系统实战](https://www.julyedu.com/course/getDetail/181?ccode=5ee751d37278c)
91-
- [互联网计算广告实战](https://www.julyedu.com/course/getDetail/158?ccode=5ee751d37278c)
92-

deepctr/estimator/models/afm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _model_fn(features, labels, mode, config):
5353
linear_logits = get_linear_logit(features, linear_feature_columns, l2_reg_linear=l2_reg_linear)
5454

5555
with variable_scope(DNN_SCOPE_NAME):
56-
sparse_embedding_list, dense_value_list = input_from_feature_columns(features, dnn_feature_columns,
56+
sparse_embedding_list, _ = input_from_feature_columns(features, dnn_feature_columns,
5757
l2_reg_embedding=l2_reg_embedding)
5858
if use_attention:
5959

deepctr/estimator/models/ccpm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _model_fn(features, labels, mode, config):
5959
linear_logits = get_linear_logit(features, linear_feature_columns, l2_reg_linear=l2_reg_linear)
6060

6161
with variable_scope(DNN_SCOPE_NAME):
62-
sparse_embedding_list, dense_value_list = input_from_feature_columns(features, dnn_feature_columns,
62+
sparse_embedding_list, _ = input_from_feature_columns(features, dnn_feature_columns,
6363
l2_reg_embedding=l2_reg_embedding)
6464
n = len(sparse_embedding_list)
6565
l = len(conv_filters)

deepctr/feature_column.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class DenseFeat(namedtuple('DenseFeat', ['name', 'dimension', 'dtype', 'transfor
9393
name: feature name,
9494
dimension: dimension of the feature, default = 1.
9595
dtype: dtype of the feature, default="float32".
96-
transform_fn: If not None, a function that can be used to transfrom
96+
transform_fn: If not `None` , a function that can be used to transform
9797
values of the feature. the function takes the input Tensor as its
98-
argument, and returns the output Tensor.
98+
argument, and returns the output Tensor.
9999
(e.g. lambda x: (x - 3.0) / 4.2).
100100
"""
101101
__slots__ = ()

deepctr/layers/interaction.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,13 @@ def call(self, inputs, **kwargs):
399399
if self.parameterization == 'vector':
400400
xl_w = tf.tensordot(x_l, self.kernels[i], axes=(1, 0))
401401
dot_ = tf.matmul(x_0, xl_w)
402-
x_l = dot_ + self.bias[i]
402+
x_l = dot_ + self.bias[i] + x_l
403403
elif self.parameterization == 'matrix':
404-
dot_ = tf.einsum('ij,bjk->bik', self.kernels[i], x_l) # W * xi (bs, dim, 1)
405-
dot_ = dot_ + self.bias[i] # W * xi + b
406-
dot_ = x_0 * dot_ # x0 · (W * xi + b) Hadamard-product
404+
xl_w = tf.einsum('ij,bjk->bik', self.kernels[i], x_l) # W * xi (bs, dim, 1)
405+
dot_ = xl_w + self.bias[i] # W * xi + b
406+
x_l = x_0 * dot_ + x_l # x0 · (W * xi + b) +xl Hadamard-product
407407
else: # error
408-
print("parameterization should be 'vector' or 'matrix'")
409-
x_l = dot_ + x_l
408+
raise ValueError("parameterization should be 'vector' or 'matrix'")
410409
x_l = tf.squeeze(x_l, axis=2)
411410
return x_l
412411

deepctr/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .fnn import FNN
1010
from .mlr import MLR
1111
from .onn import ONN
12-
from .onn import ONN as NFFM
1312
from .nfm import NFM
1413
from .pnn import PNN
1514
from .wdl import WDL

docs/source/Examples.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ if __name__ == "__main__":
367367
batch_size=2 ** 14, num_epochs=1, shuffle_factor=0)
368368

369369
# 3.Define Model,train,predict and evaluate
370-
model = DeepFMEstimator(linear_feature_columns, dnn_feature_columns, task='binary')
370+
model = DeepFMEstimator(linear_feature_columns, dnn_feature_columns, task='binary',
371+
config=tf.estimator.RunConfig(tf_random_seed=2021))
371372

372373
model.train(train_model_input)
373374
eval_result = model.evaluate(test_model_input)
@@ -422,15 +423,16 @@ if __name__ == "__main__":
422423

423424
# 3.generate input data for model
424425

425-
train, test = train_test_split(data, test_size=0.2, random_state=2020)
426+
train, test = train_test_split(data, test_size=0.2, random_state=2021)
426427

427428
# Not setting default value for continuous feature. filled with mean.
428429

429430
train_model_input = input_fn_pandas(train, sparse_features + dense_features, 'label', shuffle=True)
430431
test_model_input = input_fn_pandas(test, sparse_features + dense_features, None, shuffle=False)
431432

432433
# 4.Define Model,train,predict and evaluate
433-
model = DeepFMEstimator(linear_feature_columns, dnn_feature_columns, task='binary')
434+
model = DeepFMEstimator(linear_feature_columns, dnn_feature_columns, task='binary',
435+
config=tf.estimator.RunConfig(tf_random_seed=2021))
434436

435437
model.train(train_model_input)
436438
pred_ans_iter = model.predict(test_model_input)

docs/source/FAQ.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ es = EarlyStopping(monitor='val_binary_crossentropy')
3737
history = model.fit(model_input, data[target].values,batch_size=256, epochs=10, verbose=2, validation_split=0.2,callbacks=[es] )
3838
```
3939

40+
If you are using Estimator models, you can set learning rate like:
41+
42+
```python
43+
from deepctr.estimator import DeepFMEstimator
44+
import tensorflow as tf
45+
46+
model = DeepFMEstimator(linear_feature_columns, dnn_feature_columns, task='binary',
47+
linear_optimizer=tf.train.FtrlOptimizer(0.05), dnn_optimizer=tf.train.AdagradOptimizer(0.1)
48+
)
49+
50+
```
51+
4052

4153
## 3. Get the attentional weights of feature interactions in AFM
4254
--------------------------------------------------------------------------

0 commit comments

Comments
 (0)