# DTGCF: Diversified Tag-Aware Recommendation with Graph Collaborative Filtering
## 4 Methodology
### Adversarial Learning  
As introduced previously, we can learn effective user representations and item representations by optimizing the loss function. In an accuracy-focused recommendation model, the learned positive item representation should be closer to the target user representation than negative item representation. Essentially, item representations can reflect the interests of the corresponding users. Nevertheless, items have their own unique characteristics such as category. Especially in TRS, the user-defined tags contain rich semantic information. Similar items within the same category are more likely to have similar representations. Consequently, more items in the positive categories are easier to be recommended, which limits the opportunity for those items from diverse categories to be exposed to users. Based on the above considerations, we adopt the strategy of adversarial learning used in [23; 55] to further improve the recommendation diversity. Concretely, we perform an extra category classification task based on the learned item representations. The trained classifier is expected to predict the item category as accurately as possible. For the recommendation model, we hope that it can learn item representations which can deceive the classifier most while providing high-quality recommendations. In other words, the recommendation model and the classifier are trained in an adversarial way. To construct an item category classifier, we utilize a fully connected layer with a softmax function. Formally, assuming that the final representations of item \(i\) is \(li_{i}\), we can calculate the corresponding category probabilities by:  
\[p_{i}=\text{softmax}(W^{T}h_{i}), \tag{10}\]  
where \(W\) is the learnable parameter and the softmax function is used to transform the category scores into a probability distribution. Each element of \(p_{i}\) represents the probability of belonging to a certain class from the category set \(C\) and the sum of all elements is equal to 1. We adopt the multi-class cross entropy as the loss function, which is defined as  
\[L_{C}(i)=-\sum_{j}^{|C|}c_{i}(j)\log p_{i}(j), \tag{11}\]  
where \(c_{i}(j)\) is 0 or 1, indicating whether \(j\) is the correct category of item \(i\). By averaging the loss of all training samples, we can obtain the whole loss of category classification \(L_{C}\). Within the framework of adversarial learning, the goal of the classifier is to minimize the classification loss \(L_{\text{C}}\), while the goal of the proposed recommendation model is to minimize \(L_{\text{G}}-\lambda L_{\text{C}}\), where \(L_{\text{G}}\) is the loss of the recommendation task, and \(\lambda\) is used to trade off the main task and the extra adversarial task. Note that the sign \"-\" before \(L_{\text{C}}\) means that the classification loss is reversed to force representation of items in the same category away from each other. To train the model based on adversarial learning in an elegant way, we resort to the gradient reversal layer (GRL), which is verified to be effective and efficient in [56]. Mathematically, GRL can be regarded as a \"pseudo-function\" \(GR_{\lambda}(\mathbf{x})\) that has the following forward- and back-propagation behavior:  
\[ \begin{array}{l}GR_{\lambda}(\mathbf{x})=\mathbf{x},\\ \frac{dGR_{\lambda}(\mathbf{x})}{dx}=-\lambda\mathbf{I},\end{array}  \tag{12}\]  
where \(\mathbf{I}\) denotes an identity matrix and \(\lambda\) is the tunable parameter. Fundamentally, GRL serves as an identity transformation at the stage of the forward propagation. More importantly, GRL can obtain the gradient from the next layer, multiply it by \(-\lambda\), and pass it to the previous layer at the stage of back-propagation. By inserting a GRL in between the learned item representation and the category classifier, our adversarial learning can be achieved in a deep feed-forward architecture through standard back-propagation training.