{'fraction_non_alphanumeric': 0.042249388753056234, 'fraction_numerical': 0.02, 'mean_word_length': 4.907279029462738, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
AlignTransformer: Hierarchical Alignment of Visual Regions and Disease Tags for Medical Report Generation

Recently, medical report generation, which aims to automatically generate a long and coherent descriptive paragraph of a given medical image, has received growing research interests. Different from the general image captioning tasks, medical report generation is more challenging for data-driven neural models. This is mainly due to 1) the serious data bias: the normal visual regions dominate the dataset over the abnormal visual regions, and 2) the very long sequence. To alleviate above two problems, we propose an AlignTransformer framework, which includes the Align Hierarchical Attention (AHA) and the Multi-Grained Transformer (MGT) modules: 1) AHA module first predicts the disease tags from the input image and then learns the multi-grained visual features by hierarchically aligning the visual regions and disease tags. The acquired disease-grounded visual features can better represent the abnormal regions of the input image, which could alleviate data bias problem; 2) MGT module effectively uses the multi-grained features and Transformer framework to generate the long medical report. The experiments on the public IU-Xray and MIMIC-CXR datasets show that the AlignTransformer can achieve results competitive with state-of-the-art methods on the two datasets. Moreover, the human evaluation conducted by professional radiologists further proves the effectiveness of our approach.


Introduction
Medical images, e.g., radiology and pathology images, as well as their corresponding reports (see Fig. 1) are widely-used for diagnosis [9,12]. In clinical practice, writing a medical report can be time-consuming and tedious for experienced radiologists, and error-prone for inexperienced radiologists [5,29,28]. As a result, automatic medical report generation systems can reduce the workload of radiologists by assisting them in clinical decision-making, and are thus in urgent need [17,22,16,21,42,44,4,38,45,7,29,28,24].

Input Image Ground Truth
The heart is within normal limits in size. Surgical suture material projects over the right lung apex. 1 The lungs are hyperlucent and hyperinflated compatible with emphysema. 2 There is left lower lobe airspace disease identified. 3 There is moderate left pleural eff-usion and small right pleural effu-sion. No visualized pneumothorax.

R2Gen [8]
The heart is normal in size. Lungs are clear. There is no pneumothorax. No acute bony abnormalities.
No airspace disease or significant pleural effusion identified. No evidence of pneumothorax.

AlignTransformer [Ours]
The heart and mediastinum are normal. 1 The lungs are hyperlucent. There is no pneumothorax. 2 There is left lower lobe airspace disease suspicious for pneumonia. 3 There is a moderate left sided pleural effusion.

Aligning Visual Regions and Disease Tags
Cardiomegaly Scoliosis Pleural Effusion Pneumothorax Airspace Disease Hyperlucent Pneumonia Emphysema Fig. 1. An example of ground truth report and reports generated by a state-of-the-art approach R2Gen [7] and our approach. The Red bounding boxes and Red colored text indicate the abnormalities in images and reports, respectively. As we can see, in this example, the R2Gen fails to depict the rare but important abnormalities and generates some error sentences (Blue colored text) and repeated sentences (Purple colored text).
Most existing medical report generation models follow the standard image captioning approaches [41,40,43,1,27,26,25,32,8] and employ the encoder-decoder framework, e.g., a CNN-based image encoder followed by a LSTM-based report decoder. However, directly applying image captioning approaches to medical images has the following problems: 1) Data bias: the normal images dominate the dataset over the abnormal ones [36]. Furthermore, for each abnormal image, the normal regions dominate the image over the abnormal ones [24]. As shown in Fig. 1, abnormal regions (Red bounding boxes) only occupy a small part of the entire image. As a result, existing models tend to generate plausible general reports with no prominent abnormal narratives, failing to depict the rare but important abnormalities [16,22,44]. 2) Very long sequence: Image captioning models are designed to generate one single and short sentence, which only describes the most prominent visual contents, while medical report generation requires to generate a long paragraph, including multiple structural sentences with each one focusing on a specific medical observation. For the widely-used LSTM [14] in image captioning, it is hard to model such long sequences or paragraphs due to vanishing or exploding gradients [34]. Recent medical report generation models [17,16,44] rely on hierarchical LSTM [20], which have similar long sequence modeling problems. As shown in Fig. 1, even a state-of-the-art model R2Gen [7] still generates some repeated sentences of normalities.
To alleviate above problems, we propose the AlignTransformer, which includes two major modules: 1) Align Hierarchical Attention (AHA) works as the encoder to extract visual features. To focus on the abnormal regions, AHA first predicts the disease tags from the input image and then aligns these tags with the corresponding visual regions. To fit for both coarse-and fine-grained visual features, AHA introduces a hierarchically alignment model [25]. In detail, the disease tags are firstly used to find the most relevant visual regions, extracting disease-grounded visual features for each disease tag. Then the extracted visual features are further used to find the most relevant disease tags and filter out the irrelevant disease tags for each visual feature. By conducting the above process at different granularity level, the visual receptive fields gradually concentrate on salient abnormal regions under the guidance of the disease tags. In this way, we can obtain the features of abnormal regions, which can be used to alleviate data bias; 2) Multi-Grained Transformer (MGT) works as the decoder to generate final reports. MGT adaptively exploit coarse-and fine-grained disease-grounded visual features through a learned gating mechanism. In addition, MGT introduces the Transformer [39,8,7,28] to generate the reports. Benefiting from the visual features from multiple granularities and the Transformer, as shown in Fig. 1, our approach are a better fit for long report.
Overall, the contributions of this paper are as follows: -In this paper, we propose the AlignTransformer framework, which aims to alleviate the data bias problem and model the very long sequence for medical report generation. -The experiments on the benchmark IU-Xray [10] and MIMIC-CXR [18] datasets prove the effectiveness of our approach, which achieves results competitive with the existing state-of-the-art methods. We also verify the advantage of AlignTransformer from the manual evaluation of radiologists.

Related Works
The related works are introduced from: 1) Image Captioning and Visual Paragraph Generation and 2) Medical Report Generation. Image Captioning and Visual Paragraph Generation Image captioning [6] aims to understand the given images and generate corresponding descriptive sentences [41,40,1,27,26,25,32,8]. However, the sentence generated by AlignTransformer is usually short and describes the most prominent visual contents, which cannot fully convey the rich feature information of the image. Recently, visual paragraph generation [20], which aims to generate long and coherent reports or stories to describe visual contents, has attracted increasing research interests. To conduct the task, the Hierarchical LSTM structure (HLSTM) [20] is widely-used. However, in paragraph generation for medical images, the correctness of generating abnormalities should be emphasized more than other normalities, while in paragraphs of natural images each sentence has equal importance. Besides, due to the data bias in the medical domain, the widely-used HLSTM in the visual paragraph generation does not perform very well in medical report generation and is tend to produce normal reports [42,22,44,16,29,28,24]. Medical Report Generation Inspired by the success of deep learning models on image captioning, a lot of encoder-decoder based frameworks have been proposed [17,16,44,42,22,45,21,30,7,29,28,24] to automatically generate a fluent medical report. However, due to the data bias and the very long sequence, some errors occur in the generated reports of the existing methods, like duplicate reports, inexact descriptions, etc [42,44,17]. To this end, [16,22,30] and [28,45,21] introduced the reinforcement learning and medical knowledge graph, respectively. [29] introduced the contrastive attention to compare the abnormal image with the normal images to better capture the abnormalities. Meanwhile, [28,7] further introduced the Transformer [39] to model the very long sequence. In our work, different from [28,7], we conduct the alignments between visual regions and disease tags in an iterative manner and propose a multi-grained transformer to combine disease-grounded visual features at different depths.

Approach
We first formulate the problem; Next, we introduce our framework, which includes the Align Hierarchical Attention and Multi-Grained Transformer.

Problem Formulation
Given a medical image encoded as visual features V and disease tags T , the goal of our framework is to generate a coherent report R that describes the observations in details of both normal and abnormal regions. In implementations, for the visual features V , we follow [16,21,22,29,28,24] to adopt the ResNet-50 [13] pretrained on ImageNet [11] and fine-tuned on CheXpert dataset [15] to extract the 2,048 7×7 feature maps, which are further projected into 512 7×7 feature maps, . Moreover, we follow [17] to further predict the disease tags T of the input image. Specifically, we further feed the extracted visual features V into a multi-label classification network, which is pre-trained as multi-label classification task on the downstream datasets to generate a distribution over all of the pre-defined tags. Finally, the embeddings of the N T = 10 most likely tags T = {t 1 , t 2 , . . . , t NT } ∈ R NT×d are used as disease tags of current input image. Based on the extracted V and T , our framework first adopt the AHA to align the visual regions V and disease tags T in a coarse-to-fine manner, acquiring multi-grained disease-grounded visual featuresV . Next, MGT is introduced to generate final report based on theV .
In brief, our AlignTransformer framework is formulated as: Through the above process, our framework gets the ability to alleviate the data bias problem and model the very long sequence.

Align Hierarchical Attention
Basic Module To align the visual regions V and the disease tags T , we adopt the Multi-Head Attention (MHA) from [39], which allows probabilistic many-tomany relations instead of monotonic relations, as in [25,41]. Thus, the MHA can compute the association weights between different features. The MHA consists of n parallel heads and each head is defined as a scaled dot-product attention: where X ∈ R lx×d and Y ∈ R ly×d denote the Query matrix and the Key/Value matrix, respectively; the divisor √ d n (d n = d/n) in Eq. (2) is omitted in equations for conciseness, please see [39] for details; W Q i , W K i , W V i ∈ R d×dn and W O ∈ R d×d are learnable parameters. [·; ·] stands for concatenation operation.
Conventionally, a Fully-Connected Network (FCN) is followed by the MHA:  where max(0, * ) represents the ReLU activation function; W f ∈ R d×4d and W ff ∈ R 4d×d are learnable matrices; b f and b ff are the bias terms. It is worth noting that both the MHA and the FCN are followed by an operation sequence of dropout [37], skip connection [13] and layer normalization (Norm) [2]. Align Attention Since the MHA can compute the association weights between different features, if we apply the MHA between visual regions V and the disease tags T , we can learn the correlation and relationship between V and T , resulting in the alignment between visual regions and disease tags. Therefore, based on the MHA, as shown in Fig. 2, the align attention is conducted as: In implementation, the disease tags T are first used as the Query to find the most relevant visual regions in V , generating the disease related visual features V . Then the V are further used as the Query to find the most relevant disease tags and filter out the irrelevant disease tags in T . As a result, we can obtain alignment between visual regions and disease tags via above processes. Finally, since V and T are aligned, we can add them up to get the disease-grounded visual featuresV that exploits the best of their respective advantages: where the LayerNorm denotes the layer normalization [2]. In particular, since T contains the disease tags, the disease-grounded visual featuresV can be referred as the features of abnormal regions, which are useful in alleviating data bias. Full Model To improve the performance and acquire the multi-grained diseasegrounded visual features, we propose to perform Align Attention hierarchically, which we call Align Hierarchical Attention. Specifically, the process in Eq. (5) that uses the original features is considered as the first round: where V 0 = V , T 0 = T , V 1 and T 1 denote original visual features, original disease tags, aligned visual features, and aligned disease tags, respectively. By repeating the same process for N times, we obtain the final outputs of the two stacks: In this way, we obtain the multi-grained disease-grounded visual features

Multi-Grained Transformer
We propose the Multi-Grained Transformer (MGT), which includes L = 3 decoder layers, to exploit the {V i } and generate a proper report R. In implementations, for generating each word y t , given the embedding of current input word x (0) t = w t + e t (w t : word embedding, and e t : fixed position embedding). For the l th decoder layer, it takes x Then, inspired by [8], we introduce the Adaptive Exploiting Attention (AEA) module to adaptively exploit multi-grained disease-grounded visual features: where W i ∈ R 2d×d is a learnable parameter and b i is a learnable bias vector. , σ and [·; ·] denote the element-wise multiplication, the sigmoid function and the concatenation, respectively. The computed {λ i } weights the expected importance of different grained disease-grounded visual features for each target word. Then, we adopt the FCN to acquire the output of l th decoder layer: x t ) It is worth noting that both the MHA, the AEA and the FCN are followed by an operation sequence of dropout [37], skip connection [13] and memory-driven conditional layer normalization (MCLN) [7].
Finally, the output of last decoder layer x (L) t is used to predict the next word: y t ∼ p t = softmax(x (L) t W p + b p ), where the W p and b p are the learnable parameters. Given the ground truth report R * = {y * 1 , y * 2 , . . . , y * NR } provided by the radiologists, we can train our AlignTransformer framework by minimizing the widely-used cross-entropy loss:

Experiments
Datasets, Metrics and Settings In our work, we conduct experiments on two public datasets, i.e., a widely-used benchmark IU-Xray [10] and a recently released large-scale MIMIC-CXR [18]. IU-Xray is widely-used to evaluate the performance of medical report generation methods. It contains 7,470 chest X-ray images associated with 3,955 reports. Following previous works [7,16,21,22,29,28,24], Table 1. Results of our AlignTransformer and existing models on the MIMIC-CXR and IU-Xray datasets. Hit represents the human evaluation results and is measured by the pick-up percentages (%). The differences between their sum and 100% represent the percentage of ties. Higher value denotes better performance in all columns.

Datasets Methods
Year we randomly split the dataset into 70%-10%-20% training-validation-testing splits. MIMIC-CXR is the recently released largest dataset to date and consists of 377,110 chest X-ray images and 227,835 reports from 64,588 patients. Following [7,29,28,24], we use the official splits to report our results, resulting in 368,960 in the training set, 2,991 in the validation set and 5,159 in the test set.
To test the performance, we adopt the widely-used BLEU [33], METEOR [3] and ROUGE-L [23], which are reported by the evaluation toolkit [6]. Since our approach is based on the Transformer [39], we follow the original settings in [39] and set d = 512, n = 8. Based on the average performance on the validation set, both the N and L in our Align Hierarchical Attention and Multi-Grained Transformer, respectively, are set to 3. We use Adam optimizer [19] with a batch size of 16 and a learning rate of 2e-4 within maximum 100 epochs for parameter optimization. We also use momentum of 0.8 and weight decay of 0.999.
Automatic Evaluation Several representative models, including three most recently published state-of-the-art models, i.e., PPKED [28], R2Gen [7] and SentSAT + KG [45], are selected for comparison. The results on the test of two datasets are shown in Table 1. As we can see, our AlignTransformer achieves the competitive results with the previous state-of-the-art models on the two datasets under all metrics, which verify the effectiveness of our approach.
Human Evaluation Moreover, we invite two professional radiologists to evaluate the perceptual quality of 200 randomly selected reports generated by our AlignTransformer and the R2Gen [7]. The radiologists are unaware of which model generates these reports and are encouraged to select a more accurate report for each pair. The results of last column in Table 1 show that our approach is better than R2Gen in clinical practice with winning pick-up percentages.
Overall, the results verify that our proposed framework can generate accurate and proper reports, which could assist radiologists in making decisions. Table 2. Ablation study of our method, which includes the AHA and the MGT. The N denotes the number of alignments in AHA. The 'Baseline' and 'w/ AHA+MGT' denote the ResNet-50 image encoder [13] equipped with the Transformer report decoder in [7] and our proposed AlignTransformer, respectively.

Analysis
In this section, we conduct analysis on the benchmark IU-Xray dataset [10] from different perspectives to better understand our proposed framework. Ablation Study We investigate the contribution of each component in our approach. Table 2 shows that our AHA can significantly promote the performance over all metrics, with up to 18.8% gain in BLEU-4 (N = 3). This indicates that the disease-grounded visual features extracted by our AHA contain sufficient accurate abnormal information, which is vital in alleviating the data deviation problem and improving the performance of medical report generation. For the MGT, Table 2 shows that the MGT can further boost the performance under all metrics, which demonstrates the effectiveness of our MGT to adaptively exploit the multi-grained disease-grounded visual features. Visualization and Example In Fig. 1, we give the visualization of the AHA and an intuitive example to better understand our approach. As we can see, for the current state-of-the-art model R2Gen [7], it produces some inexact descriptions and repeated sentences of normalities, which is due to the overwhelming normal images in the dataset, i.e., data deviation [36,16,28,24]. Since our AHA can efficiently capture the abnormal regions by aligning visual regions and disease tags, we can generate more accurate report for the abnormal regions. For example, the generated report correctly describes "The lungs are hyperlucent", "There is left lower lobe airspace disease suspicious for pneumonia" and "There is a moderate left sided pleural effusion".

Conclusions
In this paper, we propose an AlignTransformer to alleviate the data bias problem and model the very long sequence for medical report generation. The experiments prove the effectiveness of our method, which not only generates meaningful medical reports with accurate abnormal descriptions and regions, but also achieves competitive results with state-of-the-art models on two public datasets with the best human preference. The results justify the usefulness of our framework in assisting radiologists in clinical decision-making, reducing their workload.