## 2 TransRFT Model Principle and Training
### Model Training  
The model must be trained beforehand for both link prediction and experimentation in triplet classification. The conventional approach is to construct negative example triples by randomly replacing the head and tail entities in the positive example triples in the entity set. This labels the original correct triplet as the wrong one. However, this simple sampling method leads to the poor quality of some of the generated negative example triples, which makes the training of the model not as effective as expected, thus affecting the actual score. As a result, when the model is trained, the probabilistic technique is selected to replace the head and tail entities. The model can learn more entities and relationships and obtain better parameter combinations since more entity attributes can be taught in this manner. In order to enhance the model's capacity to distinguish between comparable entities, replacement entities that are similar to the original ones are chosen. (1) Probability method to replace the head and tail entities  
The head and tail entities are replaced when creating a negative triplet, depending on the nature of the relationships between the entities. Both the head and tail entities have several features, regardless of whether the relationship between the entities is one-to-many or many-to-one. When the relationship between entities is many-to-one, the strategy is to replace the tail entity with a higher probability, because this allows the multiple properties of the tail entity to be better trained. When there is a one-to-many relationship between the entities, the head entity is replaced with a greater probability so that the various attributes of the head entity may be trained more effectively. During the model training process, we designate tph as the average number of tail entities corresponding to each head entity in a triplet, and hpt as the average number of head entities corresponding to each tail entity in a triplet. And then the head-tail entity will be replaced by the probability method. According to Equation (4), the sampling process follows the Bernoulli distribution. \[q=\frac{tph}{(tph+hpt)} \tag{4}\]  
When constructing a negative triplet using a positive triplet, the header entity is replaced with probability q and the tail entity is replaced with probability 1-q. At the same time, it is stipulated that when tph \(<\) 1.5 and hpt \(<\) 1.5, it means that the relationship r is one-to-one; when tph \(>\) 1.5 and hpt \(>\) 1.5, it means that the relationship r is many-to-many. When tph \(\geq\) 1.5 and hpt \(<\) 1.5, then the relationship r is one-to-many; when tph \(<\) 1.5 and hpt \(\geq\) 1.5, then the relationship r is many-to-one. (2) The entities are selected based on their similarity  
When judging the similarity between entities, the semantic similarity between entities or relationships is often selected for judgment, which is reflected in the vector space, that is, the similarity between calculation vectors. The calculation formula is as follows:  
\[dis\big{(}E,E^{\prime}\big{)}=\sqrt{\sum_{j=1}^{k}\big{(}E_{j}-E^{\prime}_{j} \big{)}} \tag{5}\]  
where \(E\) is the entity. Specifically, given a positive example triplet \((h,r,t)\), when replacing the header entity to generate a negative example triplet \((h^{\prime},r,t)\), \(h^{\prime}\) is selected to minimize \(dis(h,h^{\prime})\); when replacing tail entities to generate negative example triples \((h,r,t^{\prime})\), \(t^{\prime}\) is selected to minimize \(dis(t,t^{\prime})\). In the process of model training, in order to distinguish between correct triples and wrong triples, the following marginal loss function is adopted as the optimization objective function of the training model:  
\[L=\sum_{(h,r,t)\in S}\sum_{(h^{\prime},r,t^{\prime})\in S^{\prime}}\max\bigl{(}f _{r}(h,t)+\gamma-f_{r}\bigl{(}h^{\prime},t^{\prime}\bigr{)},0\bigr{)} \tag{6}\]  
where \(S\) is all positive case triples and \(S\) is all negative case triples. \(\max(x,y)\) is the larger value in the \(x,y\).