# Construction of Cultural Heritage Knowledge Graph Based on Graph Attention Neural Network
## 4 Data Model Construction
### Model Training and Optimization  
The input dataset is divided into training, validation, and test sets. After preprocessing the input data, the model needs to undergo parameter tuning and validation evaluation.  
The parameter tuning process consists of two stages: one involves adjusting and optimizing the model's hyperparameters using the validation set and the other involves adjusting and optimizing the model's internal parameters using the training set. During the model training process, loss functions are designed for the entity recognition task and the relationship extraction task to calculate the error between the model's predictions and the actual values, reflecting the accuracy of the model's predictions.  
The error calculated from the loss function is used to optimize the model's parameters through the backpropagation algorithm, adjusting the internal parameters of the model to minimize the loss function value. If the model's performance does not significantly improve or if overfitting occurs, adjustments to the model structure, such as changing the number of network layers, may be necessary.  
The entity recognition task can be treated as a multiclass classification problem, using the cross-entropy loss function as the loss function for the entity recognition task, as shown in Equation (29) [36]  
\[L_{NER}=\sum_{i=0}^{n+1}\text{lg}\left(\hat{y}_{i}^{p}\right) \tag{29}\]  
\(n\) is the total number of entity labels in the entity recognition task and \(\hat{y}_{i}^{p}\) is the probability that the model predicts segment \(p\) belongs to the \(i\)-th entity category.\(y_{i}\) represents the actual label information, using one-hot encoding, where \(y_{i}=1\) indicates that the segment \(p\) belongs to the \(i\)-th category; if \(y_{i}=0\), it indicates that the segment \(p\) does not belong to the \(i\)-th category. In the relationship extraction task, to handle a single entity potentially having multiple types of relationships, a multilabel cross-entropy loss function is used to calculate the loss. This loss function is suitable for multientity classification problems, where each entity is considered an independent binary classification problem. For each possible relationship type, the model will predict a probability to indicate whether the relationship exists. The calculation formula is shown in Equation (30) [36].  
\[L_{RE}=-\sum_{j=0}^{n+1}\text{lg}(\hat{y}_{k}^{r})+(1-y_{k})\text{lg}(1-\hat{ y}_{k}^{r}) \tag{30}\]  
\(r\) represents the total number of possible relationship categories and \(\hat{y}_{k}^{r}\) is the probability predicted by the model, indicating the model's prediction of the existence of a relationship of the \(k\)-th category between two entities. \(y_{k}\) represents the true distribution of the relationship category labels, using one-hot encoding. If \(y_{k}=1\), it means that there is a relationship of the \(k\)-th category between the two entities; if \(y_{k}=0\), it means that there is no relationship of the \(k\)-th category between the two entities.  
The overall loss function of the model consists of the loss function for entity recognition and the loss function for relationship extraction, as shown in Equation (31) [36]  
\[L=L_{NER}+L_{RE} \tag{31}\]  
By minimizing the total loss parameter, the model's overall extraction capability can be improved, achieving joint optimization for both entity recognition and relationship extraction tasks.