MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / DeepFM

Class DeepFM

modelzoo/features/runtime/deepfm/train.py:110–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108
109
110class DeepFM():
111 def __init__(self,
112 wide_column=None,
113 fm_column=None,
114 deep_column=None,
115 dnn_hidden_units=[1024, 256, 32],
116 final_hidden_units=[128, 64],
117 optimizer_type='adam',
118 learning_rate=0.001,
119 inputs=None,
120 use_bn=True,
121 bf16=False,
122 input_layer_partitioner=None,
123 dense_layer_partitioner=None):
124 if not inputs:
125 raise ValueError('Dataset is not defined.')
126 self.wide_column = wide_column
127 self.deep_column = deep_column
128 self.fm_column = fm_column
129 if not wide_column or not fm_column or not deep_column:
130 raise ValueError(
131 'Wide column, FM column or Deep column is not defined.')
132 self.dnn_hidden_units = dnn_hidden_units
133 self.final_hidden_units = final_hidden_units
134 self.optimizer_type = optimizer_type
135 self.learning_rate = learning_rate
136 self.input_layer_partitioner = input_layer_partitioner
137 self.dense_layer_partitioner = dense_layer_partitioner
138
139 self.feature = inputs[0]
140 self.label = inputs[1]
141 self.bf16 = bf16
142
143 self._is_training = True
144 self.use_bn = use_bn
145
146 self.predict = self.prediction()
147 with tf.name_scope('head'):
148 self.train_op, self.loss = self.optimizer()
149 self.acc, self.acc_op = tf.metrics.accuracy(labels=self.label,
150 predictions=tf.round(
151 self.predict))
152 self.auc, self.auc_op = tf.metrics.auc(labels=self.label,
153 predictions=self.predict,
154 num_thresholds=1000)
155 tf.summary.scalar('eval_acc', self.acc)
156 tf.summary.scalar('eval_auc', self.auc)
157
158 def dnn(self, dnn_input, dnn_hidden_units=None, layer_name=''):
159 for layer_id, num_hidden_units in enumerate(dnn_hidden_units):
160 with tf.variable_scope(layer_name + "_%d" % layer_id,
161 partitioner=self.dense_layer_partitioner,
162 reuse=tf.AUTO_REUSE) as dnn_layer_scope:
163 dnn_input = tf.layers.dense(dnn_input,
164 units=num_hidden_units,
165 activation=tf.nn.relu,
166 name=dnn_layer_scope)
167 if self.use_bn:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected