tensorflow / tensorflow/recommenders

Plotting model using keras

Open
#270 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

Hi Everyone,
I am new to tensorflow and tensorflow recommenders. I have tried DCN and other architectures.
When I am trying to plot using
tf.keras.utils.plot_model(model, "mymodel.png", show_shapes=False)
It only shows model name not the complete diagram.

I am trying below code
`class DCN(tfrs.Model):

def init(self, use_cross_layer, deep_layer_sizes, projection_dim=None):
super().init()

self.embedding_dimension = 32

str_features = ["movie_id", "user_id", "user_zip_code",
                "user_occupation_text"]
int_features = ["user_gender", "bucketized_user_age"]

self._all_features = str_features + int_features
self._embeddings = {}

# Compute embeddings for string features.
for feature_name in str_features:
  vocabulary = vocabularies[feature_name]
  self._embeddings[feature_name] = tf.keras.Sequential(
      [tf.keras.layers.experimental.preprocessing.StringLookup(
          vocabulary=vocabulary, mask_token=None),
       tf.keras.layers.Embedding(len(vocabulary) + 1,
                                 self.embedding_dimension)
])
  
# Compute embeddings for int features.
for feature_name in int_features:
  vocabulary = vocabularies[feature_name]
  self._embeddings[feature_name] = tf.keras.Sequential(
      [tf.keras.layers.experimental.preprocessing.IntegerLookup(
          vocabulary=vocabulary, mask_value=None),
       tf.keras.layers.Embedding(len(vocabulary) + 1,
                                 self.embedding_dimension)
])

if use_cross_layer:
  self._cross_layer = tfrs.layers.dcn.Cross(
      projection_dim=projection_dim,
      kernel_initializer="glorot_uniform")
else:
  self._cross_layer = None

self._deep_layers = [tf.keras.layers.Dense(layer_size, activation="relu")
  for layer_size in deep_layer_sizes]

self._logit_layer = tf.keras.layers.Dense(1)

self.task = tfrs.tasks.Ranking(
  loss=tf.keras.losses.MeanSquaredError(),
  metrics=[tf.keras.metrics.RootMeanSquaredError("RMSE")]
)

def call(self, features):
# Concatenate embeddings
embeddings = []
for feature_name in self._all_features:
embedding_fn = self._embeddings[feature_name]
embeddings.append(embedding_fn(features[feature_name]))

x = tf.concat(embeddings, axis=1)

# Build Cross Network
if self._cross_layer is not None:
  x = self._cross_layer(x)

# Build Deep Network
for deep_layer in self._deep_layers:
  x = deep_layer(x)

return self._logit_layer(x)

def compute_loss(self, features, training=False):
labels = features.pop("user_rating")
scores = self(features)
return self.task(
labels=labels,
predictions=scores,
)`

Can anyone help in this. I am able to see summary but not the diagram.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the shown DCN class and the tf.keras.utils.plot_model call, then inspect how the subclassed tfrs.Model is built and rendered. No repository file or test is identified; done would mean determining why only the model name appears and producing a complete diagram.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.