Skip to content

Commit db229dc

Browse files
author
浅梦
authored
refactor feature columns
refactor feature columns - different features can use different `embedding_dim` - group-wise interaction is available by setting `group_name`
1 parent 32f88fc commit db229dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+592
-609
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
python-version: [3.5,3.6,3.7]
21-
tf-version: [1.4.0,1.14.0,2.0.0]
21+
tf-version: [1.4.0,1.15.0,2.0.0]
2222

2323
exclude:
2424
- python-version: 3.7

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
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 core components layers which can be used to build your own custom model easily.It is compatible with **tensorflow 1.4+ and 2.0+**.You can use any complex model with `model.fit()`and `model.predict()` .
21+
DeepCTR is a **Easy-to-use**,**Modular** and **Extendible** package of deep-learning based CTR models along with lots of core components layers which can be used to easily build custom models.It is compatible with **tensorflow 1.4+ and 2.0+**.You can use any complex model with `model.fit()`and `model.predict()` .
2222

2323
Let's [**Get Started!**](https://deepctr-doc.readthedocs.io/en/latest/Quick-Start.html)([Chinese Introduction](https://zhuanlan.zhihu.com/p/53231955))
2424

deepctr/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from . import layers
2-
from . import models
31
from .utils import check_version
42

5-
__version__ = '0.6.3'
3+
__version__ = '0.7.0'
64
check_version(__version__)

deepctr/inputs.py

Lines changed: 153 additions & 163 deletions
Large diffs are not rendered by default.

deepctr/layers/__init__.py

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

1414
custom_objects = {'tf': tf,
1515
'InnerProductLayer': InnerProductLayer,
@@ -38,5 +38,6 @@
3838
'DynamicGRU': DynamicGRU,
3939
'SENETLayer':SENETLayer,
4040
'BilinearInteraction':BilinearInteraction,
41-
'WeightedSequenceLayer':WeightedSequenceLayer
41+
'WeightedSequenceLayer':WeightedSequenceLayer,
42+
'Add':Add
4243
}

deepctr/layers/activation.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def build(self, input_shape):
4040
self.bn = tf.keras.layers.BatchNormalization(
4141
axis=self.axis, epsilon=self.epsilon, center=False, scale=False)
4242
self.alphas = self.add_weight(shape=(input_shape[-1],), initializer=Zeros(
43-
), dtype=tf.float32, name= 'dice_alpha') # name='alpha_'+self.name
43+
), dtype=tf.float32, name='dice_alpha') # name='alpha_'+self.name
4444
super(Dice, self).build(input_shape) # Be sure to call this somewhere!
4545
self.uses_learning_phase = True
4646

47-
def call(self, inputs,training=None,**kwargs):
48-
inputs_normed = self.bn(inputs,training=training)
47+
def call(self, inputs, training=None, **kwargs):
48+
inputs_normed = self.bn(inputs, training=training)
4949
# tf.layers.batch_normalization(
5050
# inputs, axis=self.axis, epsilon=self.epsilon, center=False, scale=False)
5151
x_p = tf.sigmoid(inputs_normed)
@@ -59,9 +59,10 @@ def get_config(self, ):
5959
base_config = super(Dice, self).get_config()
6060
return dict(list(base_config.items()) + list(config.items()))
6161

62+
6263
def activation_layer(activation):
6364
if activation == "dice" or activation == "Dice":
64-
act_layer = Dice()
65+
act_layer = Dice()
6566
elif (isinstance(activation, str)) or (sys.version_info.major == 2 and isinstance(activation, (str, unicode))):
6667
act_layer = tf.keras.layers.Activation(activation)
6768
elif issubclass(activation, Layer):

deepctr/layers/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def __init__(self, hidden_units, activation='relu', l2_reg=0, dropout_rate=0, us
147147
super(DNN, self).__init__(**kwargs)
148148

149149
def build(self, input_shape):
150+
# if len(self.hidden_units) == 0:
151+
# raise ValueError("hidden_units is empty")
150152
input_size = input_shape[-1]
151153
hidden_units = [int(input_size)] + list(self.hidden_units)
152154
self.kernels = [self.add_weight(name='kernel' + str(i),

deepctr/layers/interaction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from tensorflow.python.layers import utils
1818

1919
from .activation import activation_layer
20-
from .utils import concat_fun,reduce_sum,softmax,reduce_mean
20+
from .utils import concat_func,reduce_sum,softmax,reduce_mean
2121

2222

2323
class AFMLayer(Layer):
@@ -843,7 +843,7 @@ def call(self, inputs, **kwargs):
843843
new_feature_list.append(
844844
tf.reshape(new_result, (-1, int(pooling_result.shape[1]) * new_filters, embedding_size)))
845845

846-
new_features = concat_fun(new_feature_list, axis=1)
846+
new_features = concat_func(new_feature_list, axis=1)
847847
return new_features
848848

849849
def compute_output_shape(self, input_shape):
@@ -943,7 +943,7 @@ def call(self, inputs, training=None, **kwargs):
943943
raise ValueError(
944944
"Unexpected inputs dimensions %d, expect to be 3 dimensions" % (K.ndim(inputs)))
945945

946-
inputs = concat_fun(inputs, axis=1)
946+
inputs = concat_func(inputs, axis=1)
947947
Z = reduce_mean(inputs, axis=-1,)
948948

949949
A_1 = tf.nn.relu(self.tensordot([Z, self.W_1]))
@@ -1030,7 +1030,7 @@ def call(self, inputs, **kwargs):
10301030
for v, w in zip(itertools.combinations(inputs, 2), self.W_list)]
10311031
else:
10321032
raise NotImplementedError
1033-
return concat_fun(p)
1033+
return concat_func(p)
10341034

10351035
def compute_output_shape(self, input_shape):
10361036
filed_size = len(input_shape)

deepctr/layers/sequence.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def compute_mask(self, inputs, mask):
178178
return None
179179

180180
def get_config(self, ):
181-
config = {'supports_masking': self.supports_masking}
181+
config = {'weight_normalization':self.weight_normalization,'supports_masking': self.supports_masking}
182182
base_config = super(WeightedSequenceLayer, self).get_config()
183183
return dict(list(base_config.items()) + list(config.items()))
184184

@@ -460,7 +460,6 @@ def __init__(self, att_embedding_size=1, head_num=8, dropout_rate=0.0, use_posit
460460
self.supports_masking = supports_masking
461461

462462
def build(self, input_shape):
463-
464463
embedding_size = int(input_shape[0][-1])
465464
if self.num_units != embedding_size:
466465
raise ValueError(

deepctr/layers/utils.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_config(self, ):
116116
return dict(list(base_config.items()) + list(config.items()))
117117

118118

119-
def concat_fun(inputs, axis=-1,mask=False):
119+
def concat_func(inputs, axis=-1, mask=False):
120120
if not mask:
121121
inputs = list(map(NoMask(), inputs))
122122
if len(inputs) == 1:
@@ -188,3 +188,24 @@ def softmax(logits, dim=-1, name=None):
188188
return tf.nn.softmax(logits, dim=dim, name=name)
189189
else:
190190
return tf.nn.softmax(logits, axis=dim, name=name)
191+
192+
193+
class Add(tf.keras.layers.Layer):
194+
def __init__(self, **kwargs):
195+
super(Add, self).__init__(**kwargs)
196+
197+
def build(self, input_shape):
198+
# Be sure to call this somewhere!
199+
super(Add, self).build(input_shape)
200+
201+
def call(self, inputs, **kwargs):
202+
if not isinstance(inputs,list):
203+
return inputs
204+
if len(inputs) == 1 :
205+
return inputs[0]
206+
if len(inputs) == 0:
207+
return tf.constant([[0.0]])
208+
209+
return tf.keras.layers.add(inputs)
210+
def add_func(inputs):
211+
return Add()(inputs)

0 commit comments

Comments
 (0)