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

Method _create_model

modelzoo/dssm/train.py:154–225  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

152
153 # create model
154 def _create_model(self):
155 # input embeddings of user & item features
156 with tf.variable_scope('input_layer',
157 partitioner=self._input_layer_partitioner,
158 reuse=tf.AUTO_REUSE):
159 if self._adaptive_emb and not self.tf:
160 '''Adaptive Embedding Feature Part 1 of 2'''
161 adaptive_mask_tensors = {}
162 for col in INPUT_FEATURES:
163 adaptive_mask_tensors[col] = tf.ones([self._batch_size],
164 tf.int32)
165 user_emb = tf.feature_column.input_layer(
166 self._feature,
167 self._user_column,
168 adaptive_mask_tensors=adaptive_mask_tensors)
169 item_emb = tf.feature_column.input_layer(
170 self._feature,
171 self._item_column,
172 adaptive_mask_tensors=adaptive_mask_tensors)
173 else:
174 for key in TAG_COLUMN:
175 self._feature[key] = tf.strings.split(
176 self._feature[key], '|')
177 user_emb = tf.feature_column.input_layer(
178 self._feature, self._user_column)
179 item_emb = tf.feature_column.input_layer(
180 self._feature, self._item_column)
181
182 if self.bf16:
183 user_emb = tf.cast(user_emb, dtype=tf.bfloat16)
184 item_emb = tf.cast(item_emb, dtype=tf.bfloat16)
185
186 # user dnn network
187 user_scope = tf.variable_scope('user_dnn_layer', \
188 partitioner=self._dense_layer_partitioner,
189 reuse=tf.AUTO_REUSE)
190 with user_scope.keep_weights(dtype=tf.float32) if self.bf16 \
191 else user_scope:
192 user_emb = self._dnn_tower(user_emb, 'user_dnn')
193
194 # item dnn network
195 item_scope = tf.variable_scope('item_dnn_layer', \
196 partitioner=self._dense_layer_partitioner,
197 reuse=tf.AUTO_REUSE)
198 with item_scope.keep_weights(dtype=tf.float32) if self.bf16 \
199 else item_scope:
200 item_emb = self._dnn_tower(item_emb, 'item_dnn')
201
202 if self.bf16:
203 user_emb = tf.cast(user_emb, dtype=tf.float32)
204 item_emb = tf.cast(item_emb, dtype=tf.float32)
205
206 # norm
207 user_emb = tf.math.l2_normalize(user_emb, axis=1)
208 item_emb = tf.math.l2_normalize(item_emb, axis=1)
209
210 user_item_sim = tf.reduce_sum(tf.multiply(user_emb, item_emb),
211 axis=1,

Callers 1

__init__Method · 0.95

Calls 11

_dnn_towerMethod · 0.95
variable_scopeMethod · 0.80
onesMethod · 0.80
keep_weightsMethod · 0.80
reduce_sumMethod · 0.80
multiplyMethod · 0.80
reshapeMethod · 0.80
splitMethod · 0.45
castMethod · 0.45
get_variableMethod · 0.45
matmulMethod · 0.45

Tested by

no test coverage detected