Be like a Goldfish, Don't Memorize! Mitigating Memorization in Generative LLMs

Large language models can memorize and repeat their training data, causing privacy and copyright risks. To mitigate memorization, we introduce a subtle modification to the next-token training objective that we call the goldfish loss. During training, randomly sampled subsets of tokens are excluded from the loss computation. These dropped tokens are not memorized by the model, which prevents verbatim reproduction of a complete chain of tokens from the training set. We run extensive experiments training billion-scale Llama-2 models, both pre-trained and trained from scratch, and demonstrate significant reductions in extractable memorization with little to no impact on downstream benchmarks.

Paper

Similar papers

Peer review

Reviewer muP65/10 · confidence 4/52024-07-03

Summary

This paper proposes a `goldfish loss', a loss that excludes some tokens in each training data sequence from the loss computation, with the aim of decreasing verbatim memorization of sequences. Which token is excluded is decided with a function G(x_i). The authors try two different drop functions, one of which drops 1/k tokens randomly, and other drops every kth tokens. To ensure similar tokens get dropped for duplicate documents, in the second method, a hashing approach is used to make sure that if a token is dropped, preceeding occurrences of that token will be dropped as well if they share h=13 previous tokens. To test this loss, the authors first train a 7B Llama2 model over 100 wikipedia documents for 100 epochs that in total have around 200K tokens. Without goldfish scenario, the verbatim memorization rate is 84/100 articles, while with a goldfish loss with k=4 no articles get memorized. Next, the authors train a TinyLlama-1.1B model on a subset of RedPajama v2 (single epoch), with around a 2-4M wikipedia tokens mied in, repeated 50 times in random locations to simulate data duplication. The total amount of tokens trained on is 20B. They show that the goldfish loss substantially decreases the memorization rates in this training setup. They show that it has little to no effect on a range of benchmark scores (though those scores are often at chance). The also show that model strained with goldfish loss have Mauve scores similar to the control models.

Strengths

- This paper proposes a simple loss that can be used to reduce memorization. It's simplicity will make it more likely that the loss could actually be adapted - The loss seems to be very effective in reducing memorization rates, while not impacting validation loss - The paper is well written and easy to follow

Weaknesses

- It is a bit unclear to me why it is necessary to mix in the wikipedia sequences at such a high rate. RedPajamas is intended to provide a reasonable version of a training corpus, why not just train on that alone? Mixing in data with a repetition rate of 50 times is quite unusual, I wouldn't call that 'normal training conditions'. It makes me wonder if the effect is less strong if the method is applied to red pajamas alone. - Several of the benchmark scores are barely above chance level (e.g. Winogrande has a chance performance of 50%, performance of the trained models is hardly above that), while this strictly speaking supports the statement that there is no performance drop, a consistent random performance is no evidence that the method does notnegatively impact performance. While the scores are above chance for several other benchmarks (e.g. Arc-C performance is 40%, while chance is 25%, PiQA performance is around 62%, chance is 50%), the scores are low, making it difficult to judge the impact of the method on performances.

Questions

- Did I understand correctly that you mix in 2-4M tokens 50 times, so that 100-200M = 0.5% of the total corpus is heavily repeated corpora (that may also be included in the RedPajama corpus)? Why do you call that 'normal training conditions'? Wouldn't training on RedPajama itself be normal training conditions? - I do not really understand why the gold fish loss (per supervised token count) would be lower than the regul ar loss. Do you have an explanation for that?

Rating

5

Confidence

4

Soundness

2

Presentation

4

Contribution

2

Limitations

- One limitation that I would like the authors to address is my point about the chance level performance on benchmarks (though it may be better to just remove the benchmarks). Perhaps it would be worth including a few benchmarks that are better at small scale as well? - I don't think there are any negative societal impacts of the work.

Reviewer EFrP6/10 · confidence 2/52024-07-03

Summary

This paper tackles the issue of memorization in large language models (LLMs), where models reproduce verbatim training data, posing copyright, privacy, and legal risks. The authors propose a novel technique called "goldfish loss" to mitigate this problem during training. Instead of calculating the next-token prediction loss on all input tokens, goldfish loss computes it on a pseudo-random subset, preventing the model from learning entire training sequences verbatim. The paper demonstrates the effectiveness of goldfish loss in reducing extractable sequences with minimal impact on downstream benchmark performance and language modeling ability.

Strengths

- The goldfish loss is a simple yet effective technique for mitigating memorization during training, distinct from existing post-training methods. - Introducing the robust handling of duplicate passages with hashing is a very interesting technique that makes the goldfish loss possible in practice. - The paper provides strong empirical evidence supporting the effectiveness of goldfish loss in reducing memorization, particularly in extreme scenarios designed to induce memorization with minimal impact on downstream tasks. - The simplicity and ease of integration of the goldfish loss into existing training pipelines make it a viable solution for real-world LLM development.

Weaknesses

- While empirically effective, the goldfish loss lacks theoretical guarantees regarding the complete prevention of memorization. The paper acknowledges this limitation and highlights the possibility of adversarial extraction techniques circumventing the goldfish loss. - The paper would benefit from a more in-depth discussion on the computational complexity introduced by the hashing mechanism used for robust duplicate handling. Analyzing the trade-off between hash context size (h) and memorization prevention, as well as the computational overhead of hashing, would strengthen the paper.

Questions

- he paper explores different values of k (drop frequency) and h (hash context size). A more detailed analysis of the sensitivity of goldfish loss to these hyperparameters would be beneficial. How do different values affect memorization prevention and downstream performance?

Rating

6

Confidence

2

Soundness

3

Presentation

3

Contribution

2

Limitations

- The paper does not include an analysis of the computational overhead introduced by the hashing mechanism.

Reviewer YZ484/10 · confidence 4/52024-07-06

Summary

This work presents a new goldfish loss to mitigate memorization during pretraining. Specifically, for every k tokens during training, the loss for one token is skipped to prevent the exact memorization of the entire string. Experiments on 7B llama-2 and 1.1B tinyllama demonstrate that the goldfish loss can effectively reduce memorization while maintaining performance on downstream tasks.

Strengths

1. The idea is conceptually simple and very easy to implement. 2. The goldfish loss can effectively reduce the risk of exact memorization. This is demonstrated in multiple experiments in this paper and through multiple different metrics. Even for more advanced attacked (e.g., membership inference attack, beam search, etc.), the proposed method also show significant improvement.

Weaknesses

1. The main empirical results to support the claim that goldfish loss will not hurt downstream performance in Figure 4. While I do see in the figure that the goldfish loss can achieve similar performance as the standard loss, the stand loss itself also only achieves very little gain over the control model (with BoolQ being the only exception). Therefore, the only real empirical result is that goldfish loss will not hurt gain on BoolQ, which is still good evidence but insufficient to support the main claim of the paper. 2. While I'm confident that the goldfish loss can prevent exact memorization, I'm not sure if it actually prevents the model from learning the content that the model is not supposed to learn. It is very likely that the model learns the content, but can only generate it in a slightly paraphrased way. If this is really the case, the impact of this paper seems limited. There is no related investigation or discussion in this paper. 3. There are some inclarities about the experiment settings (see questions below).

Questions

1. Why are some of the experiments conducted on llama-2 and others on tinyllama? 2. How do you implement the hash function mentioned at line 128? 3. Do you also apply the goldfish loss on RedPajama? 4. Can you explain more about why the gold loss work even when sampling with zero temperature (i.e., greedy decoding)? In such a case, the toy example from line 104-113 will not work, as the token with the maximum probability remains the same. Is it the case that the generalization probability on those tokens in fact quite small?

Rating

4

Confidence

4

Soundness

2

Presentation

3

Contribution

2

Limitations

The authors provide a good discussion of limitations in Sec. 7

Reviewer wVka7/10 · confidence 4/52024-07-12

Summary

This work focuses on the issue of memorization, where a language model can be prompted to exactly repeat a document or sequence from its training data. The authors introduce a loss which masks random tokens in a sequence during training. To ensure the same mask is applied to duplications of a sequence, or a same sequence in a different context, they always use the same mask for the same words using a hash table. They then show through different training paradigms that their loss reduces memorization while having minimal impact on performance and training time.

Strengths

Strengths A very simple but efficient approach, adapted to the specificity of the exact memorization framework. Tests are quite relevant and show very strong performance, even in adverserial settings (and aknowledge weaknesses to those). Main usage drawbacks are mentioned and convinvingly argued to be a small cost for high gain : absence of guarantees, and a need for a small amount of additional training. Math is clear, work is reproducible, and experiments address main concerns and baselines relevant to the field.

Weaknesses

(1) Results on benchmarks seem to show that while verbatim repetition is avoided, knowledge is still retained (Fig. 4). Do you have any qualitative pointers on output variation between goldfish and non goldfish loss in those settings? Is the output a paraphrase of learnt text? My worry is that the strict "exact copy" metrics used to evaluate the loss might be too artificial, and might not give a complete idea of data leakage. While this deviates from the definition of memorization in 2.1, motivation in introduction would push for analysis in this direction. (the privacy/copyright/PII motivation is harmed where sensitive data might still filter through, using different words).

Questions

Mostly a curiosity question: Do you have any idea of the impact on the model’s generalisation capabilities? Similarly to the reasoning behind dropout, the proposed loss seems to avoid a form of overfitting, and might refocus learning on higher level representations.

Rating

7

Confidence

4

Soundness

4

Presentation

4

Contribution

4

Limitations

While I am quite impressed by the actual results and work, my main concern (and reason for ethical concerns) is the way motivation is explained. Trials have shown in Europe, (and to my knowledge in the US) usage of copyrighted data in a for-profit setting without authorisation is forbidden (ex: RGPD compliance, copyrighted books.). This includes training the model with this data, even if it does not output exactly the same data word for word. The proposed loss, especially with the high performance reported in the paper could therefore have the negative outcome of hiding this unlawful usage. In the introduction (and to a lesser extent the conclusion), it sometimes appears that this is argued to be a feature. → In the “copyright risk for the consumer” example, it seems to be argued that if the model does not reproduce the unauthorised copyrighted data, they will be protected from copyright infringement. It is my understanding that using a tool made with that code also falls under copyright. → The “copyright risk for the provider” example follows a similar idea. Making profit as creator/provider/user of a tool made with copyrighted code falls under copyright. (On the other hand, the privacy risk example seems a very interesting and promising use case). I strongly recommend clarifying both in the text, and in either limitation or some ethics paragraph that the usage of non-authorised or stolen private data is forbidden, and a potential misuse of this work.

Reviewer wVka2024-08-09

Thank you for addressing my concerns, I am glad to hear you commit to re-emphasizing adherence to fair data use in the intro. As this was my main concern I will now increase the score.

Authorsrebuttal2024-08-09

Author Response to Reviewer wVka

We thank the reviewer for their positive comments and the corresponding score increase. We further welcome any questions during the discussion period.

Reviewer muP62024-08-10

Thank you for your response. I appreciate them and appreciate the updates. However, they do not really take away my main concerns (if anything, they may have strengthened them in confirmation). In particular: - I appreciate the adding of random scores and the additional experiments done by the authors, and I recognise that with an academic budget it is difficult to get sota performance on difficult benchmarks. However, it does not really help to make a convincing point about lack of degradation on benchmarks if the scores are that low. I would recommend the authors to focus on some simpler benchmarks - The rebuttal strengthens me in my idea that the 'normal' setting the authors propose is in fact not a normal amount of duplication in training. The authors are correct there is usually quite some duplication in training corpora, this challenge exists not because people deliberately put in duplicate sequences, but because deduplication is pretty difficult. This implies that a 'normal' scenario is the one where models are trained on is -- in fact -- using a corpus like RedPajama's as is, not starkly upsampling part of it. This stark deviation diminishes the contribution of the paper, unfortunately, because it is unclear what the effect of the loss would be in more normal scenarios. I appreciate the extra experiment done with the increased batch / step-size to clear up the curiosity that the goldfish loss has a lower per-token loss initially (though I don't fully follow the first three points in the explanation, I think only the last 3 are relevant?)

Authorsrebuttal2024-08-11

Thank you for your continuing the discussion! I think we understand your concerns a bit better now. We'll rephrase our clarifications in a different way: * **Regarding the choice of benchmarks for "small" LLMs**. While we showed all of these benchmarks, for completeness' sake, in the paper, we do observe SOTA performance for ~1B param LLMs on the easier tasks, such as bool-q. (For reference, OPT-1.3b: 60.83, Pythia-1B:57.83). Further, we do know that validation loss closely tracks downstream performance in large language models, and we closely measure and quantify the impact on validation loss (which can be much more precisely measured than the benchmarks) in the paper, and e.g. rebuttal Fig.2b. * **Regarding the normal training setting**. To re-iterate, this setting (the 1B param model training also discussed above) is a normal training setting. The model is trained from scratch with a common pretraining dataset to do language modeling. The *only* difference is that canary sequences (from Wikipedia) are inserted and repeated, so that memorization can be measured in a controlled manner. These sequences are a minuscule fraction of the overall training data, but allow us to measure memorization in a controlled way. This is not even our design only, the usage of canary sequences like this is a common choice to measure memorization effects, e.g. [1], [2], [3], [4]. To clarify, is your concern that setup of **normal training + canary data** is in some way distorting training dynamics? (While this is technically not impossible, the chances are quite low, due to the small fraction of canaries to overall training data). Or, is your concern that "natural" memorization behavior, would look differently from this test study? From existing literature, repeated sequences are a key component of memorization in language model, and studies of trained models show that "Examples that are repeated more often in the training set are more likely to be extractable, again following a log-linear trend" [5], and further investigations in [6]. --- [1] "Measuring Forgetting of Memorized Training Examples", Matthew Jagielski, Om Thakkar, Florian Tramèr, Daphne Ippolito, Katherine Lee, Nicholas Carlini, Eric Wallace, Shuang Song, Abhradeep Thakurta, Nicolas Papernot, Chiyuan Zhang (please look for the definition of the INJECT strategy for canary injection in Sec 4.1) [2] "The Secret Sharer: Evaluating and Testing Unintended Memorization in Neural Networks", Nicholas Carlini, Chang Liu, Úlfar Erlingsson,Jernej Kos, Dawn Song [3] "Understanding Unintended Memorization in Federated Learning" Om Thakkar, Swaroop Ramaswamy, Rajiv Mathews, Françoise Beaufays [4] "Investigating the Impact of Pre-trained Word Embeddings on Memorization in Neural Networks" Aleena Thomas, David Ifeoluwa Adelani, Ali Davody, Aditya Mogadala, Dietrich Klakow [5] "Quantifying Memorization Across Neural Language Models" Nicholas Carlini, Daphne Ippolito, Matthew Jagielski, Katherine Lee, Florian Tramer, Chiyuan Zhang [6] "Memorization Without Overfitting: Analyzing the Training Dynamics of Large Language Models" Kushal Tirumala, Aram H. Markosyan, Luke Zettlemoyer, Armen Aghajanyan

Reviewer YZ482024-08-12

Thank the authors for the detailed response. The answers to my questions clear many of my confusions about this work. However, my major concern is still not resolved: I understood the impact on validation loss, and I think the story there is convincing. However, there is just no real informative (where we can see a clear benefit from standard pretraining) downstream task evaluation other than Boolean QA. I like the idea in this paper, but impact on downstream application is a critical part of this paper, and more empirical evidence is needed.

Authorsrebuttal2024-08-13

Thank you for understanding our key experiment measuring validation loss and finding it convincing in determining the benchmark scores at larger (beyond our compute budget). We share below the benchmark results from Pythia [1] and TinyLLaMA [2] models, both SOTA at 1B scale, across different tokens seen. Please see the results from our work in the bottom 3 rows (with standard error in parentheses). | Model | Pretrain Tokens | HellaSwag | OpenBookQA | WinoGrande | Arc-C| Arc-E | BoolQ | PIQA | Average | |-------------------------------------------|-----------------|-----------|------|------------|-------|-------|-------|------|-----| | Pythia-1.0B | 300B | 47.16 | 31.40| 53.43 | 27.05 | 48.99 | 60.83 | 69.21 | 48.30 | | TinyLlama-1.1B-step-50K | 103B | 43.50 | 29.80| 53.28 | 24.32 | 44.91 | 59.66 | 67.30 | 46.11| | TinyLlama-1.1B-step-240k| 503B | 49.56 |31.40 |55.80 |26.54 |48.32 |56.91 |69.42 | 48.28 | | TinyLlama-1.1B-step-480k | 1007B | 52.54 | 33.40 | 55.96 | 27.82 | 52.36 | 59.54 | 69.91 | 50.22 | | TinyLlama-1.1B-step-715k | 1.5T | 53.68 | 35.20 | 58.33 | 29.18 | 51.89 | 59.08 | 71.65 | 51.29 | | TinyLlama-1.1B-step-955k | 2T | 54.63 | 33.40 | 56.83 | 28.07 | 54.67 | 63.21 | 70.67 | 51.64 | | TinyLlama-1.1B-step-1195k | 2.5T | 58.96 | 34.40 | 58.72 | 31.91 | 56.78 | 63.21 | 73.07 | 53.86| | TinyLlama-1.1B-step-1431k | 3T | 59.20 | 36.00 | 59.12 | 30.12 | 55.25 | 57.83 | 73.29 | 52.99 | | Control (ours) | 20B (RedPajama) | 35.29 (0.47) | **29.60** (2.04) | 52.24 (1.40)| **23.81** (1.24) | **40.61** (1.01) | 52.72 (0.87) | 62.78 (1.12) | 42.43 (1.16) | | Standard Loss (ours) | 20B (RedPajama + Wiki) | **35.53** (0.47) | 28.60 (2.02) | 52.24 (1.40) | 23.63 (1.24) | 40.57 (1.01) | 58.31 (0.86) | **63.11** (1.12) | 43.14 (1.16) | | **Goldfish Loss (ours)** | 20B (RedPajama + Wiki) | 34.51 (0.47) | 28.80 (2.02) | **52.64** (1.40) | 23.80 (1.24) | 39.73 (1.02) | 60.82 (0.85) | 62.89 (1.12) | **43.31** (1.16) | - As observed in the above table, the benchmark scores are only increased to the SOTA level for a high amount of compute (500B-1T tokens), which is significantly beyond our academic budget, not just for this project but for multiple of our projects combined. - The performance of all three models – Control, Standard Loss, and Goldfish Loss – varies only marginally. This indicates that the models learn roughly equally well, considering the mentioned statistical significance. - Thus, to empirically measure the impact of goldfish on downstream performance (i.e., performance cost), we conduct the validation-loss gap experiment and measure the performance gap (Figure 2b, global rebuttal pdf). We also supplement this result with two strategies to mitigate this cost (by matching the supervised token count). - We argue that this is justified for a proof-of-concept research work like ours and that large-scale benchmark scaling of goldfish is more suited to industry applications. Moreover, we also run all benchmarks from Open LLM Leaderboard v2 [3]. Out of 63 tasks, only 14 (shown below) have better performance for _Standard Loss_ than _Control_. Of which, _Control_ is better than chance-level for 6 tasks. This showcases that, at our scale, not many benchmarks provide non-trivial results and thus we're bound by our compute and high-signal benchmarks for smaller models. |Benchmark Task|Chance-Level Score|Control|Control > Chance Level|Goldfish Loss|Standard Loss| |:----|:----|:----|:----|:----|:----| |bbh_boolean_expressions|50.00|46.00|No|46.80|47.20| |bbh_date_understanding|16.60|14.00|No|19.60|20.00| |bbh_geometric_shapes|10.00|7.20|No|8.40|8.40| |bbh_logical_deduction_three_objects|33.00|33.20|Yes|32.00|33.60| |bbh_movie_recommendation|16.60|25.60|Yes|28.00|27.60| |bbh_penguins_in_a_table|20.00|18.49|No|21.23|22.60| |musr_object_placements|25.00|22.66|No|26.17|26.95| |commonsense_qa|20.00|19.66|No|20.23|19.82| |fda|contains the value|18.97|-|20.78|23.32| |gpqa_diamond_cot_zeroshot|exact_match,flexible-extract|5.56|-|8.08|9.60| |gpqa_diamond_generative_n_shot|exact_match,flexible-extract|6.57|-|7.07|9.60| |gpqa_extended_generative_n_shot|exact_match,flexible-extract|10.26|-|8.06|11.72| |gpqa_main_cot_zeroshot|exact_match,flexible-extract|7.37|-|7.14|8.26| |squad_completion|contains the value|18.06|-|27.25|21.75| We have added all above mentioned results in our potential camera-ready version as well. --- [1] Stella Biderman, et al., "Pythia: A Suite for Analyzing Large Language Models Across Training and Scaling," 2023. [2] [2] Peiyuan Zhang, Guangtao Zeng, Tianduo Wang, & Wei Lu. (2024). TinyLlama: An Open-Source Small Language Model. [3] Clémentine Fourrier, et al. (2024). Open LLM Leaderboard v2.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC