# Joint Extraction of Entities and Relations Based on Enhanced Span and Gate Mechanism
## 3 ESGM Model
### Span Extraction Module
This process allows for the identification of nested entities. The indexing process for the start and end positions of the spans is shown in Equations (6) and (7):  
\[T_{start\_s}=\left\{i|p_{i}^{start\_s}>h_{bar},i=1,2,\cdot\cdot\cdot,n\right\} \tag{6}\]  
\[T_{end\_s}=\left\{j|p_{j}^{end\_s}>t_{bar},j=1,2,\cdot\cdot\cdot,n\right\}\  
mation of the subject are crucial for accurately classifying the relation. The subject can provide contextual information relevant to the object, allowing for a better understanding of the object, its position, and the relationship between them. Furthermore, the subject can offer important clues to sentence meaning and semantic inference. Properly understanding and extracting the subject contributes to a more accurate comprehension of the sentence's semantics, thereby improving relation extraction and semantic inference. To sum up, the correct extraction of subjects is vital for the successful execution of entity and relation extraction tasks and the reliability of downstream applications. Therefore, in this study we focus on improving the accuracy and effectiveness of subject extraction in order to enhance the quality and reliability of entity and relation extraction.  
It can be seen from Figure 2 that after the span extraction module the span collection contains four spans, several of which are not entities; thus, it is necessary to judge the formed spans. In this module, the BERT-encoded sentence feature vector is input into an attention mechanism, allowing the information in the sentence to be learned. Each word in the sentence is projected to all words, including itself, in order to obtain the correlation between each word and then obtain the dependency between them. Words with strong dependencies must have greater correlations, and are more likely to be a subject. To capture multi-dimensional dependencies between words, the model utilizes a multi-head attention mechanism that captures dependencies from multiple spatial vectors, allowing it to learn richer features of the sentence. After the attention layer, a multi-layer binary classifier takes the span vector representations as input and leverages the learned entity features from the attention mechanism to determine whether the spans obtained in this module are subjects. By applying the process described in Equation (8), Span 4 is identified as not being a subject, resulting in the output of only three subject results:  
\[P_{m}(s|x_{j})=\sigma(W_{sub}\cdot[E^{i}_{start\_s},E^{j}_{end\_s}]+b_{sub}) \tag{8}\]  
where \(W_{sub}\) and \(b_{sub}\) respectively represent the training weights and biases of the model and \(E^{i}_{start\_s}\) and \(E^{j}_{end\_s}\) respectively indicate the token vectors corresponding to the span's start and end positions, with \(i\in T_{start\_s}\), \(j\in T_{end\_s}\), and \(i<j\). In order to reduce the occurrence of entity redundancy, in this paper we introduce a length limitation during the span combination process to remove spans that are deemed too long during the judgment process. Different parameters are set for English and Chinese datasets. In this model, the maximum length for English spans is set to 15.