tensorflow / tensorflow/recommenders
Model stops learning when using average batch loss instead of sum (Why even use sum?)
Nobody has claimed this yet.
- 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:
- In almost all of neural-network architectures I've seen, the batch-average loss is the norm - so why not for tensorflow-recommenders models?
- How can I successfully perform the basic retrieval example with batch-average loss?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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