tensorflow / tensorflow/recommenders

Model stops learning when using average batch loss instead of sum (Why even use sum?)

Open
#213 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would like to have the average batch loss, instead of the sum. This because it simplifies a lot of things when performing hyper-parameter tuning in regards to learning-rate, regularization parameters and so on.

To do this, I've simply replaced the default task from the source:

    self._loss = loss if loss is not None else tf.keras.losses.CategoricalCrossentropy(
        from_logits=True, reduction=tf.keras.losses.Reduction.SUM)

with the loss (SUM_OVER_BATCH_SIZE ):

task = tfrs.tasks.Retrieval(
  loss=tf.keras.losses.CategoricalCrossentropy(
                from_logits=True, reduction=tf.keras.losses.Reduction.SUM_OVER_BATCH_SIZE                           
            ),
  metrics=tfrs.metrics.FactorizedTopK(
      candidates=movies.batch(128).map(movie_model)
  )
)

When I do this change in the basic retrieval example, the loss never decreases, thus stops learning and top-k performance obviously goes down the drain. I've played around with learning rates and batch sizes but all to no avail.

Because of this, I have two questions:

  1. In almost all of neural-network architectures I've seen, the batch-average loss is the norm - so why not for tensorflow-recommenders models?
  2. How can I successfully perform the basic retrieval example with batch-average loss?

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 with the basic retrieval example and the shown tfrs.tasks.Retrieval loss configuration; compare SUM with SUM_OVER_BATCH_SIZE while checking the training loss and top-k metrics. Determine why average batch loss prevents learning, then document or reproduce the conditions under which the example trains successfully.

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
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.