Radiology report generation model loss function weighting method based on clinical entity graph

CN122889223APending Publication Date: 2026-10-09CHENGDU JINFA EDGE INTELLIGENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611021568.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-09
Publication Date
2026-10-09

AI Technical Summary

Technical Problem

[0008]本发明的目的在于克服目前现有损失函数设计所存在的对临床阴性发现缺乏专项学习信号以及多路损失归一化不一致导致梯度冲突的技术缺陷,提供一种基于临床实体图谱的放射报告生成模型损失函数加权方法

Benefits of technology

[0036](1)本发明通过RadGraph实体图谱精确提取OBS_ABS阴性实体及其token位置,在训练中对阴性发现token施以专项额外损失权重,使模型对阴性发现描述产生更强的学习信号,有效改善了现有方法因阴性发现文本频次相对固定、语言模式重复而导致的欠学习问题,提升了生成报告中阴性发现的表述准确性和完整性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122889223A_ABST
    Figure CN122889223A_ABST
Patent Text Reader

Abstract

The application discloses a radiology report generation model loss function weighting method based on a clinical entity graph, comprising the following steps: S1, acquiring a RadGraph clinical entity graph annotation file, extracting entities with an annotation type of OBS_ABS and token strings thereof in each radiology report, and constructing an index file with a sample ID as a key; and S2, in model forward propagation, manually calculating cross-entropy loss of each target token position in a reduction=none mode, and obtaining a per-token loss tensor with a shape of [batch_size, seq_len]. The application can effectively improve the under-learning problem caused by relatively fixed negative finding text frequency and repeated language patterns in the prior art, and can improve the expression accuracy and integrity of negative findings in the generated report.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the interdisciplinary field of medical image analysis and natural language processing, specifically to a weighted loss function method for a radiology report generation model based on clinical entity maps. Background Technology

[0002] Radiology Report Generation (RRG) is an important research direction in the field of medical artificial intelligence. Its goal is to automatically generate radiological diagnostic reports with structured clinical semantics based on medical images such as chest X-rays. Radiologists need to read a large number of images and write reports every day. AI-powered automatic generation systems can effectively alleviate the manpower pressure on radiology departments and, to some extent, assist doctors in reducing missed diagnoses and misdiagnoses.

[0003] In recent years, multimodal generation frameworks based on large language models have made significant progress in radiology report generation tasks. Among them, representative frameworks such as LLM-RG4 have effectively improved the coherence, accuracy, and clinical credibility of report generation by incorporating sentence quality scores to weight the training loss.

[0004] However, existing methods still have the following problems in loss function design:

[0005] First, there is a lack of specific learning signals for clinical negative findings. Negative findings refer to statements in reports that explicitly describe the "definite absence" of a particular anatomical location or clinical symptom (such as "no pneumothorax" or "no pleural effusion"), which are entities labeled as OBS_ABS in the RadGraph entity atlas. Negative findings have significant value in clinical exclusionary diagnoses, but current methods apply the same weight to all tokens, failing to provide a stronger learning signal for them, leading to underlearning of such expressions by the model.

[0006] Second, inconsistent normalization of multi-path losses leads to gradient conflicts. Existing methods use a weighted sum of two-path losses with different normalization denominators, resulting in uncontrollable relative proportions of gradient weights between different tokens, causing gradient interference and affecting training stability.

[0007] In summary, existing loss function designs still suffer from technical shortcomings such as a lack of specific learning signals for clinical negative findings and gradient conflicts caused by inconsistent normalization of multi-path losses. There is an urgent need for a loss function weighting method that can effectively overcome these shortcomings to meet the pressing clinical needs. Summary of the Invention

[0008] The purpose of this invention is to overcome the technical defects of existing loss function designs, such as the lack of specific learning signals for clinical negative findings and gradient conflicts caused by inconsistent normalization of multi-path losses, and to provide a weighted method for loss function in radiology report generation models based on clinical entity maps.

[0009] To achieve the above objectives, the present invention employs the following technical solution: a weighted method for the loss function of a radiology report generation model based on clinical entity atlas, characterized by comprising the following steps:

[0010] S1: Obtain the RadGraph clinical entity atlas annotation file, extract the entities with annotation type OBS_ABS and their token strings from each radiology report, and construct an index file with the sample ID as the key;

[0011] S2: During the forward propagation of the model, the cross-entropy loss at each target token position is manually calculated with reduction=none to obtain a per-token loss tensor of shape [batch_size, seq_len].

[0012] S3: Perform precise subsequence matching on the OBS_ABS entity token list of each sample in the target token sequence, increase the loss weight at the matching position from the base value of 1.0 to the preset entity loss weight entity_loss_weight, and construct an entity-level weight mask of shape [batch_size, seq_len].

[0013] S4: Combine the constructed entity-level weight mask with the sentence quality score weights using element-wise addition to form a unified weight coefficient combined_weight;

[0014] S5: Mark the position of the valid target token with valid_mask, and calculate the weighted loss as the sole optimization objective for model training.

[0015] Step S1, "extracting entities and their token strings labeled as OBS_ABS from each radiology report," includes the following steps:

[0016] S11: Read the RadGraph labeled JSON file, iterate through the entities field of each sample, and sort all entities in ascending order by start_ix;

[0017] S12: Map entity labels, marking Observation::definitely present as OBS_PRE, Observation::definitely absent as OBS_ABS, Observation::uncertain as OBS_UNC, and Anatomy::definitely present as ANAT;

[0018] S13: Extract linearized entity description string information, entity_tokens information of all entities, and obs_abs_tokens information of OBS_ABS type entity token list for each sample;

[0019] S14: Using the sample ID as the key, store the three types of information extracted in the previous step into a compact index file for quick querying by sample ID during training.

[0020] Step S3, "performing precise subsequence matching of the OBS_ABS entity token list for each sample in the target token sequence," specifically includes the following steps:

[0021] S31: Initialize the entity-level weight mask obs_abs_weight as a tensor of all 1s with shape [batch_size, seq_len];

[0022] S32: For each sample in the batch, split the obs_abs_tokens field by the delimiter to obtain the list of negative entity token strings corresponding to that sample;

[0023] S33: For each negative entity token string, use a language model tokenizer to encode it into a token ID sequence entity_ids;

[0024] S34: In the target token sequence to_regress_tokens.input_ids[b] of this sample, the entity_ids subsequence is precisely matched by traversing through a sliding window to locate all matching start positions i;

[0025] S35: Calculate the offset position in the complete sequence based on the matching position, and set the weight of the corresponding position in obs_abs_weight to entity_loss_weight.

[0026] Furthermore, step S4, which involves "combining the entity-level weight mask and the sentence quality score weights into a unified weight coefficient combined_weight using element-wise addition," specifically includes the following steps:

[0027] S41: Obtain the sentence quality score vector from the scores field of the data sample, align it with zero_padding, concatenate them, and perform a shift operation to obtain shift_scores_2d;

[0028] S42: Perform additive fusion: combined_weight = obs_abs_weight + sentence_ratio ×shift_scores_2d;

[0029] S43: For OBS_ABS negative entity tokens, combined_weight = entity_loss_weight + sentence_ratio × score, achieving dual enhancement at both the entity and sentence levels; for ordinary tokens, combined_weight = 1.0 + sentence_ratio × score, only affected by sentence quality weights.

[0030] Step S5, which involves "marking the positions of valid target tokens with valid_mask and calculating the weighted loss as the sole optimization objective for model training," specifically includes the following steps:

[0031] S51: Construct a valid token mask: valid_mask = (shift_labels!=-100).float(), where the valid target token position is 1.0, and the padding and image prefix positions are 0.0;

[0032] S52: Calculate the total loss: total_loss = (per_token_loss × combined_weight × valid_mask).sum() / (valid_mask.sum() + 0.001). All valid tokens share a unique normalized denominator valid_mask.sum(), and the effective gradient weight of each token is uniquely determined, eliminating gradient conflicts caused by inconsistent normalization of multiple tokens.

[0033] Preferably, the default value of "entity_loss_weight" in step S3 is 2.0, which is configured through command-line parameters.

[0034] Preferably, the scaling factor `sentence_ratio` for the "sentence quality score weight" in step S4 is configured via command-line parameters. When `sentence_ratio=0`, only entity-level weighting is retained; when `entity_loss_weight=1.0`, only sentence quality weighting is retained.

[0035] Compared with the prior art, the beneficial effects of the present invention are:

[0036] (1) This invention accurately extracts the negative entities and their token positions of OBS_ABS through RadGraph entity graph. During training, a special additional loss weight is applied to the negative discovery token, which enables the model to generate a stronger learning signal for the description of negative discovery. This effectively improves the underlearning problem caused by the relatively fixed frequency of negative discovery text and the repetition of language patterns in existing methods, and improves the accuracy and completeness of the description of negative discovery in the generated report.

[0037] (2) The present invention adopts a unified normalized single-item loss design, using valid_mask.sum() as the only normalized denominator to calculate the weighted loss. All valid tokens share the same normalized denominator, which eliminates the gradient conflict caused by the use of different normalized denominators (N and M, M≠N) for average_loss and key_loss in the existing LLM-RG4 framework, making the training process more stable and the convergence smoother.

[0038] (3) This invention fuses entity-level weight masks and sentence quality score weights element-wise, thereby simultaneously enhancing OBS_ABS negative entity tokens with both entity-level and sentence quality-level increments, while ordinary tokens are only affected by sentence quality weights. The two signals are independently superimposed and do not interfere with each other, avoiding the problem of one signal being suppressed by the other signal in multiplication fusion.

[0039] (4) This invention supports flexible ablation experiment configuration through command line parameters. It can not only turn off sentence quality weights and retain only entity-level weights, or turn off entity weights and retain only sentence quality weights, or degenerate to the standard mean CE baseline, but also accurately verify the independent contribution of each module. It is applicable to other natural language processing tasks that require special learning signal reinforcement for specific types of text entities. Attached Figure Description

[0040] Figure 1 This is a schematic diagram of the overall process of the present invention. Detailed Implementation

[0041] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0042] Example

[0043] like Figure 1 As shown, the weighted loss function method for the radiology report generation model based on clinical entity atlas in this embodiment includes the following steps:

[0044] S1: Obtain the RadGraph clinical entity atlas annotation file, extract the entities with annotation type OBS_ABS and their token strings from each radiology report, and construct an index file with the sample ID as the key.

[0045] This step involves RadGraph data preprocessing and negative entity extraction, providing a data foundation for accurately locating OBS_ABS entity positions and applying specific loss weights during training.

[0046] The extraction of entities and their token strings labeled as OBS_ABS from each radiology report includes the following steps:

[0047] S11: Read the RadGraph labeled JSON file, iterate through the entities field of each sample, and sort all entities in ascending order by start_ix. Specifically, reading the RadGraph labeled JSON file involves first running the preprocess_radgraph.py script, taking the RadGraph labeled JSON file (containing entity graph annotations for the training and validation sets) as input; then iterating through the entities field of each sample. Each entity record includes tokens (entity text), label (entity category label), start_ix and end_ix (the start and end positions of the tokens in the report), and relations (relationship list) fields; finally, sorting all entities of the current sample in ascending order by start_ix to ensure the linearization order matches the report text order.

[0048] S12: Map entity labels, marking Observation::definitely present as OBS_PRE, Observation::definitely absent as OBS_ABS, Observation::uncertain as OBS_UNC, and Anatomy::definitely present as ANAT.

[0049] This step defines the LABEL_MAP label mapping rules, marking the RadGraph original label Observation::definitely absent as the short identifier OBS_ABS (identifying non-existent clinical observations, i.e., negative findings entities), the RadGraph original label Observation::definitely present as the short identifier OBS_PRE (identifying present clinical observations), the RadGraph original label Observation::uncertain as the short identifier OBS_UNC (uncertain clinical observations), and the RadGraph original label Anatomy::definitelypresent as the short identifier ANAT (identifying present anatomical structures).

[0050] The OBS_ABS type corresponds to explicit negative clinical statements in radiological reports, such as "no pneumothorax," "no pleural effusion," and "no cardiomegaly," and has important exclusionary value in clinical diagnosis.

[0051] S13: Extract the linearized entity description string (linearized), the entity token list (entity_tokens), and the OBS_ABS type entity token list (obs_abs_tokens) for each sample.

[0052] This step involves the extraction and storage of three types of information: for each sample, the following three types of information are extracted:

[0053] The first type of information is linearized entity description strings. Its format is "[tag]entity text[relationship]target entity...", which concatenates all entities and their relationships into a readable clinical summary string.

[0054] The second type of information: a list of all entity tokens (entity_tokens). This type of information contains text strings for all entities in the current sample.

[0055] The third type of information: The obs_abs_tokens list of negative entity tokens (OBS_ABS). This type of information only contains a list of text strings for entities labeled OBS_ABS.

[0056] S14: Using the sample ID as the key, store the three types of information extracted in the previous step into a compact index file for quick querying by sample ID during training.

[0057] This step involves organizing the linearized entity description string (linearized information), the entity token list (entity_tokens information), and the OBS_ABS negative entity token list (obs_abs_tokens information) extracted from the above steps into a dictionary using the training sample ID as the key, and then serializing and storing this information in the rg_compact_sn.json index file.

[0058] Specifically, the RadGraphIndex class is defined, and during initialization, the entire rg_compact_sn.json file is loaded into the memory dictionary self._index. A get(sample_id) method is provided: This method queries based on the sample ID; if the sample exists, it returns a triple (linearized, entity_tokens, obs_abs_tokens); otherwise, it returns (None, None, []) to support compatibility with unlabeled samples. During the data loading phase, data_helper_sn.py calls rg_index.get(features["id"]) when constructing each training sample. The obs_abs_tokens list is concatenated with a vertical bar "|" to form a string (e.g., "no pneumothorax|no pleural effusion"), which is then written into the sample dictionary and packaged into a batch with the DataLoader and passed to the model's forward() function.

[0059] S2: During the forward propagation of the model, the cross-entropy loss at each target token position is manually calculated with reduction=none to obtain a per-token loss tensor of shape [batch_size, seq_len].

[0060] This step changes the conventional automatic aggregation (mean or summation) of loss functions to independent calculation per token, retaining the independent cross-entropy loss value for each target token position, forming a token-by-token loss tensor. This provides a token-by-token level fine-grained operational basis for subsequently applying specific additional weights to OBS_ABS negative entity tokens, allowing tokens at different positions to have independent loss weights, and realizing differentiated learning signal enhancement for negative discovery tokens.

[0061] The manual calculation of the cross-entropy loss for each target token position specifically includes the following steps:

[0062] S21. Loss function initialization. In the forward() function of LLM_RG4.py, loss_fct =CrossEntropyLoss(reduction="none") is defined. Unlike the automatic aggregation loss using reduction="mean" in the original framework, reduction="none" returns the per-token loss value of the same length as the input sequence, providing a basis for subsequent fine-grained weighting.

[0063] S22. Sequence shifting operation. Since the language model training adopts the teacher forcing next token prediction paradigm, shift_logits = logits[..., :-1, :].contiguous() is executed on the predicted logits (removing the prediction of the last token), and shift_labels = labels[..., 1:].contiguous() is executed on the labels (removing the label of the first token), so that logits[t] and labels[t+1] are aligned, that is, the token of the next position is predicted at the current position.

[0064] S23. Per-token loss calculation and reshaping. Call `per_token_loss_flat = loss_fct(shift_logits.view(-1, vocab_size), shift_labels.view(-1))` to obtain a one-dimensional loss vector of shape [batch_size × seq_len]. Then reshape it to `per_token_loss = per_token_loss_flat.view(batch_size, -1)` to obtain a per-token loss matrix of shape [batch_size, seq_len]. The labels at the padding positions and the image token prefix positions are usually set to -100, which CrossEntropyLoss automatically treats as 0 loss.

[0065] S3: Perform precise subsequence matching on the OBS_ABS entity token list of each sample in the target token sequence, increase the loss weight at the matching position from the base value of 1.0 to the preset entity loss weight entity_loss_weight, and construct an entity-level weight mask with shape [batch_size, seq_len].

[0066] This step involves accurately locating the OBS_ABS entity token position during training and assigning it a higher loss weight through a weight mask, enabling the model to generate a stronger specific learning signal for negative detection. Specifically, this involves performing precise subsequence matching on the OBS_ABS entity token list for each sample within the target token sequence, which includes the following steps:

[0067] S31: Initialize the entity-level weight mask `obs_abs_weight` as a tensor of all 1s with shape `[batch_size, seq_len]`. Initialize `obs_abs_weight = torch.ones(batch_size, seq_len)`, with all position weights set to 1.0, serving as the base weight values ​​for non-negative entity positions. This initial value is designed so that the minimum `combined_weight` after additive fusion is no less than 1.0, ensuring that all tokens contribute at least as much as the standard loss during training.

[0068] S32: For each sample in the batch, split the obs_abs_tokens field by the delimiter to obtain the list of negative entity token strings corresponding to that sample.

[0069] This step involves parsing the OBS_ABS entity token string. Specifically, for each sample b in the batch (b = 0, 1, ..., batch_size-1), the string "obs_abs_tokens" is retrieved from the sample dictionary and split into a list of entity texts using the vertical bar "|". If a sample has no corresponding RadGraph label (obs_abs_tokens is an empty string), it is skipped, and the weight mask remains all 1s.

[0070] S33: For each negative entity token string, use a language model tokenizer to encode it into a token ID sequence entity_ids.

[0071] This step involves entity token encoding. For each negative entity text string (entity_text), `tokenizer.encode(entity_text, add_special_tokens=False)` is called to encode it into a list of token IDs (entity_ids). No special tokens (such as [CLS], [SEP]) are added to ensure that the matched token sequence is plain text content.

[0072] S34: In the target token sequence to_regress_tokens.input_ids[b] of this sample, the entity_ids subsequence is precisely matched by traversing through a sliding window to locate all matching starting positions i.

[0073] This step involves precise subsequence matching within a sliding window. Specifically, the target token sequence `target_ids = to_regress_tokens.input_ids[b].tolist()` is obtained, with a length of `seq_len`. The sliding window length is defined as `L = len(entity_ids)`. Starting from position `i = 0`, the window iterates to `i = seq_len - L`, comparing `target_ids[i:i+L]` with `entity_ids` position by position. If a complete match is found, the starting position `i` is recorded. Precise subsequence matching, rather than approximate matching, is used here to ensure that weights are applied only to the complete entity token sequence, avoiding mislabeling caused by partial matching.

[0074] S35: Calculate the offset position in the complete sequence based on the matching position, and set the weight of the corresponding position in obs_abs_weight to entity_loss_weight.

[0075] This step is the weight mask update. For each matching start position i, the offset position in the complete sequence (including the image embedding prefix) is calculated as shift_pos = img_len + i - 1 (where img_len is the sequence length occupied by the image token prefix). Then, obs_abs_weight[b, shift_pos : shift_pos + L] = entity_loss_weight is executed to update the weights at the corresponding positions to entity_loss_weight. If the same entity appears multiple times in the report for a single sample, each appearance participates in the weight update.

[0076] As the optimal approach, the entity loss weight (entity_loss_weight) is set to a default value of 2.0, which is configured via the command-line parameter --entity_loss_weight.

[0077] S4: Combine the constructed entity-level weight mask with the sentence quality score weights using element-wise addition to form a unified weight coefficient, combined_weight.

[0078] This step involves merging the entity-level weight mask and the sentence quality score weight at the element-wise level, so that the final weight coefficients simultaneously integrate the negative entity-specific learning signal and the overall sentence quality signal, thereby achieving a unified expression of dual-granularity knowledge. This is then applied to each token in the subsequent loss calculation, maintaining the independent adjustability of the two signals.

[0079] The step of merging the entity-level weight mask and the sentence quality score weight into a unified weight coefficient combined_weight by element-wise addition includes the following steps:

[0080] S41: Obtain the sentence quality score vector from the scores field of the data samples, align it with zero-padding, concatenate them, and perform a shift operation to obtain shift_scores_2d. This step constructs the sentence quality score tensor, that is, obtain the sentence quality score vector scores of each sample from the samples field of the batch. This vector is calculated by RadCliQ, BERTScore, and other metrics during the training data preprocessing stage. Each element corresponds to the comprehensive quality score of a sentence in the report, and the value range is usually [0, 1]. Since the number of sentences in different samples is different, zero-padding is applied to the scores vector of each sample to align it to the maximum number of sentences in the batch. Then, it is expanded into a per-token score vector of the same length as the token sequence according to the token position, and a shift operation is performed: shift_scores_2d = scores[..., 1:].contiguous(), maintaining the same sequence shift alignment as shift_labels.

[0081] S42: Perform additive fusion: combined_weight = obs_abs_weight + sentence_ratio ×shift_scores_2d.

[0082] This step involves additive fusion, specifically fusing the entity-level weight mask with the sentence quality score weights: `combined_weight = obs_abs_weight + sentence_ratio × shift_scores_2d`. Here, `sentence_ratio` is the scaling factor for the sentence quality score weights, configured via the command-line parameter (the default value is adjusted based on experiments). When `sentence_ratio=0`, only entity-level weights are retained; when `entity_loss_weight=1.0`, only sentence quality weights are retained. The mathematical essence of additive fusion is to sum the weight increments from both sources: entity-level increment = obs_abs_weight - 1.0 (only non-zero values ​​at OBS_ABS entity positions), sentence quality increment = `sentence_ratio × shift_scores_2d` (all non-zero values ​​at positions with sentence scores).

[0083] S43: For OBS_ABS negative entity tokens, combined_weight = entity_loss_weight + sentence_ratio × score, achieving dual enhancement at both the entity and sentence levels; for ordinary tokens, combined_weight = 1.0 + sentence_ratio × score, only affected by sentence quality weights.

[0084] This step analyzes the advantages of additive fusion. Compared to multiplicative fusion (combined_weight = obs_abs_weight × shift_scores_2d), additive fusion has the following advantages: 1) Signal independence: The two increments are added independently, and the entity-level signal is not suppressed due to a low sentence quality score, and vice versa; there is no mutual masking effect; 2) Gradient interpretability: For any token, loss / Combined_weight = per_token_loss, the contributions of the two weights to the gradient are directly added together, with no overlapping terms, which is convenient for analysis; 3) Ablation experiment friendly: a signal can be turned off independently by setting entity_loss_weight=1.0 or sentence_ratio=0 to achieve precise control of variable experiments.

[0085] S5: Mark the position of the valid target token with valid_mask, and calculate the weighted loss as the sole optimization objective for model training.

[0086] This step involves constructing an effective token mask to filter out the locations of real text tokens that need to participate in training. A single normalized denominator is used to calculate the weighted loss as the sole optimization objective, ensuring that the gradient weight of each token during backpropagation is uniquely determined by the combined_weight. This eliminates gradient conflicts caused by inconsistent normalized denominators in existing methods, while also enabling refined weighted training of effective tokens, ultimately improving the stability and convergence of model training.

[0087] The valid target token position is marked with valid_mask, and the weighted loss is calculated as the sole optimization objective for model training. The specific steps include:

[0088] S51: Construct a valid token mask: valid_mask = (shift_labels!=-100).float(), with the valid target token position set to 1.0 and the padding and image prefix positions set to 0.0.

[0089] This step constructs a valid token mask. The function `valid_mask = (shift_labels != -100).float()` is executed, marking positions with label values ​​other than -100 (i.e., non-padding, non-image prefix) as 1.0, and all other positions as 0.0. This mask ensures that only the true target token participates in the loss calculation; image embedding placeholder tokens and padding tokens do not generate gradients.

[0090] S52: Calculate the total loss: total_loss = (per_token_loss × combined_weight × valid_mask).sum() / (valid_mask.sum() + 0.001). All valid tokens share a unique normalized denominator valid_mask.sum(), and the effective gradient weight of each token is uniquely determined, eliminating gradient conflicts caused by inconsistent normalization of multiple tokens.

[0091] This step is for calculating the unified normalized loss. It executes: `total_loss = (per_token_loss × combined_weight × valid_mask).sum() / (valid_mask.sum() + 0.001)`. The numerator is the sum of the weighted losses of all valid tokens, and the denominator `valid_mask.sum()` is the total number of valid tokens in the current batch, with a small increment of 0.001 to prevent division by zero in extreme cases. All valid tokens share a unique normalized denominator `valid_mask.sum()`. The actual gradient contribution ratio of each valid token is `combined_weight_i / valid_mask.sum()`, entirely determined by `combined_weight` and unaffected by the distribution of other tokens within the batch, thus achieving precise control of the gradient weights.

[0092] After completing the above, this embodiment can also add a gradient conflict comparison analysis with the original LLM-RG4 framework. In the original LLM-RG4 framework, if the number of valid tokens in a batch is N=500, the number of keyword tokens is M=200, and λ=0.5, then the gradient coefficient of a regular token is 1 / 500=0.002, and the gradient coefficient of a keyword token is 1 / 500 + 0.5×score / 200. The two calculation paths are mixed, and the relative gradient weights cannot be precisely controlled. However, in the method of this invention, if entity_loss_weight=2.0 and sentence_ratio=0.5, the gradient coefficient of an OBS_ABS keyword token is (2.0 + 0.5×score) / 500, and the gradient coefficient of a regular token is (1.0 + 0.5×score) / 500. Both use the same denominator of 500, and the gradient weight ratio is completely determined by combined_weight, perfectly matching the design intent and actual calculation.

[0093] Correspondingly, the ablation experiment configuration support can also be increased. Specifically, this embodiment also supports the following ablation configurations to facilitate control experiments: Configuration A (Complete Method): use_radgraph=True, entity_loss_weight=2.0, sentence_ratio=0.5, loss_mode="weighted"; Configuration B (No Entity Weighting): use_radgraph=False, sentence_ratio=0.5, loss_mode="weighted"; Only sentence quality weighting is retained to verify the independent contribution of OBS_ABS entity weighting; Configuration C (No Sentence Quality Weighting): use_radgraph=True, entity_loss_weight=2.0, sentence_ratio=0, loss_mode="weighted"; Only entity weighting is retained to verify the independent contribution of sentence quality weights; Configuration D (Standard CE Baseline): loss_mode=None; Degenerates to standard mean CE loss for overall comparison with the method of this invention.

[0094] The methods described in steps 1 to 5 above are specifically implemented within the OBSRRG radiology report generation framework. Using the Dinov2Model visual language large-scale model as the backbone, the method is trained and evaluated on two standard radiology report generation benchmark datasets: IU-Xray and MIMIC-CXR. Experimental results show that, compared to the standard CE baseline without any loss weighting, the method of this invention significantly improves clinical report quality metrics such as BLEU-4, ROUGE-L, BERTScore, and RadGraph F1. The improvement in F1 score is particularly pronounced in report sentences involving negative findings, validating the effect of OBS_ABS entity weighting on improving the quality of negative findings generation. Compared to the dual-loss scheme of the original LLM-RG4 framework, the unified normalization design of this invention makes the training loss curve smoother, reducing loss oscillations during training and validating the positive impact of eliminating gradient conflicts on training stability.

[0095] As described above, the present invention can be well implemented.

Claims

1. A weighted loss function method for a radiology report generation model based on clinical entity atlas, characterized in that, Includes the following steps: S1: Obtain the RadGraph clinical entity atlas annotation file, extract the entities with annotation type OBS_ABS and their token strings from each radiology report, and construct an index file with the sample ID as the key; S2: During the forward propagation of the model, the cross-entropy loss at each target token position is manually calculated with reduction=none to obtain a per-token loss tensor of shape [batch_size, seq_len]. S3: Perform precise subsequence matching on the OBS_ABS entity token list of each sample in the target token sequence, increase the loss weight at the matching position from the base value of 1.0 to the preset entity loss weight entity_loss_weight, and construct an entity-level weight mask of shape [batch_size, seq_len]. S4: Combine the constructed entity-level weight mask with the sentence quality score weights using element-wise addition to form a unified weight coefficient combined_weight; S5: Mark the position of the valid target token with valid_mask, and calculate the weighted loss as the sole optimization objective for model training.

2. The weighted loss function method for a radiology report generation model based on clinical entity atlas according to claim 1, characterized in that, Step S1, "extracting entities and their token strings labeled as OBS_ABS from each radiology report," includes the following steps: S11: Read the RadGraph labeled JSON file, iterate through the entities field of each sample, and sort all entities in ascending order by start_ix; S12: Map entity labels, marking Observation::definitely present as OBS_PRE, Observation::definitely absent as OBS_ABS, Observation::uncertain as OBS_UNC, and Anatomy::definitely present as ANAT; S13: Extract linearized entity description string information, entity_tokens information of all entities, and obs_abs_tokens information of OBS_ABS type entity token list for each sample; S14: Using the sample ID as the key, store the three types of information extracted in the previous step into a compact index file for quick querying by sample ID during training.

3. The weighted loss function method for a radiology report generation model based on clinical entity atlas according to claim 1, characterized in that, Step S3, "performing precise subsequence matching of the OBS_ABS entity token list for each sample in the target token sequence," specifically includes the following steps: S31: Initialize the entity-level weight mask obs_abs_weight as a tensor of all 1s with shape [batch_size, seq_len]; S32: For each sample in the batch, split the obs_abs_tokens field by the delimiter to obtain the list of negative entity token strings corresponding to that sample; S33: For each negative entity token string, use a language model tokenizer to encode it into a token ID sequence entity_ids; S34: In the target token sequence to_regress_tokens.input_ids[b] of this sample, the entity_ids subsequence is precisely matched by traversing through a sliding window to locate all matching start positions i; S35: Calculate the offset position in the complete sequence based on the matching position, and set the weight of the corresponding position in obs_abs_weight to entity_loss_weight.

4. The weighted loss function method for a radiology report generation model based on clinical entity atlas according to claim 1, characterized in that, Step S4, which involves "combining the entity-level weight mask and the sentence quality score weights into a unified weight coefficient combined_weight using element-wise addition," specifically includes the following steps: S41: Obtain the sentence quality score vector from the scores field of the data sample, align it with zero_padding, concatenate them, and perform a shift operation to obtain shift_scores_2d; S42: Perform additive fusion: combined_weight = obs_abs_weight + sentence_ratio ×shift_scores_2d; S43: For OBS_ABS negative entity tokens, combined_weight = entity_loss_weight + sentence_ratio × score, achieving dual enhancement at both the entity and sentence levels; for ordinary tokens, combined_weight = 1.0 + sentence_ratio × score, only affected by sentence quality weights.

5. The weighted loss function method for a radiology report generation model based on clinical entity atlas according to claim 1, characterized in that, Step S5, which involves "marking the positions of valid target tokens with valid_mask and calculating the weighted loss as the sole optimization objective for model training," specifically includes the following steps: S51: Construct a valid token mask: valid_mask = (shift_labels!=-100).float(), where the valid target token position is 1.0, and the padding and image prefix positions are 0.0; S52: Calculate the total loss: total_loss = (per_token_loss × combined_weight × valid_mask).sum() / (valid_mask.sum() + 0.001). All valid tokens share a unique normalized denominator valid_mask.sum(), and the effective gradient weight of each token is uniquely determined, eliminating gradient conflicts caused by inconsistent normalization of multiple normalizations.

6. The weighted method for loss function in a radiology report generation model based on clinical entity atlas according to claim 3, characterized in that: The default value of "entity_loss_weight" mentioned in step S3 is 2.0, which is configured through command-line parameters.

7. The weighted loss function method for a radiology report generation model based on clinical entity atlas according to claim 4, characterized in that: In step S4, the scaling factor of "sentence quality score weight" is configured through command-line parameters. When sentence_ratio=0, only entity-level weighting is retained, and when entity_loss_weight=1.0, only sentence quality weighting is retained.