{'fraction_non_alphanumeric': 0.030978934324659233, 'fraction_numerical': 0.009350005632533513, 'mean_word_length': 4.958053691275167, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Nested Named Entity Recognition from Medical Texts: An Adaptive Shared Network Architecture with Attentive CRF

Recognizing useful named entities plays a vital role in medical information processing, which helps drive the development of medical area research. Deep learning methods have achieved good results in medical named entity recognition (NER). However, we find that existing methods face great challenges when dealing with the nested named entities. In this work, we propose a novel method, referred to as ASAC, to solve the dilemma caused by the nested phenomenon, in which the core idea is to model the dependency between different categories of entity recognition. The proposed method contains two key modules: the adaptive shared (AS) part and the attentive conditional random field (ACRF) module. The former part automatically assigns adaptive weights across each task to achieve optimal recognition accuracy in the multi-layer network. The latter module employs the attention operation to model the dependency between different entities. In this way, our model could learn better entity representations by capturing the implicit distinctions and relationships between different categories of entities. Extensive experiments on public datasets verify the effectiveness of our method. Besides, we also perform ablation analyses to deeply understand our methods.


Introduction
Natural language documents in the medical field, such as medical textbooks, medical encyclopedias, clinical cases, and test reports, contain much medical expertise and terminology. The key idea of understanding medical data is to extract critical knowledge from the medical text accurately [21]. Therefore, accurate and rapid extraction of medical entities and transformation of these unstructured data into structured domain knowledge graphs are crucial for obtaining and exploiting medical information. Named entity recognition (NER) based on deep learning applies machines to read medical texts, which significantly improve the efficiency and quality of medical research and serve downstream subtasks [16]. However, there are often cases of nested named entities in texts in the medical field. Figure 1 displays an example of nested NER in Chinese medical texts, where the symptom named entity contains the body named entity. The foremost sequence labeling method [9,1] is only valid for non-nested entities (or flat entities). Previous studies have given some solutions, which regard NER either as question answering [25], span classification [12], dependency parsing tasks [32], or discrete joint model [11]. However, despite the success of span prediction based systems, these methods suffer from some different weaknesses [26]. First, their method suffers from the boundary inconsistency problem due to the separate decoding procedures. Then, due to numerous low-quality candidate spans, these methods require high computational costs. Next, it is hard to identify long entities frequently found in medical texts because the length of the span enumerated during training is not infinite. Different from the above researches, layered methods solve this task through multi-level sequential labeling [27,6], which can capture the dependencies between adjacent word-level labels and maximize the probability of predicted labels over the whole sentence [31]. However, these methods always simply divide entities into several levels, where the term level indicates the depth of entity nesting, and sequential labeling is performed repeatedly. Therefore, the differences between entity categories have not been noticed, since just identifying the results of each layer independently. Moreover, there are often implicit relationships between the recognition results of different entity categories, such as symptom and body, but it is easy to be ignored or only pass results from lower layers to upper layers without the reverse way.
In this paper, we propose a Adaptive Shared network architecture with Attentive Conditional random fields namely ASAC based on the end-to-end sequence labeling, which can handle the nested NER for medical texts. Our model not only takes advantage of sequence labeling, but also equally considers the implicit distinctions and relationships between entities in different layers. More specifically, we introduce the adaptive shared mechanism for pre-trained language model at encoding, to adaptively learn the difference between different entities recognition tasks [22]. This method has a better fitting ability than the hard-shared method [29,3], which shares different modules according to a fixed strategy. Besides, we utilize attentive conditional random fields to explore the relationships among the multi-layer learning results at decoding based on attention mechanism [20].
Our main contributions are as follows: -We introduce a novel ASAC model based on deep learning methods, which can efficiently extract named entities from medical texts. We leverage effective mechanisms to enable the model to adaptively discover distinctions and connections between multiple entity recognition tasks in parallel, in order to enhance the performance of the NER task. -We adopt the Adaptive Shared (AS) mechanism [29]

Related Work
In this section, we review the related work on the current approaches for NER, including the pre-trained language model, nested NER algorithm, and the Chinese NER in the medical domain.

Chinese Medical NER
With the increasing demand for NER in the medical field, there have emerged some related medical competitions and datasets, such as CHIP 4 and CCKS 5 . However, due to privacy or property rights protection issues, the medical NER corpora, especially the Chinese medical NER corpora, is particularly scarce [21]. There is no other officially authorized way for these datasets. So most of the research on Chinese medical NER is based on China Conference on Knowledge Graph and Semantic Computing (CCKS) datasets.
When it comes to solutions, Chinese NER methods based on deep learning have gradually become dominant and have achieved continuous performance improvements [13]. Cai et al. [2] added attention layers between the character representation and the context encoder. Zhu et al. [33] used a convolutional attention layer between the feature representation and the encoder.

Nested NER
Previously, some researchers have also discussed the nested NER based on deep learning. There are various solutions, mainly including the following: (a) transform the decoding process into multi-classification decoding [28,19]. (b) spanbased methods which treat NER as a classification task on a span with the innate ability to recognize nested named entities [7,12]. (c) use other modeling methods instead of sequence labeling and span-based methods, such as machine reading comprehension task [18], constructing a hyper-graph [30], etc

Pre-trained Model
In recent years, the emergence of the pre-trained model has brought NLP into a new era. Many researches [21] have shown that the pre-trained model trained on a very large corpus can learn a lot of language text representation suitable for different domains. This approach can often help different downstream NLP tasks, including NER. Among various well-known pre-trained language models, the BERT model [5] with excellent results is widely used. BERT is a bi-directional encoder based on transformer. It can mine the representation information contained in the context through the self-supervised learning task. Some researchers have carried out more research on the basis of BERT and put forward many improved models, such as RoBERTa [23], AlBERT [15], and so on.

Methodology
Our ASAC model can be divided into two modules. The former part is an adaptive shared pre-trained language model for encoding the input texts to capture the distinctions between pre-defined different entity categories. The latter part is the attentive conditional random field for decoding to acquire the relationships of recognition results between the parallel tasks. The input texts pass through the former module and obtain the encoding features matched with different entity categories according to the pre-defined entity categories classes. Afterwards the attentive conditional random fields make the model learns the residual value according to the label results of other classes, and uses the attention mechanism to correct the output of the original conditional random fields. Figure 2 illustrates an overview of the model structure.

Adaptive Shared Pre-trained Model
The data representation method follows the paper of Devlin et al. [5]. We use special '[CLS]' and ' [SEP]' tokens at the beginning and end of sentences respectively, and add '[PAD]' tokens at the end of sentences to make their lengths equal to the maximum sequence length. All models are character-level based. The adaptive shared mechanism [29] will assign a learnable weight α ij to each transformer encoder layer of the BERT pre-trained model, and update the value of the weight during backward propagation. i indicates that the number of entity categories classes, and the number of transformer encoder layers of the pre-trained model defines the max value of j. They can be calculated as: where n denotes the total number of transformer encoder layers of the pre-trained language model, E i denotes the encoder results of i th entity categories classes. In addition, in order to ensure that the weight can better reflect the actual action of each layer after each batch of learning, and prevent the weight from disappearing or exploding, the sof tmax function is used to output the corrected value of the weight after calculation, as follows:

Attentive Conditional Random Fields
Conditional random fields (CRF) were proposed by Lafferty et al. [14] in 2001. It has mixed the characteristics of maximum entropy model and hidden Markov model. CRF has been widely used in state-of-the-art NER models to help make better decisions, which considers strong label dependencies by adding transition scores between neighboring labels. Viterbi algorithm is applied to search for the label sequence with the highest probability during the decoding process. For y = {y 1 , ..., y N } being a sequence of predictions with length N . Its score is defined as follows.
where T yi,yi+1 represents the transmission score from y i to y i+1 , H i,yi is the score of the j th tag of the i th word from the adaptive shared encoder. CRF model defines a family of conditional probability p(y|x) over all possible tag sequences y: during training phase, we consider the maximum log probability of the correct predictions. While decoding, we search the tag sequences with maximum score: Supposed that there are m entity categories classes that we defined in advance. It means that we have m parallel CRFs. For each CRF, the inference results of other parallel CRFs are used as the query of the attention mechanism.
Here, set C denotes the Viterbi decoding results of all CRFs except the current one, and d l indicates the max sequence length of each input text. We calculate the attention value of i th CRF as: where W f ∈ R dt×d l , b f ∈ R dt×d l . c denotes the padding constant, and is set to 0 in our paper. d t denotes the number of tags plus the padding zero. Then we exploit attention mechanism to explicitly learn the dependencies between the origin score and the parallel results and capture the inner structure information of sentence.
where K i ∈ R dt×d l , V i ∈ R dt×d l are keys matrix and value matrix, respectively. In our setting, K i = V i = H i , denotes that the input of i th CRF. Then we plus the residual R i and the origin H i to i th CRF again, and get the final prediction label list.

Dataset
We conduct experiments on the Chinese medical NER, namely the Chinese Medical Entity Extraction dataset (CMeEE) [8], which is a subtask of Chinese Biomedical Language Understanding Evaluation 6 (CBLUE). While absorbing the previous CHIP/CCKS/CCL and other academic evaluation tasks, the dataset also appropriately increases the industry data. Hence, this dataset can well cover the task of Chinese NER in the medical field. CMeEE dataset contains 20,000 texts and we randomly split these data into training, development, and test sets by 14:3:3, respectively. The goal of this task is to detect and extract the named entities from Chinese medical texts, and divide them into one of the nine pre-defined categories. The statistical results of the nine types of named entities are shown in Table 1. Dataset provider points that all nested named entities are allowed in the sym entity category, and other eight types of entities are allowed inside the entity. So we divide these nine entity categories into two classes: one contains the sym entity category and the other one contains eight other entity categories.

Experimental Setup
Precision (P ), Recall (R) and F-score(F 1) are used to evaluate the predicted entities. An entity is confirmed correct when the predicted category and predicted span both are completely correct. Our model is implemented with PyTorch and we run experiments on NVIDIA Tesla V100 with 32 GB memory. We use the AdamW optimizer for parameter optimization [24]. Most of the model hyper-parameters are listed in Table 2. The pre-trained model used in this paper comes from [4], namely BERT-wwm-ext, Chinese, with 12-layer, 768hidden, 12-heads and 110M parameters. Table 3 shows the overall comparisons of different models for the end-to-end Chinese medical NER. We conduct several neural models as baselines. First is the BiLSTM-CRF, which adopts BiLSTM [9] for encoding input texts and a single CRF for decoding entity labels. And BERT-MLP [4], which employs the linear layer for label classification above the BERT pre-trained language model. Another one is BERT-CRF [17], which uses CRF for decoding on the basis of the BERT encoding features. On the CMeEE dataset, our method improves the F 1 scores by 12.5, 3.1, and 2.0 respectively, compared with BiLSTM-CRF, BERT-MLP, and BERT-CRF. Furthermore, our approach achieves better results in 6 of the 9 entity categories, surpassing other baseline models.

Ablation Studies
In this paper, we introduce the interactions of adaptive shared mechanism and attentive conditional random fields to respectively help better predict nested named entities in the dataset. We implement an ablation study to verify the effectiveness of the interactions. We conduct four experiments: (a) our model with adaptive shared mechanism and attentive conditional random fields. (b) without adaptive shared mechanism: we skip Eq. (2)-(3) and only used the final output layer of the BERT-based pre-trained model for encoding. (c) without attentive conditional random fields: we skip Eq. (7)-(9) and use separate CRFs to predict the labels of different category classes, and combine the results. (d) without adaptive shared mechanism and attentive conditional random fields: a combination of (b) and (c), different from BERT-CRF, there are two independent CRFs for decoding entities from two category classes. Table 4 shows the experimental results. Experimental results show that adaptive shared mechanism and attentive conditional random fields both make a positive effect on prediction, while attentive conditional random fields are a little more effective. Compared to abandoning the above two methods, our model received a 1.12 F1 score boost. Analysis of the Adaptive Shared Mechanism. Some researches [10] show that different context features are stored in different layers of the BERT-based pre-trained language model. Therefore, we reasonably infer that different features of hidden layers can variously affect the recognition of different entity categories. As mentioned above, we divide entity categories into two classes. Under the adaptive shared mechanism, there are two groups of weights: {α 1,0 , ..., α 1,11 } for class 1, {α 2,0 , ..., α 2,11 } for class 2 to extract the different layers of the pre-trained model. Figure 3 shows the weights of two classes after training.
According to the data shown in the figure, we notice that class 1 prefers the upper layers outputs of the BERT-based model while middle layers outputs have a greater impact on class 2. Therefore, the adaptive shared mechanism enables the model to learn the context features that match the nested entity category better, which is conducive to subsequent decoding.
Analysis of the Attentive Conditional Random Fields. In the decoding module, we count the changed labels between the outputs of the initial CRF and the outputs plus the residual of the CRF after the attention mechanism. Table 5 evaluates the performance of attentive conditional random fields. In a total of 155,658 tokens of 3,000 test cases, 4,816 and 1,392 prediction labels for the two classes have changed, where the positive changes are exceeded 60%.

Conclusion
In this paper, we proposed a novel end-to-end model ASAC for Chinese nested named entity recognition in the medical domain, which can adaptively learn the distinctions and connections between different entities recognition tasks based on sequence labeling. First, we introduce the adaptive shared mechanism to get features of different layers of the BERT-based model to different nested entity category classes. Moreover, by constructing attentive conditional random fields, our model can exploit the encoding features to decode corresponding labels by blending other predictions via the attention mechanism. Extensive experiments conducted on publicly available datasets show the effectiveness of the proposed method. In the future, we will apply this novel model to more different types of datasets to verify validity.