# DACSR: Decoupled-Aggregated End-to-End Calibrated Sequential Recommendation
## 4 Methodology
### The Calibration Loss Function  
**Loss Function for Calibration** To generate a calibrated recommendation list, we design the loss function for the model training. The calibration measures the consistency between the recommendation list and the historical sequence. The distribution of historical sequence \(p(s)\) can be computed as Equation (4). For the recommendation list, we estimate its preference distribution \(\hat{q}(s)\) as follows:  
\[\hat{q}(g\mid s) =\sum_{i}^{|I|}\hat{y}_{i}\cdot p(g\mid i) \tag{6}\] \[\hat{y}_{i} =softmax(\hat{y}_{i}/\tau) \tag{7}\]  
where \(\hat{y}_{i}\) is the score of the item \(i\) predicted by the model, and it is further processed by a softmax function. If an item has a higher prediction score, it contributes more to \(\hat{q}(g\mid s)\). The softmax function also amplifies the difference in scores. Items with high scores will still be given higher weights, while weights of other items are close to 0. \(\tau\) (\(\tau>0\)) is the temperature parameter of softmax function. If \(\tau<1\), the score distribution becomes sharper and items with higher scores get more emphasis. In contrast, an extremely large value of \(\tau\) will make the score distribution more uniform. After estimating \(\hat{q}(g\mid s)(g\in G)\), we define the loss function of calibration as:  
\[L_{\mathit{Calib}}(\hat{y})=1-cos(\hat{q}(s),p(s)) \tag{8}\]  
where \(\hat{q}(s)\) is the estimated distribution vector \(\{\hat{q}(g=1\mid s),\dots,\hat{q}(g=G\mid s)\}\) and \(cos(v_{1},v_{2})\) is the cosine similarity between two vectors. If the two distributions are more consistent, the value of \(L_{\mathit{Calib}}\) will be lower. **Distribution Modification** Although calibration is related to diversity, a calibrated recommendation list is not always a diversified list. For example, a user who focuses on a few types of items will receive less diversified recommendations when calibration is considered. Therefore, if we want a diversified recommendation list to a certain degree, we can modify the distribution as follows:  
\[p_{d}(s)=softmax(p(s)/\tau_{div}) \tag{9}\]  
In this equation, the historical distribution \(p(s)\) is normalized by a softmax function. For item attribute \(g\) that the user did not interacted (i.e., \(p(g\mid s)=0\)), it will obtain a positive value. Therefore, all attributes are considered. The parameter \(\tau_{div}\) is also used to control the distribution, similar to \(\tau\). Meanwhile, for users who have homogeneous interests, their main interests may be amplified under the end-to-end framework. This is similar to the imbalanced classification tasks which tend to predict the major labels. To this end, we propose a mask-based modification method:  
\[p_{m}(s)=softmax(mask(p(s))/\tau_{div}) \tag{10}\]  
where the \(mask(p(s))\) give all attributes whose \(p(g\mid s)=0\) an extremely little negative value (e.g., \(-10^{10}\)). Therefore, scores of these attributes in \(p_{m}(s)\) will be 0. In this equation, \(\tau_{div}\) can be larger than 1 so that the distribution becomes more uniform, and the scores of the main interest and other interests are more close. The difference from Equation (9) is that the scope of interests are still limited in those the user have interacted with, while the \(p_{d}(s)\) distribution can explore new interests for the user. **Loss Function for Accuracy and Calibration** To obtain recommendation lists with accuracy and calibration, an intuitive way is directly optimizing the sequential recommendation model with a weighted sum of loss function:  
\[L_{w}(\hat{y})=(1-\lambda)L_{Acc}(\hat{y})+\lambda L_{\mathit{Calib}}(\hat{y}) \tag{11}\]  
where \(\lambda\in[0,1]\) is the trade-off factor between accuracy and calibration. A higher value of \(\lambda\) means more consideration on calibration. \(L_{Acc}\) is the accuracy-based loss function.