Skip to content

Commit ec78b9b

Browse files
authored
support python 3.9&3.10
- support python 3.9 and 3.10 - support `cos` and `ln` attention_type in transformer - polish docstring
1 parent 9564e05 commit ec78b9b

File tree

13 files changed

+89
-42
lines changed

13 files changed

+89
-42
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Steps to reproduce the behavior:
1919

2020
**Operating environment(运行环境):**
2121
- 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.9.0,]
22+
- tensorflow version [e.g. 1.4.0, 1.15.0, 2.10.0]
23+
- deepctr version [e.g. 0.9.2,]
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.15.0, 2.5.0]
20-
- deepctr version [e.g. 0.9.0,]
19+
- tensorflow version [e.g. 1.4.0, 1.15.0, 2.10.0]
20+
- deepctr version [e.g. 0.9.2,]

.github/workflows/ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
timeout-minutes: 180
1818
strategy:
1919
matrix:
20-
python-version: [3.6,3.7,3.8]
21-
tf-version: [1.4.0,1.15.0,2.5.0,2.6.0,2.7.0,2.8.0,2.9.0]
20+
python-version: [3.6,3.7,3.8,3.9,3.10.7]
21+
tf-version: [1.4.0,1.15.0,2.6.0,2.7.0,2.8.0,2.9.0,2.10.0]
2222

2323
exclude:
2424
- python-version: 3.7
@@ -37,12 +37,32 @@ jobs:
3737
tf-version: 2.8.0
3838
- python-version: 3.6
3939
tf-version: 2.9.0
40+
- python-version: 3.6
41+
tf-version: 2.10.0
4042
- python-version: 3.9
4143
tf-version: 1.4.0
4244
- python-version: 3.9
4345
tf-version: 1.15.0
4446
- python-version: 3.9
4547
tf-version: 2.2.0
48+
- python-version: 3.9
49+
tf-version: 2.5.0
50+
- python-version: 3.9
51+
tf-version: 2.6.0
52+
- python-version: 3.9
53+
tf-version: 2.7.0
54+
- python-version: 3.10.7
55+
tf-version: 1.4.0
56+
- python-version: 3.10.7
57+
tf-version: 1.15.0
58+
- python-version: 3.10.7
59+
tf-version: 2.2.0
60+
- python-version: 3.10.7
61+
tf-version: 2.5.0
62+
- python-version: 3.10.7
63+
tf-version: 2.6.0
64+
- python-version: 3.10.7
65+
tf-version: 2.7.0
4666
steps:
4767

4868
- uses: actions/checkout@v3

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
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

2020

21-
DeepCTR is a **Easy-to-use**,**Modular** and **Extendible** package of deep-learning based CTR models along with lots of
21+
DeepCTR is a **Easy-to-use**, **Modular** and **Extendible** package of deep-learning based CTR models along with lots of
2222
core components layers which can be used to easily build custom models.You can use any complex model with `model.fit()`
2323
,and `model.predict()` .
2424

25-
- Provide `tf.keras.Model` like interface for **quick experiment**
26-
. [example](https://deepctr-doc.readthedocs.io/en/latest/Quick-Start.html#getting-started-4-steps-to-deepctr)
27-
- Provide `tensorflow estimator` interface for **large scale data** and **distributed training**
28-
. [example](https://deepctr-doc.readthedocs.io/en/latest/Quick-Start.html#getting-started-4-steps-to-deepctr-estimator-with-tfrecord)
25+
- Provide `tf.keras.Model` like interfaces for **quick experiment**. [example](https://deepctr-doc.readthedocs.io/en/latest/Quick-Start.html#getting-started-4-steps-to-deepctr)
26+
- 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)
2927
- It is compatible with both `tf 1.x` and `tf 2.x`.
3028

3129
Some related projects:

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

deepctr/feature_column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __hash__(self):
9595
class DenseFeat(namedtuple('DenseFeat', ['name', 'dimension', 'dtype', 'transform_fn'])):
9696
""" Dense feature
9797
Args:
98-
name: feature name,
98+
name: feature name.
9999
dimension: dimension of the feature, default = 1.
100100
dtype: dtype of the feature, default="float32".
101101
transform_fn: If not `None` , a function that can be used to transform

deepctr/layers/sequence.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class Transformer(Layer):
442442
- **blinding**: bool. Whether or not use blinding.
443443
- **seed**: A Python integer to use as random seed.
444444
- **supports_masking**:bool. Whether or not support masking.
445-
- **attention_type**: str, Type of attention, the value must be one of { ``'scaled_dot_product'`` , ``'additive'`` }.
445+
- **attention_type**: str, Type of attention, the value must be one of { ``'scaled_dot_product'`` , ``'cos'`` , ``'ln'`` , ``'additive'`` }.
446446
- **output_type**: ``'mean'`` , ``'sum'`` or `None`. Whether or not use average/sum pooling for output.
447447
448448
References
@@ -490,6 +490,9 @@ def build(self, input_shape):
490490
initializer=glorot_uniform(seed=self.seed))
491491
self.v = self.add_weight('v', shape=[self.att_embedding_size], dtype=tf.float32,
492492
initializer=glorot_uniform(seed=self.seed))
493+
elif self.attention_type == "ln":
494+
self.att_ln_q = LayerNormalization()
495+
self.att_ln_k = LayerNormalization()
493496
# if self.use_res:
494497
# self.W_Res = self.add_weight(name='res', shape=[embedding_size, self.att_embedding_size * self.head_num], dtype=tf.float32,
495498
# initializer=TruncatedNormal(seed=self.seed))
@@ -529,28 +532,42 @@ def call(self, inputs, mask=None, training=None, **kwargs):
529532
queries = self.query_pe(queries)
530533
keys = self.key_pe(queries)
531534

532-
querys = tf.tensordot(queries, self.W_Query,
533-
axes=(-1, 0)) # None T_q D*head_num
534-
keys = tf.tensordot(keys, self.W_key, axes=(-1, 0))
535-
values = tf.tensordot(keys, self.W_Value, axes=(-1, 0))
535+
Q = tf.tensordot(queries, self.W_Query,
536+
axes=(-1, 0)) # N T_q D*h
537+
K = tf.tensordot(keys, self.W_key, axes=(-1, 0))
538+
V = tf.tensordot(keys, self.W_Value, axes=(-1, 0))
536539

537-
# head_num*None T_q D
538-
querys = tf.concat(tf.split(querys, self.head_num, axis=2), axis=0)
539-
keys = tf.concat(tf.split(keys, self.head_num, axis=2), axis=0)
540-
values = tf.concat(tf.split(values, self.head_num, axis=2), axis=0)
540+
# h*N T_q D
541+
Q_ = tf.concat(tf.split(Q, self.head_num, axis=2), axis=0)
542+
K_ = tf.concat(tf.split(K, self.head_num, axis=2), axis=0)
543+
V_ = tf.concat(tf.split(V, self.head_num, axis=2), axis=0)
541544

542545
if self.attention_type == "scaled_dot_product":
543-
# head_num*None T_q T_k
544-
outputs = tf.matmul(querys, keys, transpose_b=True)
546+
# h*N T_q T_k
547+
outputs = tf.matmul(Q_, K_, transpose_b=True)
545548

546-
outputs = outputs / (keys.get_shape().as_list()[-1] ** 0.5)
549+
outputs = outputs / (K_.get_shape().as_list()[-1] ** 0.5)
550+
elif self.attention_type == "cos":
551+
Q_cos = tf.nn.l2_normalize(Q_, dim=-1)
552+
K_cos = tf.nn.l2_normalize(K_, dim=-1)
553+
554+
outputs = tf.matmul(Q_cos, K_cos, transpose_b=True) # h*N T_q T_k
555+
556+
outputs = outputs * 20 # Scale
557+
elif self.attention_type == 'ln':
558+
Q_ = self.att_ln_q(Q_)
559+
K_ = self.att_ln_k(K_)
560+
561+
outputs = tf.matmul(Q_, K_, transpose_b=True) # h*N T_q T_k
562+
# Scale
563+
outputs = outputs / (K_.get_shape().as_list()[-1] ** 0.5)
547564
elif self.attention_type == "additive":
548-
querys_reshaped = tf.expand_dims(querys, axis=-2)
549-
keys_reshaped = tf.expand_dims(keys, axis=-3)
550-
outputs = tf.tanh(tf.nn.bias_add(querys_reshaped + keys_reshaped, self.b))
565+
Q_reshaped = tf.expand_dims(Q_, axis=-2)
566+
K_reshaped = tf.expand_dims(K_, axis=-3)
567+
outputs = tf.tanh(tf.nn.bias_add(Q_reshaped + K_reshaped, self.b))
551568
outputs = tf.squeeze(tf.tensordot(outputs, tf.expand_dims(self.v, axis=-1), axes=[-1, 0]), axis=-1)
552569
else:
553-
raise ValueError("attention_type must be scaled_dot_product or additive")
570+
raise ValueError("attention_type must be [scaled_dot_product,cos,ln,additive]")
554571

555572
key_masks = tf.tile(key_masks, [self.head_num, 1])
556573

@@ -583,7 +600,7 @@ def call(self, inputs, mask=None, training=None, **kwargs):
583600
outputs = self.dropout(outputs, training=training)
584601
# Weighted sum
585602
# ( h*N, T_q, C/h)
586-
result = tf.matmul(outputs, values)
603+
result = tf.matmul(outputs, V_)
587604
result = tf.concat(tf.split(result, self.head_num, axis=0), axis=2)
588605

589606
if self.use_res:

deepctr/models/deepfm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def DeepFM(linear_feature_columns, dnn_feature_columns, fm_group=(DEFAULT_GROUP_
2424
dnn_activation='relu', dnn_use_bn=False, task='binary'):
2525
"""Instantiates the DeepFM Network architecture.
2626
27-
:param linear_feature_columns: An iterable containing all the features used by linear part of the model.
28-
:param dnn_feature_columns: An iterable containing all the features used by deep part of the model.
27+
:param linear_feature_columns: An iterable containing all the features used by the linear part of the model.
28+
:param dnn_feature_columns: An iterable containing all the features used by the deep part of the model.
2929
:param fm_group: list, group_name of features that will be used to do feature interactions.
3030
:param dnn_hidden_units: list,list of positive integer or empty list, the layer number and units in each layer of DNN
3131
:param l2_reg_linear: float. L2 regularizer strength applied to linear part

docs/source/History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# History
2+
- 10/15/2022 : [v0.9.2](https://github.com/shenweichen/DeepCTR/releases/tag/v0.9.2) released.Support python `3.9`,`3.10`.
23
- 06/11/2022 : [v0.9.1](https://github.com/shenweichen/DeepCTR/releases/tag/v0.9.1) released.Improve compatibility with tensorflow `2.x`.
34
- 09/03/2021 : [v0.9.0](https://github.com/shenweichen/DeepCTR/releases/tag/v0.9.0) released.Add multitask learning models:[SharedBottom](./Features.html#sharedbottom),[ESMM](./Features.html#esmm-entire-space-multi-task-model),[MMOE](./Features.html#mmoe-multi-gate-mixture-of-experts) and [PLE](./Features.html#ple-progressive-layered-extraction). [running example](./Examples.html#multitask-learning-mmoe)
45
- 07/18/2021 : [v0.8.7](https://github.com/shenweichen/DeepCTR/releases/tag/v0.8.7) released.Support pre-defined key-value vocabulary in `Hash` Layer. [example](./Examples.html#hash-layer-with-pre-defined-key-value-vocabulary)

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.9.1'
29+
release = '0.9.2'
3030

3131

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

0 commit comments

Comments
 (0)