Considering adding complex DL models such as Wide & Deep Learning Model
See original GitHub issueHi,
It is apparent that TF-Ranking is utilizing 3-layer MLP for learning to rank. So I am considering adding other complex models demonstrating abilities for recommender systems or CTR to TFR library. The Wide & Deep learning from Google 2016 uses a wide structure for memorization and a DNN for generation. I tried to add a linear combination part to _score_fn, then use both wide and deep logits to optimize for listwise-based softmax loss. I am pasting my code here. Can someone have a look and point out if I make any mistakes? Thanks!
def _score_fn(unused_context_features, group_features, mode, unused_params,
unused_config):
"""Defines the network to score a group of documents."""
with tf.compat.v1.name_scope("input_layer"):
group_input = [
tf.compat.v1.layers.flatten(group_features[name])
for name in sorted(example_feature_columns())
]
input_layer = tf.concat(group_input, 1)
# tf.compat.v1.summary.scalar("input_sparsity",
# tf.nn.zero_fraction(input_layer))
# tf.compat.v1.summary.scalar("input_max",
# tf.reduce_max(input_tensor=input_layer))
# tf.compat.v1.summary.scalar("input_min",
# tf.reduce_min(input_tensor=input_layer))
is_training = (mode == tf.estimator.ModeKeys.TRAIN)
cur_layer = input_layer
cur_layer = tf.compat.v1.layers.batch_normalization(
input_layer, training=is_training)
for i, layer_width in enumerate(int(d) for d in FLAGS.hidden_layer_dims):
cur_layer = tf.compat.v1.layers.dense(cur_layer, units=layer_width)
cur_layer = tf.compat.v1.layers.batch_normalization(
cur_layer, training=is_training)
cur_layer = tf.nn.relu(cur_layer)
# tf.compat.v1.summary.scalar("fully_connected_{}_sparsity".format(i),
# tf.nn.zero_fraction(cur_layer))
cur_layer = tf.compat.v1.layers.dropout(
cur_layer, rate=FLAGS.dropout_rate, training=is_training)
logits = tf.compat.v1.layers.dense(cur_layer, units=FLAGS.group_size)
print("Checkpoint 1: ", logits)
dnn_logits = logits
## Build linear classifier
group_input = [
tf.compat.v1.layers.flatten(group_features[name])
for name in sorted(example_feature_columns())
]
input_layer = tf.concat(group_input, 1)
is_training = (mode == tf.estimator.ModeKeys.TRAIN)
cur_layer = tf.compat.v1.layers.batch_normalization(
input_layer, training=is_training)
cur_layer = tf.compat.v1.layers.dense(cur_layer, units=2)
#cur_layer = tf.compat.v1.layers.batch_normalization(
#cur_layer, training=is_training)
#cur_layer = tf.nn.sigmoid(cur_layer)
linear_logits = tf.compat.v1.layers.dense(cur_layer, units=FLAGS.group_size)
print("Checkpoint 2: ", logits)
# Combine logits and build full model.
if dnn_logits is not None and linear_logits is not None:
logits = dnn_logits + linear_logits
elif dnn_logits is not None:
logits = dnn_logits
else:
logits = linear_logits
if _use_multi_head():
# Duplicate the logits for both heads.
return {_PRIMARY_HEAD: logits, _SECONDARY_HEAD: logits}
else:
return logits
return _score_fn
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Wide and Deep learning With TensorFlow in 10 Min - Medium
The concept is to join the two methods of memorizing and generalizing the learnings by making a wide linear model and a deep...
Read more >Review of deep learning: concepts, CNN architectures ...
In this paper, an overview of DL is presented that adopts various perspectives such as the main concepts, architectures, challenges, ...
Read more >Deep Learning Model - an overview | ScienceDirect Topics
First, most deep learning models have a large model complexity. Deep learning is based on artificial neural networks (ANN), and one of the...
Read more >Deep Learning: A Comprehensive Overview on Techniques ...
Although DL models are successfully applied in various application areas, mentioned above, building an appropriate model of deep learning is ...
Read more >When and When Not to Use Deep Learning - Dataiku blog
Deep learning is all the rage right now, but is it always the best solution? Here's a guide to choosing when and when...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Oh I maybe mixed a little bit. My project is Learning to rank more precisely. The features in the libsvm format are item embeddings and use embeddings. But I used TF Ranking for the ranking and did not need to use matrix factorization at this moment.
Closing this discussion for now. A lot of good of advice here, we may use it for future reference.