Retrieval-Augmented Code Review Generation
Retrieval-Augmented Code Review Generation
Generation
Hyunsun Hong Jongmoon Baik
School of Computing School of Computing
KAIST KAIST
Daejeon, Republic of Korea Daejeon, Republic of Korea
[Link]@[Link] jbaik@[Link]
Abstract—Automated Code review comment generation (RCG) review-related activities, including reading, understanding, and
arXiv:2506.11591v1 [[Link]] 13 Jun 2025
aims to assist developers by automatically producing natural providing feedback on code changes [4]. Moreover, authors
language feedback for code changes. Existing approaches are often face delays of 15 to 64 hours before receiving review
primarily either generation-based, using pretrained language
models, or information retrieval-based (IR), reusing comments comments, which can hinder development velocity [5]. As
from similar past examples. While generation-based methods software systems grow, the volume of code review requests
leverage code-specific pretraining on large code–natural language increases significantly; for example, Microsoft Bing reportedly
corpora to learn semantic relationships between code and natural conducts approximately 3,000 code reviews per month [6].
language, they often struggle to generate low-frequency but se- These challenges have led researchers to explore automating
mantically important tokens due to their probabilistic nature. In
contrast, IR-based methods excel at recovering such rare tokens the review process. Review Comment Generation (RCG) has
by copying from existing examples but lack flexibility in adapting emerged as a promising approach, aiming to ease the burden of
to new code contexts—for example, when input code contains manual review comment writing by automatically generating
identifiers or structures not found in the retrieval database. To relevant, context-aware feedback for code changes.
bridge the gap between generation-based and IR-based methods, RCG has been researched in two directions: Generation-
this work proposes to leverage retrieval-augmented generation
(RAG) for RCG by conditioning pretrained language models on based RCG and Information-Retrieval (IR)-based RCG.
retrieved code–review exemplars. By providing relevant examples Generation-based RCG utilizes a generative language model.
that illustrate how similar code has been previously reviewed, the With the hypothesis that software exhibits repetitive and pre-
model is better guided to generate accurate review comments. dictable property [7], generation-based RCG takes advantage
Our evaluation on the Tufano et al. benchmark shows that RAG- of probabilistic language models trained on the large code-
based RCG outperforms both generation-based and IR-based
RCG. It achieves up to +1.67% higher exact match and +4.25% review corpus to generate most probable code review words.
higher BLEU scores compared to generation-based RCG. It also Tufano et al. [8], [9] were first to apply pre-trained language
improves the generation of low-frequency ground-truth tokens by model (PLM) to code review automation and Li et al. [10] later
up to 24.01%. We additionally find that performance improves proposed a code review-specific pre-training methodology.
as the number of retrieved exemplars increases. Both studies contributed benchmark datasets that have since
Index Terms—Code Review Automation, Deep Learning, Soft-
ware Quality Assurance, Retrieval-Augmented Generation become foundational for evaluating RCG methodology [9],
[10]. Based on these benchmarks, subsequent works have
focused on adapting advanced natural language processing
I. I NTRODUCTION
(NLP) techniques to enhance generation-based RCG [11]–
Code review is a systematic and collaborative process that [13]. IR-based RCG, on the other hand, utilizes information
involves examining code written by others to assess its quality retrieval. It finds the most probable code reviews from a
and readiness for integration. If a code change is deemed large code review history database and regards these retrieved
unsatisfactory, the reviewer may reject the merge request and exemplars as code reviews for the input code [14]–[16]. Rather
provide feedback in the form of review comments, enabling than generating new text from generative language model,
the author to revise the code accordingly. This process plays a IR-based RCG reuses exemplar mined from a code review
key role in identifying latent issues early in the development history database. It is more efficient than generation-based
cycle, preventing potential defects, and improving maintain- RCG because it does not require any training [14]. Notably,
ability through refactoring [1]. For this reason, code review is CommentFinder [14], an IR-based RCG approach, reports
widely adopted and strongly recommended practice as a core a 32% performance improvement over the generation-based
component of software quality assurance [2]. However, code method proposed by Tufano et al. [9] in RCG. This enhance-
review is inherently labor-intensive and time-consuming, re- ment is achieved with a 49× speedup over the generation-
quiring experienced developers to thoroughly inspect changes based method [9], by leveraging simple Bag-of-Words lexical
and deliver precise, constructive feedback [3]. Studies report similarity to retrieve similar code examples from the training
that developers spend an average of six hours per week on dataset. Although both generation-based RCG and IR-based
produce LFGTs that are absent from the input. Conversely,
IR-based RCG can retrieve LFGTs from similar examples in
the retrieval corpus even when they are not present in the
input code (e.g., “IIRC” or “Java”), but it struggles to capture
identifier tokens that appear in the input but are rare in the
retrieval set. This observation motivates our investigation into
a hybrid approach that integrates both paradigms to leverage
their respective strengths.
To bridge the complementary gap between generation-based
and IR-based RCG, we propose to leverage Retrieval Aug-
mented Generation (RAG) [20] to RCG by augmenting input
code query with top-k most similar code’s review exemplars.
RAG enhances generative language model’s performance on
Fig. 1. A motivating example of generation-based and IR-based code review knowledge-intensive tasks by augmenting input queries with
comment generation. Words in ground truth were underlined. relevant knowledge passages [20]. By incorporating retrieved
exemplars, RAG enables generative language models to access
domain-specific knowledge and refer to LFGTs without requir-
RCG have been studied independently with its own advan- ing additional training [21]. Building on this principle, RAG
tages, their integration has not been explored. However, there has been effectively employed in diverse software engineering
is room for two methods to be integrated harmoniously. tasks, including code summarization [22], code completion
As generative language models innately tend to generate [23], code generation [24], and test case generation [25]. Given
high-frequency words, it has trouble with generating low- that code review requires extensive knowledge of project-
frequency but semantically important tokens—referred to as specific practices—such as coding conventions, review focus
Low-Frequency Ground-Truth Tokens (LFGTs) [17], [18]. areas, and stylistic guidelines [26]—RAG can be beneficial, as
Accurately generating LFGTs is critical for improving the retrieved exemplars help convey this domain-specific knowl-
overall quality and usefulness of generated review comments. edge to the generation model. However, the use of RAG
We hypothesize that incorporating retrieval candidates from for generating review comments has not been explored. To
IR-based RCG can expose the generative model to informative address this gap, we propose RAG-Reviewer: RAG-based
exemplars containing LFGTs, thereby guiding the language RCG framework that integrates IR-based and generation-based
model to generate contextually appropriate LFGTs. approaches.
Figure 1 shows a motivating example. This is an example The RAG-Reviewer framework comprises two primary
result of generation-based RCG (CodeT5 [19]) and IR-based components: a retrieval module and a generation module. The
(CommentFinder [14]) RCG on the Tufano et al.’s benchmark retrieval module retrieves top-k similar review exemplars that
dataset [9]. Given an input code snippet, the generation-based are most similar to the input code snippet from a large his-
approach produces review comments using its parametric torical code review database. The generation module utilizes
knowledge acquired during training. In contrast, the IR-based a PLM to generate a review comments for the input code
method identifies lexically similar code from the training snippet with the retrieved exemplars. Given an input code
dataset and directly reuses the associated review comment for review, the retrieval module first identifies the top-k most
as the output. The generation-based model tends to produce similar code examples and extracts their corresponding review
high-frequency tokens such as “it” (46,654 occurrences in the comments. These retrieved exemplars are then concatenated
training corpus), “should” (26,721), and “return” (142,643), with the input code and passed to the generation module. To
but it fails to generate LFGTs like “Also” (7,476), “IIRC” adapt the generator for this retrieval-augmented input format,
(123), “internal” (1,621), and “Java” (7,016). Although the we fine-tune the language model to produce review comments
model successfully generate “ReadOnlyArray” (1), a token that jointly reflect information from both the input and the
that appears only once in the training corpus, this is primarily retrieved examples. Empirical evaluations demonstrate that
due to its presence in the input code itself, rather than the RAG-Reviewer outperforms both generation-only and IR-only
model’s ability to generalize to rare vocabulary. Conversely, baselines. It achieves consistent improvements in Exact Match
the IR-based method is capable of retrieving review comments and BLEU scores across all PLMs and enhances the generation
that contain LFGTs such as “Also,” “IIRC,” “internal,” and of LFGTs. The key contributions of this work are as follows:
“Java” by leveraging similar examples in the retrieval set. • We propose RAG-Reviewer, a RAG framework for RCG
However, it fails to retrieve identifier-specific tokens like that unifies generation-based and IR-based approaches.
“ReadOnlyArray” when such tokens are rare in the retrieval To the best of our knowledge, this is the first study to
corpus. This example illustrates a complementary gap between apply the RAG paradigm to the RCG task.
generation-based RCG and IR-based RCG. While generation- • We conduct comprehensive experiments across multiple
based RCG can effectively generate LFGTs that are present PLMs, showing that RAG-Reviewer improves generation
in the input code (e.g., “ReadOnlyArray”), it struggles to accuracy, better captures LFGTs, and exhibits perfor-
Fig. 3. An example of code review comment generation
model training and model application. During the training where hi is the vectorized representation of ICi . We use
phase, RAG-Reviewer constructs a retrieval database from the the UniXcoder [29] as dc , because it can effectively pre-
training dataset, comprising code snippets, their corresponding serve code’s semantic and syntactic information. Especially,
review comments, and their encoded vector representations. UniXcoder showed state-of-the-art performance in IR-based
Each code snippet is encoded into a dense vector space to RCG [16]. Based on this, we construct the retrieval database
facilitate similarity computation using Maximum Inner Prod- Dreview as follows:
uct Search (MIPS). The retrieval module then identifies the
Dreview = {(hi , ICi , CRi )|i = 1, . . . , M } (2)
top-k most similar code snippets from this database using the
same encoding mechanism. To prevent data leakage, the top- To find the most similar exemplars corresponding to a given
1 retrieved exemplar—which is identical to the input training input code Cinput , we encode Cinput into hx using dc :
instance—is excluded during training. The generator is fine-
hx = dc (Cinput ) (3)
tuned on these augmented inputs, learning to condition on
both the input code and the retrieved exemplars. During model Note that we used same encoder dc for both Cinput and ICi
application, the same retrieval procedure is applied to obtain because they are both forms of code, making them unimodal.
relevant exemplars for a new input code snippet. Using the same encoder ensures consistency in the dense
vector representation. After encoding, we compute similarity
B. Retrieval Module
score si between Cinput and ICi s using the inner dot product:
The retrieval module is responsible for identifying the
most relevant exemplars from the retrieval database given si = ⟨hx , hi ⟩, ∀i ∈ {1, . . . , M } (4)
an input code snippet. These retrieved exemplars provide where ⟨·, ·⟩ denotes the inner product. Based on the computed
contextual guidance that the generator can leverage to produce similarity scores, we then select the top-k most similar exem-
more accurate and informative review comments. The retrieval plars with respect to the input code:
database is constructed from the training dataset. Formally, the
M
training dataset is defined as a set Treview = {(ICi , CRi )|i = CR = TopK {si }i=1 , Dreview , K = {(IC1 , CR1 ) , . . . , (ICk , CRk )} (5)
1, . . . , M } where ICi denotes the input code snippet, CRi where TopK(S, D, K) returns top-k most similar code re-
represents its corresponding ground-truth review comment and view exemplars based on the similarity score set S, retrieval
M is the total number of training instances. This dataset serves database D and specified value of K. The resulting top-k
as the basis for both retrieval and generator training within the retrieval candidates CR are then used to augment the input
RAG-Reviewer framework. To enable similarity computation in the generation module.
between the input code and the code snippets in the retrieval
database, all input code instances ICi s must be encoded into C. Generation Module
dense vector representations. This vectorization allows for Given the output (Equation 5) of retrieval module, the list
the efficient measurement of semantic similarity—typically of top-k most similar exemplars with respect to the input code,
using cosine similarity—between code snippets. Formally, we we construct the input to the generator by concatenating the
employ an encoder dc : input code sequence X with the retrieved candidates CR :
hi = dc (ICi ), ∀(ICi , CRi ) ∈ Treview (1) X ′ = X ⊕ C1 ⊕ C2 · · · ⊕ Ck , Ci ∈ CR (6)
TABLE I
F REQUENCY DISTRIBUTION OF REVIEW COMMENTS IN T UFANO ET AL .’ S TRAINING DATASET
TABLE II
S TATISTICS OF T UFANO ET AL .’ S DATASET
N
X C. Evaluation Metrics
L(θ) = − log Pθ (yitrue | X ′ , y1:i−1
true
) (10) Following the previous code review comment generation
i=1
work [9]–[11], [14], we evaluate the quality of generated
where θ denotes the trainable parameters of the generator. We review comments using the metric BLEU [31] and Exact
fine-tuned only the generator while keeping the code encoder Match (EM) score. These metrics are widely used in other
dc fixed because training dc would necessitate updating hi automated software engineering work [22]–[24], [30].
BLEU measures the frequency of overlapped n-grams be- tagging and cross pre-training. It is trained on a curated
tween the generated comment and the reference comment dataset of over 10,000 real-world code change and review
using n-gram precision. We use BLEU-4, which considers up comment pairs from popular Java projects. AUGER incor-
to 4-gram matches. The BLEU-N score is computed as: porates review-specific tags and demonstrates significant
XN
! improvements in review comment quality.
BLEU-N = BP · exp wn log pn
E. Implementation Details
n=1
where pn is the n-gram precision, wn is the weight for each All experiments were conducted on a NVIDIA Tesla
n-gram (uniformly set to 1/N ), and BP is a brevity penalty V100-SXM2-32GB GPU. For CodeT5, CodeT5+ and
that penalizes overly short generated sequences. Higher BLEU CodeReviewer, we used the AdamW optimizer (learning
scores indicate greater similarity to the ground truth review rate = 3e-5, weight decay = 0.01) with a linear learning
comment, ranging from 0% to 100%. rate schedule and 10% warm-up steps. To address memory
EM measures the ratio of generated outputs that are exactly constraints, we applied gradient accumulation over 3 steps
identical to the ground truth review comment. It is a stricter with a batch size of 12 (effective batch size = 36). We used
metric than BLEU because it requires a character-wise match. gradient clipping with a maximum norm of 1.0 and enabled
The EM score also ranges from 0% to 100%, where 100% mixed-precision training. The input and output lengths were
indicates that all the generated outputs for the test dataset are capped at 512 tokens for code and 128 tokens for review com-
character-wise identical to the ground truth. ments, based on the dataset’s token distribution (see Table II
and Figure 5). Longer input sequences were truncated to fit
D. Baselines within token limits. For RAG-based models, input prompts
To evaluate the effectiveness of RAG-Reviewer, we com- were augmented with as many retrieved exemplars as would
pare it against a range of baselines, including both generation- fit within the input token budget. We used a beam size of 10 for
based and IR-based methods. We reproduced all the baselines. evaluation. Training was conducted for up to 20 epochs, with
• CommentFinder: A first IR-based RCG approach that early stopping applied after 3 epochs of no improvement on the
uses Bag-of-Words (sparse vector) for code vectorization validation set. The best model checkpoint was selected based
and cosine similarity for candidate ranking [14]. on validation performance. For Tufano T5 and AUGER, we
• UniXCoder-IR: Proposed by Kartal et al. [16], this used the Adam optimizer (learning rate = 3e-4) with a batch
method uses UniXCoder (dense vector) [29] for code size of 12 and no gradient accumulation, based on preliminary
vectorization. Retrieval is based on similarity metrics tuning results. All baseline models were implemented using
such as cosine or Euclidean distance. publicly available replication packages [36]–[42].
• Tufano T5: A small version of the T5 [32] architecture
(6-layer encoder and 6-layer decoder) pre-trained for code V. E XPERIMENTAL R ESULT
review automation. It was pre-trained on code and natural In this section, we present experimental result of our work
language pairs collected from Stack Overflow and Code- following three research questions.
SearchNet [33] using masked language modeling [9].
• CodeT5: A pre-trained encoder-decoder model that sup-
A. (RQ1) Does RAG-Reviewer outperform existing baseline
ports both code understanding and generation. Based methods in terms of review comment generation quality?
on the T5 [32] architecture, CodeT5 [19] introduces Singleton vs. Pair Retrieval Strategy. Before comparing
identifier-aware objectives and bimodal dual generation RAG-Reviewer with existing baselines, we first evaluate which
tasks. It was pre-trained on CodeSearchNet [33] and ad- retrieval strategy achieves superior performance within RAG-
ditional GitHub repositories. We use the CodeT5-base Reviewer. Following Parvez et al. [24], we consider two strate-
variant, which has 12 encoder and 12 decoder layers. gies: (1) Singleton Retrieval, which retrieves a larger number
• CodeT5+: An extended version of CodeT5 that incorpo- of review comments without their associated code snippets
rates a mixture of pre-training objectives including span and (2) Pair Retrieval, which retrieves fewer exemplars but
denoising, contrastive learning, text–code matching, and preserves both the code snippets and their corresponding
causal language modeling. CodeT5+ [34] is trained on review comments.
both unimodal code and bimodal code–text corpora. We As shown in Table III, the pair retrieval strategy consistently
use the CodeT5p-220m version. outperforms singleton retrieval in terms of both EM and BLEU
• CodeReviewer: Specifically pre-trained for code review scores across all PLMs. The EM gains range from +0.14%
automation tasks, CodeReviewer [10] leverages a mul- (AUGER: 2.32% → 2.46%) to +0.53% (Tufano T5: 2.01%
tilingual dataset of code diffs and review comments → 2.54%). The BLEU gains range from +0.53% (CodeT5:
from GitHub. It introduces four novel pre-training tasks 12.45% → 12.98%) to +1.76% (CodeReviewer: 11.76% →
tailored for code review, such as diff tag prediction and 13.52%). These results suggest that providing both code and its
denoising objectives for both code and review comments. review comment in retrieved exemplars helps the model better
• AUGER: AUGER [35] is a T5-based [32] model that learn code–comment relationships. Given the inherent input
enhances review comment generation using review-line token limitations of language models, it is crucial to include
TABLE III TABLE IV
P ERFORMANCE COMPARISON OF RAG-R EVIEWER WITH T HE NUMBER OF CORRECTLY GENERATED LOW- FREQUENCY REVIEW
GENERATION - BASED AND IR- BASED BASELINES TOKENS
Answering RQ1
helpful information—both in quantity and quality—within Pair retrieval consistently outperforms singleton re-
the available budget. Our experiments show that rather than trieval in both EM and BLEU, and RAG-Reviewer
allocating tokens to more review-only exemplars, it is more achieves higher performance than generation-based
effective to include both the review comments and their and IR-based methods.
corresponding code. Notably, since code snippets are typically
much longer than comments (see Table II), pair retrieval fits
much fewer exemplars within the token limit. Nevertheless, B. (RQ2) Does RAG-Reviewer mitigate the challenges faced
providing richer contextual information through paired code- by language models in generating low-frequency tokens?
comment exemplars yields better performance than using a Effect on Generating Low-frequency Tokens. A well-
larger number of comment-only examples. known challenge for language models in generation-based
Generation-based vs. RAG-Reviewer. RAG-Reviewer methods is their difficulty in generating low-frequency ground-
consistently outperforms generation-based models across all truth tokens (LFGTs), due to a bias toward high-frequency
PLMs in both EM and BLEU scores. Notably, even models patterns learned during training [17], [18]. In contrast, IR-
with modest baseline performance, such as Tufano T5 and based approaches can help expose such tokens by retrieving
CodeReviewer, show the most significant gains—Tufano T5 similar examples that contain them. While we have observed
improves from 0.87% to 2.54% in EM (+1.67%), while that RAG-Reviewer improves generation over standard base-
CodeReviewer improves from 9.27% to 13.52% in BLEU lines in RQ1, we further examine whether it specifically helps
(+4.25%). These results suggest that retrieval augmentation mitigate this limitation by evaluating its ability to generate
benefits not only strong backbones but also weaker ones, LFGTs compared to generation-based methods. We define
enhancing both precision and fluency by grounding generation LFGTs as tokens that appear fewer than 100 times in the
in relevant contextual exemplars. training review comment corpus following previous work [22],
IR-based vs. RAG-Reviewer. Compared to IR-based meth- [30]. For each generated review comment, we count a token
ods, RAG-Reviewer achieves comparable or slightly higher as correctly generated if it appears in both the output and the
performance in most cases. For example, Pair CodeT5 ground truth. We then group these correctly generated tokens
(2.90%) and Pair CodeT5+ (3.01%) slightly outperform Com- by their frequency in the training set using thresholds of ≤20,
mentFinder (2.80%) and UniXCoder-IR (2.79%) in EM. ≤40, ≤60, ≤80, and ≤100. The improvement is measured as
BLEU scores show modest gains as well, with Pair CodeRe- the relative increase over the generation-based baseline.
viewer reaching 13.52% versus 12.41% and 12.80% for the IR As shown in Table IV, RAG-Reviewer improves the gen-
baselines. While the margins are small, RAG-Reviewer offers eration of LFGTs across all evaluated models. Tufano T5 ex-
the added benefit of generating comments conditioned on both hibits the most consistent relative gains, ranging from 20.68%
the input code and retrieved exemplars, allowing it to leverage to 23.67%. And CodeReviewer shows similar improvements
Fig. 6. Exact match performance of Pair CodeT5 with varying numbers of
retrieved exemplars on Tufano et al. benchmark
TABLE VI
R ETRIEVED EXEMPLARS USED FOR INPUT AUGMENTATION IN F IGURE 8
(K EY LFGT ‘ TRY- WITH - RESOURCES ‘ UNDERLINED )
Language models often struggle with generating low-frequency tokens due to a bias towards patterns that occur more frequently in the training data. RAG-Reviewer addresses these challenges by using retrieval augmentation to provide contextual exemplars that include such low-frequency tokens. This method assists the generation model in producing rare tokens more effectively by exposing it to similar examples that contain these less common elements .
RAG-Reviewer framework integrates retrieval-augmented generation to improve comment generation by leveraging contextual exemplars. Unlike traditional generation-based methods, which rely solely on the input code, RAG-Reviewer retrieves relevant review comment exemplars from a database, allowing the generator to condition on both the input code and these retrieved exemplars. This process helps ground the generation in meaningful context, enhancing the precision and fluency of the generated comments, as well as mitigating the difficulty in generating low-frequency tokens .
While strong pre-trained language models perform well on their own, the RAG-Reviewer framework enhances their capability by integrating retrieval augmentation. This approach grounds the comment generation process in specific, contextual exemplars, leading to improvements in precision and coverage, especially for low-frequency tokens. By leveraging both retrieval and generation methodologies, RAG-Reviewer enhances the models’ inherent capabilities beyond what is possible using pre-trained models alone .
Retrieval augmentation improves the generation of low-frequency tokens by exposing generation models to exemplars containing these rare tokens. This exposure mitigates the language models' bias toward high-frequency patterns. Recent findings show consistent improvements across various models, such as Tufano T5 and CodeReviewer, with relative gains in generating low-frequency tokens ranging from about 20% to 24% .
The primary tasks in a code review process include code repair (code-to-code), review comment generation (code-to-comment), and code refinement (code&comment-to-code). Automation, particularly through Code Review Automation (CRA), seeks to improve these tasks by reducing manual effort, increasing efficiency, and enhancing consistency in reviews. Automating especially the review comment generation task helps reviewers by providing potential comments as references or starting points for feedback .
BLEU score is a metric for evaluating the quality of text generated by models, assessing how similar the generated output is to a set of reference texts. In the context of models like RAG-Reviewer, a high BLEU score indicates that the generated review comments are precise and close to human-written references, reflecting better fluency and relevance of the model's outputs. A higher BLEU score signifies improved model performance in accurately generating review comments .
The retrieval module in the RAG-Reviewer framework identifies the most relevant exemplars from a pre-constructed retrieval database, which includes code snippets and their corresponding review comments. By encoding each code snippet into a dense vector space and utilizing maximum inner product search, the module retrieves exemplars that are most similar to the input code. These exemplars provide contextual grounding, enabling the generator to augment the input code with additional information that enhances the accuracy and relevance of the generated comments .
The performance of RAG-Reviewer improves as more exemplars are retrieved, with the most significant improvement occurring with the first exemplar. This indicates that even a small amount of additional context enhances the model's ability to generate accurate comments. However, the performance gains diminish as more exemplars are added due to the input length constraints of the language model, which limits the amount of exemplar information that can be effectively included .
RAG-Reviewer generally shows comparable or slightly higher performance than purely IR-based methods. While the performance margins are small, RAG-Reviewer benefits from retrieving exemplars to guide generation processes, allowing it to produce review comments that are more contextually grounded. This advantage is particularly evident in generating higher BLEU scores, precision, and fluency due to the combined use of retrieval and generative capabilities .
During the training phase, RAG-Reviewer prevents data leakage by excluding the top-1 retrieved exemplar that is identical to the input training instance. This is crucial because it ensures that the model does not simply memorize the training data but instead learns to generalize from similar but not identical examples. Such a strategy helps the model develop robust generation capabilities that can handle new, unseen inputs effectively .