# An Easy Partition Approach for Joint Entity and Relation Extraction
## 3 Method
### Epre Architecture
#### 3.2.3 Task Module  
In the task module, we apply the features obtained from the previous module to obtain triples by table filling. Specifically, in the NER unit, we need to find the index of the tail token of the entity in the upper triangle part of the table, and mark the corresponding index position as 1. In the RE unit, we need to find the index of the head token pairs of the entity pair in the whole table range, and mark the index position as 1. The specific calculation process is as follows.  
**Entity recognition unit.** To make the model elastic enough, we feed the entity-level feature \(\mathbf{h_{ge}}\) to the fully-connected layer to obtain the token-level entity representation \(\mathbf{h^{e}}\) for identifying each entity type \(e\). We take the i-th token to describe the process:  
\[\mathbf{h^{e}_{i}}=\text{Linear}\left(\mathbf{h^{ge}_{i}}\right), \tag{7}\]  
where \(\mathbf{h^{ge}_{i}}\) is the entity-level global feature of the i-th token, and \(\mathbf{h^{e}_{i}}\) is the feature of the i-th token for entity type classification.  
Assume that the token \(x\) with position \(i\) is expressed as \(\mathbf{h^{e}_{i}}\), and the token \(y\) with position \(j\) is denoted as \(\mathbf{h^{e}_{j}}\). We can obtain the entity score \(e^{k}_{ij}\), as follows:  
\[e^{k}_{ij}=(\mathbf{h^{e}_{i}})^{\text{T}}\mathbf{h^{e}_{j}}. \tag{8}\]  
The corresponding loss function is as follows:  
\[\text{L}_{\text{ner}}=\sum_{k\in\mathbf{K}}\sum_{(ij)\in\mathbf{P_{k}}}\text{BCELoss} \left(e^{\hat{s}_{k(ij)}},\ e^{\hat{s}_{k}(ij)}\right), \tag{9}\]  
where \(s_{k}(i,\ j)\) represents the predicted entity score of the entity span of type \(k\), which is composed of tokens [\(i\);], \(\hat{s}_{k}(i,j)\) represents the true entity score of the entity span of type \(k\), which is composed of token [\(i\);], \(\mathbf{P}_{k}\) is the entity span set of type \(k\), and \(\mathbf{K}\) is the type set of entities.  
**Relation extraction unit.** In this unit, we only predict the relation score between the starting indices of each entity pair. The computation of the RE unit is symmetrical to the NER unit. We use the i-th and p-th tokens to denote the starting index of the entities in an entity pair. To obtain the global representation, for example, we take the p-th token global representation \(\mathbf{h^{gr}_{p}}\) to the fully-connected layer to obtain the token representation \(\mathbf{h^{r}_{p}}\). Then we use the dot product to compute the relation score \(r^{l}_{ij}\):  
\[\mathbf{h^{r}_{p}}=\text{Linear}\left(\mathbf{h^{gr}_{p}}\right), \tag{10}\]\[r^{l}_{pq}=(\mathbf{h^{r}_{p}})^{\mathrm{T}}\mathbf{h^{r}_{q}}, \tag{11}\]  
where \(r^{l}_{iq}\) is the relation score, which represents the probability of the relation type \(l\) between the entity pair. When the relation score is higher than a certain threshold \(\beta_{r}\), it can be interpreted as entities with start token indices \(i\), and \(p\) has a relation of type \(l\). The loss function \(L_{rel}\) is as follows:  
\[\mathrm{L_{rel}}=\sum_{l\in L}\sum_{(i,p)\in\mathbf{L}_{l}}\mathrm{BCELoss}(e^{i(i,p)},e^{i(i,p)}), \tag{12}\]  
where \(l\) represents the type of relation, \(\mathbf{L}\) is the set of relation types, \(s_{l}(i,p)\) is the predicted relation score and \(\hat{s_{l}}(i,p)\) is the true relation score, and \(\mathbf{L_{l}}\) is the entity pairs which have the \(l\) relation.