AutoLossGen: Automatic Loss Function Generation for Recommender Systems

Zelong Li, Jianchao Ji, Yingqiang Ge, Yongfeng ZhangSIGIR 2022 · DOI

Abstract

In recommendation systems, the choice of loss function is critical since a good loss may significantly improve the model performance. However, manually designing a good loss is a big challenge due to the complexity of the problem. A large fraction of previous work focuses on handcrafted loss functions, which needs significant expertise and human effort. In this paper, inspired by the recent development of automated machine learning, we propose an automatic loss function generation framework, AutoLossGen, which is able to generate loss functions directly constructed from basic mathematical operators without prior knowledge on loss structure. More specifically, we develop a controller model driven by reinforcement learning to generate loss functions, and develop iterative and alternating optimization schedule to update the parameters of both the controller model and the recommender model. One challenge for automatic loss generation in recommender systems is the extreme sparsity of recommendation datasets, which leads to the sparse reward problem for loss generation and search. To solve the problem, we further develop a reward filtering mechanism for efficient and effective loss generation. Experimental results show that our framework manages to create tailored loss functions for different recommendation models and datasets, and the generated loss gives better recommendation performance than commonly used baseline losses. Besides, most of the generated losses are transferable, i.e., the loss generated based on one model and dataset also works well for another model or dataset.

Introduction

Recommender Systems (RS) typically rely on standard loss functions like Mean Squared Error (MSE) or Binary Cross-Entropy (BCE). While these "off-the-shelf" solutions are convenient, they often fail to align perfectly with specific evaluation metrics like AUC or NDCG, especially given the extreme data sparsity inherent in recommendation tasks. AutoLossGen addresses this by automating the design of loss functions, treating it as a search problem over mathematical expressions rather than relying on human intuition.

Methodology

AutoLossGen utilizes a reinforcement learning framework to discover novel loss functions. The process is divided into three distinct phases to ensure both efficiency and effectiveness.

The three-phase AutoLossGen framework: Loss Search, Validation Check, and Effectiveness Test.

The Controller and Search Space

At the heart of the system is an RNN-based controller (LSTM) that acts as the designer. In each round, the controller samples from a set of mathematical operators (e.g., Add, Multi, Log, Square) and variables (ground truth $y$, prediction $\hat{y}$, and constant $1$) to construct a computational graph representing a new loss function.

The RNN controller iteratively samples operators and variables to construct a loss function computational graph.

Iterative Optimization and Filtering

The framework employs a bi-level optimization strategy. The RS model is updated using a sampled loss for one epoch, and the resulting performance improvement on a validation set serves as a reward to update the controller via the REINFORCE algorithm. To handle the noise and sparsity of RS data, two critical mechanisms are implemented:

  1. Proxy Test: A rapid gradient check on small data batches to discard non-functional or redundant expressions, providing a 30x speedup.
  2. Reward Filtering: To prevent poorly performing losses from destabilizing the main RS model, candidate losses are first tested on a model copy. Only those yielding positive rewards are used to update the primary model.

Experimental Setup and Results

The framework was evaluated on the ML-100K (MovieLens) and Amazon Electronics datasets. The latter is particularly challenging due to its extreme sparsity (0.014% density).

Key Findings

  • Performance: Generated losses like MaxR ($max(\frac{\hat{y}+\epsilon}{y+\epsilon}, \frac{y+\epsilon}{\hat{y}+\epsilon})$) and SumR ($\frac{\hat{y}+y+\epsilon}{\hat{y} \cdot y + \epsilon}$) consistently outperformed standard baselines. For instance, MaxR achieved an AUC of 0.8087 on ML-100K, significantly higher than BCE's 0.7882.
  • Symmetry and Logic: The most successful losses exhibited high mathematical symmetry. Interestingly, the framework "rediscovered" MSE for regression tasks, validating the search logic.
  • Transferability: Losses generated for one specific model or dataset often performed well when applied to others, suggesting that AutoLossGen uncovers fundamental properties of the recommendation task itself.
  • Robustness: The Reward Filtering mechanism proved essential; without it, the search process failed to converge on the ultra-sparse Amazon dataset.

Conclusion

AutoLossGen demonstrates that machines can effectively design their own optimization objectives. By moving beyond handcrafted losses, the framework discovers tailored functions that better handle data sparsity and improve recommendation accuracy. Future work may involve expanding the search space to include more complex operators and exploring differentiable search methods for even greater efficiency.

Summary updated

BibTeX
@inproceedings{li2022autolossgen,
  author = {Zelong Li and Jianchao Ji and Yingqiang Ge and Yongfeng Zhang},
  title = {{AutoLossGen: Automatic Loss Function Generation for Recommender Systems}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2022},
  doi = {10.1145/3477495.3531941},
}
Figure