Skip to content

Commit

Permalink
update EDCN &fix typo
Browse files Browse the repository at this point in the history
update EDCN &fix typo
  • Loading branch information
shenweichen authored Nov 9, 2022
1 parent c13aba6 commit 91dc7c6
Show file tree
Hide file tree
Showing 23 changed files with 309 additions and 218 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI
name: CI_TF2

on:
on:
push:
path:
- 'deepctr/*'
Expand All @@ -9,17 +9,17 @@ on:
path:
- 'deepctr/*'
- 'tests/*'

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 180
strategy:
matrix:
python-version: [3.6,3.7,3.8,3.9,3.10.7]
tf-version: [1.4.0,1.15.0,2.6.0,2.7.0,2.8.0,2.9.0,2.10.0]
python-version: [ 3.6,3.7,3.8, 3.9,3.10.7 ]
tf-version: [ 2.6.0,2.7.0,2.8.0,2.9.0,2.10.0 ]

exclude:
- python-version: 3.7
tf-version: 1.4.0
Expand Down Expand Up @@ -64,31 +64,31 @@ jobs:
- python-version: 3.10.7
tf-version: 2.7.0
steps:

- uses: actions/checkout@v3

- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip3 install -q tensorflow==${{ matrix.tf-version }}
pip install -q protobuf==3.19.0
pip install -q requests
pip install -e .
- name: Test with pytest
timeout-minutes: 180
run: |
pip install -q pytest
pip install -q pytest-cov
pip install -q python-coveralls
pytest --cov=deepctr --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.xml
flags: pytest
name: py${{ matrix.python-version }}-tf${{ matrix.tf-version }}
- uses: actions/checkout@v3

- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip3 install -q tensorflow==${{ matrix.tf-version }}
pip install -q protobuf==3.19.0
pip install -q requests
pip install -e .
- name: Test with pytest
timeout-minutes: 180
run: |
pip install -q pytest
pip install -q pytest-cov
pip install -q python-coveralls
pytest --cov=deepctr --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.xml
flags: pytest
name: py${{ matrix.python-version }}-tf${{ matrix.tf-version }}
96 changes: 96 additions & 0 deletions .github/workflows/ci2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: CI_TF1

on:
push:
path:
- 'deepctr/*'
- 'tests/*'
pull_request:
path:
- 'deepctr/*'
- 'tests/*'

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 180
strategy:
matrix:
python-version: [ 3.6,3.7 ]
tf-version: [ 1.15.0 ]

exclude:
- python-version: 3.7
tf-version: 1.4.0
- python-version: 3.7
tf-version: 1.12.0
- python-version: 3.7
tf-version: 1.15.0
- python-version: 3.8
tf-version: 1.4.0
- python-version: 3.8
tf-version: 1.14.0
- python-version: 3.8
tf-version: 1.15.0
- python-version: 3.6
tf-version: 2.7.0
- python-version: 3.6
tf-version: 2.8.0
- python-version: 3.6
tf-version: 2.9.0
- python-version: 3.6
tf-version: 2.10.0
- python-version: 3.9
tf-version: 1.4.0
- python-version: 3.9
tf-version: 1.15.0
- python-version: 3.9
tf-version: 2.2.0
- python-version: 3.9
tf-version: 2.5.0
- python-version: 3.9
tf-version: 2.6.0
- python-version: 3.9
tf-version: 2.7.0
- python-version: 3.10.7
tf-version: 1.4.0
- python-version: 3.10.7
tf-version: 1.15.0
- python-version: 3.10.7
tf-version: 2.2.0
- python-version: 3.10.7
tf-version: 2.5.0
- python-version: 3.10.7
tf-version: 2.6.0
- python-version: 3.10.7
tf-version: 2.7.0
steps:

- uses: actions/checkout@v3

- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip3 install -q tensorflow==${{ matrix.tf-version }}
pip install -q protobuf==3.19.0
pip install -q requests
pip install -e .
- name: Test with pytest
timeout-minutes: 180
run: |
pip install -q pytest
pip install -q pytest-cov
pip install -q python-coveralls
pytest --cov=deepctr --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.xml
flags: pytest
name: py${{ matrix.python-version }}-tf${{ matrix.tf-version }}
2 changes: 1 addition & 1 deletion deepctr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utils import check_version

__version__ = '0.9.2'
__version__ = '0.9.3'
check_version(__version__)
14 changes: 7 additions & 7 deletions deepctr/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import tensorflow as tf

from .activation import Dice
from .core import DNN, LocalActivationUnit, PredictionLayer, RegulationLayer
from .core import DNN, LocalActivationUnit, PredictionLayer, RegulationModule
from .interaction import (CIN, FM, AFMLayer, BiInteractionPooling, CrossNet, CrossNetMix,
InnerProductLayer, InteractingLayer,
OutterProductLayer, FGCNNLayer, SENETLayer, BilinearInteraction,
FieldWiseBiInteraction, FwFMLayer, FEFMLayer, BridgeLayer)
FieldWiseBiInteraction, FwFMLayer, FEFMLayer, BridgeModule)
from .normalization import LayerNormalization
from .sequence import (AttentionSequencePoolingLayer, BiasEncoding, BiLSTM,
KMaxPooling, SequencePoolingLayer, WeightedSequenceLayer,
Transformer, DynamicGRU,PositionEncoding)

from .utils import NoMask, Hash, Linear, _Add, combined_dnn_input, softmax, reduce_sum
Transformer, DynamicGRU, PositionEncoding)
from .utils import NoMask, Hash, Linear, _Add, combined_dnn_input, softmax, reduce_sum, Concat

custom_objects = {'tf': tf,
'InnerProductLayer': InnerProductLayer,
Expand All @@ -28,7 +27,6 @@
'SequencePoolingLayer': SequencePoolingLayer,
'AttentionSequencePoolingLayer': AttentionSequencePoolingLayer,
'CIN': CIN,
'RegulationLayer': RegulationLayer,
'InteractingLayer': InteractingLayer,
'LayerNormalization': LayerNormalization,
'BiLSTM': BiLSTM,
Expand All @@ -39,6 +37,7 @@
'FGCNNLayer': FGCNNLayer,
'Hash': Hash,
'Linear': Linear,
'Concat': Concat,
'DynamicGRU': DynamicGRU,
'SENETLayer': SENETLayer,
'BilinearInteraction': BilinearInteraction,
Expand All @@ -50,5 +49,6 @@
'FEFMLayer': FEFMLayer,
'reduce_sum': reduce_sum,
'PositionEncoding': PositionEncoding,
'BridgeLayer': BridgeLayer
'RegulationModule': RegulationModule,
'BridgeModule': BridgeModule
}
26 changes: 12 additions & 14 deletions deepctr/layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,41 +267,39 @@ def get_config(self, ):
return dict(list(base_config.items()) + list(config.items()))


class RegulationLayer(Layer):
class RegulationModule(Layer):
"""Regulation module used in EDCN.
Input shape
- A list of 3D tensor with shape: ``(batch_size,1,embedding_size)``.
- 3D tensor with shape: ``(batch_size,field_size,embedding_size)``.
Output shape
- 2D tensor with shape: ``(batch_size, embedding_size * field_num)``.
- 2D tensor with shape: ``(batch_size,field_size * embedding_size)``.
Arguments
- **tau** : Positive float, the temperature coefficient to control
distribution of field-wise gating unit.
- **seed** : A Python integer to use as random seed.
References
- [Enhancing Explicit and Implicit Feature Interactions via Information Sharing for Parallel Deep CTR Models.](https://dlp-kdd.github.io/assets/pdf/DLP-KDD_2021_paper_12.pdf)
"""

def __init__(self, tau=0.1, **kwargs):
def __init__(self, tau=1.0, **kwargs):
if tau == 0:
raise ValueError("RegulationLayer tau can not be zero.")
raise ValueError("RegulationModule tau can not be zero.")
self.tau = 1.0 / tau
super(RegulationLayer, self).__init__(**kwargs)
super(RegulationModule, self).__init__(**kwargs)

def build(self, input_shape):
self.field_num = int(input_shape[1])
self.field_size = int(input_shape[1])
self.embedding_size = int(input_shape[2])
self.g = self.add_weight(
shape=(1, self.field_num, 1),
shape=(1, self.field_size, 1),
initializer=Ones(),
name=self.name + '_field_weight')

# Be sure to call this somewhere!
super(RegulationLayer, self).build(input_shape)
super(RegulationModule, self).build(input_shape)

def call(self, inputs, **kwargs):

Expand All @@ -311,13 +309,13 @@ def call(self, inputs, **kwargs):

feild_gating_score = tf.nn.softmax(self.g * self.tau, 1)
E = inputs * feild_gating_score
return tf.reshape(E, [-1, self.field_num * self.embedding_size])
return tf.reshape(E, [-1, self.field_size * self.embedding_size])

def compute_output_shape(self, input_shape):
return (None, self.field_num * self.embedding_size)
return (None, self.field_size * self.embedding_size)

def get_config(self):
config = {'tau': self.tau}
base_config = super(RegulationLayer, self).get_config()
base_config = super(RegulationModule, self).get_config()
base_config.update(config)
return base_config
43 changes: 19 additions & 24 deletions deepctr/layers/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,48 +1493,45 @@ def get_config(self):
return config


class BridgeLayer(Layer): # ridge
"""AttentionPoolingLayer layer used in EDCN
class BridgeModule(Layer):
"""Bridge Module used in EDCN
Input shape
- A list of 3D tensor with shape: ``(batch_size,1,embedding_size)``. Its length is ``number of subnetworks``.
- A list of two 2D tensor with shape: ``(batch_size, units)``.
Output shape
- 2D tensor with shape: ``(batch_size, embedding_size)``.
- 2D tensor with shape: ``(batch_size, units)``.
Arguments
- **activation**: Activation function to use.
- **l2_reg**: float between 0 and 1. L2 regularizer strength applied to the kernel weights matrix.
- **bridge_type**: The type of bridge interaction, one of 'pointwise_addition', 'hadamard_product', 'concatenation', 'attention_pooling'
- **seed**: A Python integer to use as random seed.
- **activation**: Activation function to use.
References
- [Enhancing Explicit and Implicit Feature Interactions via Information Sharing for Parallel Deep CTR Models.](https://dlp-kdd.github.io/assets/pdf/DLP-KDD_2021_paper_12.pdf)
"""

def __init__(self, bridge_type='attention_pooling', activation='relu', l2_reg=0, seed=1024, **kwargs):
def __init__(self, bridge_type='hadamard_product', activation='relu', **kwargs):
self.bridge_type = bridge_type
self.activation = activation
self.l2_reg = l2_reg
self.seed = seed

super(BridgeLayer, self).__init__(**kwargs)
super(BridgeModule, self).__init__(**kwargs)

def build(self, input_shape):
if not isinstance(input_shape, list) or len(input_shape) < 2:
raise ValueError(
'A `AttentionPoolingLayer` layer should be called '
'on a list of at least 2 inputs')
'A `BridgeModule` layer should be called '
'on a list of 2 inputs')

self.dnn_dim = int(input_shape[0][-1])
if self.bridge_type == "concatenation":
self.dense = Dense(self.dnn_dim, self.activation)
elif self.bridge_type == "attention_pooling":
self.dense_x = DNN([self.dnn_dim, self.dnn_dim], self.activation, output_activation='softmax')
self.dense_h = DNN([self.dnn_dim, self.dnn_dim], self.activation, output_activation='softmax')

self.dense = Dense(self.dnn_dim, self.activation)
self.dense_x = DNN([self.dnn_dim, self.dnn_dim], output_activation='softmax')
self.dense_h = DNN([self.dnn_dim, self.dnn_dim], output_activation='softmax')

super(BridgeLayer, self).build(input_shape) # Be sure to call this somewhere!
super(BridgeModule, self).build(input_shape) # Be sure to call this somewhere!

def call(self, inputs, **kwargs):
x, h = inputs
Expand All @@ -1543,7 +1540,7 @@ def call(self, inputs, **kwargs):
elif self.bridge_type == "hadamard_product":
return x * h
elif self.bridge_type == "concatenation":
return self.dense(tf.concat(inputs, axis=-1))
return self.dense(tf.concat([x, h], axis=-1))
elif self.bridge_type == "attention_pooling":
a_x = self.dense_x(x)
a_h = self.dense_h(h)
Expand All @@ -1553,12 +1550,10 @@ def compute_output_shape(self, input_shape):
return (None, self.dnn_dim)

def get_config(self):
base_config = super(BridgeLayer, self).get_config().copy()
base_config = super(BridgeModule, self).get_config().copy()
config = {
'bridge_type': self.bridge_type,
'l2_reg': self.l2_reg,
'activation': self.activation,
'seed': self.seed
'activation': self.activation
}
config.update(base_config)
return config
Loading

0 comments on commit 91dc7c6

Please sign in to comment.