## 3 Methodology
### Self-Adversarial Negative Sampling Method Considering Entity Type  
Negative samples serve as non-target or contrast samples to help the model more accurately identify positive samples. By introducing negative samples, the model can learn the nuances in the data, thereby improving the task accuracy and robustness such as classification and recommendation, which has a significant impact on the training and performance improvement of the model. Currently, remarkable results have been achieved in the domains of KG embedding and word embedding. Considering the low efficiency of existing negative sampling methods, this paper proposes a self- adversarial negative sampling method considering entity type information based on the self- adversarial negative sampling proposed by RotatE model, and takes logical rules as constraints to ensure the effectiveness of negative sampling. Specifically, the negative sampling method includes two parts: negative sample generation and negative sample collection. The negative sample generation methods are divided into three types: entity replacement based, relation replacement based and entity type replacement based negative sample generation. Among them, entity replacement based and entity type replacement based negative sample generation are used for entity completion task, while relation replacement based negative sample generation is used for relation completion task. The flow of the negative sample generation method is shown in Figure 3 below. For example, for the entity replacement based negative sample generation method, the training data set is constructed including entity dictionary, entity type dictionary, entity-entity type dictionary, and quintuple dictionary. For each five-tuple in quintuple dictionary, random head entity replacement (h -> h' or t') is performed based on the constructed entity dictionary. Simultaneously, the entity type is replaced based on the constructed entity-entitytype dictionary to ensure that the entity-entity type is correct, which is convenient for the subsequent model training based on logical rules. The replaced quintuple is filtered by the quintuple dictionary to ensure that the replaced quintuple is a negative sample. In this process, the function of the quintuple dictionary is to ensure that the generated sample is negative. The purpose of the entity dictionary and the entity-entity type dictionary is to ensure that when an entity is replaced, its entity type is replaced accordingly. For the negative sample generation based on entity replacement and entity type replacement, in essence, the two parts of entity and entity type are replaced. The reason is that the essence of the model training process based on embedded learning is to express and train the relation between _<head entity_, _relation_, _tail entity_> in vector space, and entity type does not participate in it. Therefore, the negative samples generated by simply replacing the entity type are still positive samples in essence, and only the samples generated after replacing the entity or relation can participate in the model training process as negative samples. Negative sampling loss usually samples negative triplets uniformly, but this approach leads to inefficiencies. Therefore, based on generated negative samples, a self-adversarial sampling strategy is adopted to sample entities and relations in the negative samples. Specifically, the negative quintuple is extracted from the following distribution according to the current embedded model:  
\[p\left(h_{j}^{\prime},r,t_{j}^{\prime}\middle|\left\{\left(h_{i},r,t_{i} \right)\right\}\right)=\frac{\exp\alpha f_{r}\left(h_{j}^{\prime},t_{j}^{ \prime}\right)}{\sum_{i}\exp\alpha f_{r}\left(h_{i}^{\prime},t_{i}^{\prime}\right)} \tag{3}\]  
where, \(\alpha\) is the sampling probability and _fr_() is the scoring function of the embedded model.