Scaling Laws for Fact Memorization of Large Language Models (2024)

Abstract: Fact knowledge memorization is crucial for Large Language Models (LLM) to generate factual and reliable responses. However, the behaviors of LLM fact memorization remain under-explored. In this paper, we analyze the scaling laws for LLM’s fact knowledge and LLMs’ behaviors of memorizing different types of facts. We find that LLMs’ fact knowledge capacity has a linear and negative exponential law relationship with model size and training epochs, respectively. Estimated by the built scaling law, memorizing the whole Wikidata’s facts requires training an LLM with 1000B non-embed parameters for 100 epochs, suggesting that using LLMs to memorize all public facts is almost implausible for a general pre-training setting. Meanwhile, we find that LLMs can generalize on unseen fact knowledge and its scaling law is similar to general pre-training. Additionally, we analyze the compatibility and preference of LLMs’ fact memorization. For compatibility, we find LLMs struggle with memorizing redundant facts in a unified way. Only when correlated facts have the same direction and structure, the LLM can compatibly memorize them. This shows the inefficiency of LLM memorization for redundant facts. For preference, the LLM pays more attention to memorizing more frequent and difficult facts, and the subsequent facts can overwrite prior facts’ memorization, which significantly hinders low-frequency facts memorization. Our findings reveal the capacity and characteristics of LLMs’ fact knowledge learning, which provide directions for LLMs’ fact knowledge augmentation.

## introduction large language models (llm) have demonstrated remarkable abilities over a wide range of tasks @xcite @xcite cai @xcite . however, llms are prone to generating non-factual and fabricated contents, which is usually called "hallucination" @xcite @xcite and undermines llms' reliability. llms' factual responses highly rely on fact memorization. specifically, the llm memorizes fact knowledge during pre-training and the subsequent fine-tuning enables it to extract corresponding fact knowledge for the given instruction @xcite . if the base llm does not memorize specific knowledge, it will be challenging for the fine-tuned llm to correctly answer the corresponding question @xcite . additionally, fine-tuning with unmemorized fact knowledge even encourages llms' hallucination @xcite . despite the critical role of fact memorization, the behaviors of llm fact memorization remain largely under-explored. previous work usually analyzes the pre-trained llms' various abilities through the loss on unstructured text @xcite , and it is hard to reflect llms' fact memorization for two reasons: 1. the composition of pre-training corpus is highly complicated and fact knowledge appears in it mixedly and unevenly, which makes it hard to accurately quantify the fact knowledge in massive pre-training data. 2. the widely used metric, loss, can not directly measure the llm fact memorization since not all tokens are fact-related. this paper makes progress in quantitatively analyzing llm fact memorization behaviors, including the scaling laws and behaviors of memorizing different types of facts. we focus on the memorization of atomic facts to facilitate accurately quantifying the number of facts and the memorization accuracy. we define atomic fact knowledge as a (key, attribute, value) triple, e.g., (spacex, ceo, elon musk), following @xcite . given a key and an attribute, if the llm correctly predicts the corresponding value, we consider it to memorize this fact knowledge. in this way, we can accurately quantify the number of fact knowledge and whether the llm fully memorizes a specific fact, which facilitates a more accurate quantitative analysis of llm's fact memorization behaviors. based on this setting, we analyze the llm's fact memorization behaviors on massive facts from a large real-world information table. specifically, we analyze the fact memorization scaling law of llms and llms' behaviors of memorizing different types of fact knowledge, including the following research questions (rq): rq1: how does llm's fact knowledge capacity scale with its size and training epochs? we define the fact knowledge capacity as the maximum fact triple quantity that the llm can accurately memorize. we find that llm's fact capacity linearly scales with its size under the same training epochs. additionally, we find that the training epochs required for llms to memorize fact knowledge is significantly larger than one and this leads to higher training cost than general knowledge learning in pre-training. increasing training epochs can initially increase the llm's fact capacity and then reach saturation, which exhibits a trend of negative exponential law. additionally, we extend our experiments to the wikidata and the results exhibit a consistent trend, shown in figure 1 . according to the scaling law, under 100 training epochs, memorizing all wikidata's fact triples requires about 1000b non-embed parameters, which seems very costly. these indicate the necessity of supplementing llms with fact knowledge by external information, like retrieval-augmented generation (rag) @xcite @xcite @xcite @xcite . rq2: can llms efficiently memorize redundant facts? many facts are derivable and thus redun-dant. for example, "ivanka is trump's daughter" can derive from "trump is ivanka's father". we analyze whether llms can efficiently memorize redundant facts, i.e., whether llms can save memorization capacity when simultaneously memorizing redundant facts. we find that llms struggle with efficiently memorizing redundant information. in general cases, when memorizing the redundant and non-redundant information of the same scale, the llm exhibits a similar memorization rate. only under specialized conditions, e.g., the correlated facts have the same direction and structure, the llm can efficiently memorize them. these demonstrate llms' inefficiency in redundant fact memorization. since massive redundant facts can appear in pre-training data in various forms, these indicate it is not cost-effective to use llms' parameters to store fact knowledge, and using a non-parametric method, like rag, can be more efficient. rq3: what influences llm's memorization preference for different types of fact knowledge? during pre-training, llms meet various facts and only memorize portions of them. we analyze llms' fact memorization preference in three aspects: frequency, difficulty and memorization order. we find that llms pay more attention to memorizing more frequent and difficult facts. additionally, when an llm memorizes two types of facts sequentially, the subsequent facts will significantly overwrite the memorization of prior facts. these further explain llms' inferior memorization of low-frequency facts since they appear infrequently during pre-training process and thus can be easily overwritten by subsequent pre-training knowledge. beyond fact memorization, we also analyze an interesting topic of fact knowledge generalization: rq4: can llms generalize on unseen fact knowledge? what is the relation between fact memorization and generalization? surprisingly, we find that the llm can generalize on unseen facts to a certain level and its scaling law is highly similar to common pre-training llm scaling law @xcite . the generalization accuracy is determined by the type of fact and some types of facts exhibit high generalizability, suggesting the potential of improving llms' factuality by adaptively leveraging fact generalization. meanwhile, we find a qualitative relation between fact memorization and generalization: to the same type of fact, the easier the llm is to memorize it, the better the llm generalizes on the unseen set. this indicates that both llm fact memorization and generalization are based on the correlation between input and output @xcite . if there is a stronger correlation between the input and output of one type of fact, it will be easier for the llm to memorize and learn about the type of fact knowledge in a unified manner. conversely, if the correlation is minimal, llm needs to memorize facts individually, and is hard to generalize on unseen ones. we summarize our contribution as follows: 1) to the best of our knowledge, this paper is the first to quantitatively analyze llms' scaling laws and behaviors of fact memorization on massive realworld facts. 2) our findings reveal the capacity and characteristics of llms' fact knowledge learning. these results show that llms are highly inefficient for fact memorization from multiple perspectives, which suggests leveraging non-parametric methods, e.g., rag, to enhance the fact knowledge of llms. ## preliminary in this paper, we focus on the quantitative analysis of llms' atomic fact knowledge memorization and we introduce the experiment setup as follows. ## fact capacity scaling laws exploratory experiment first, we observe the same llm's memorization rate over varying numbers of training facts under the same training epochs. we show the results in figure 2 . we see that the memorization rate significantly decreases with the increasing facts. these initially show that there is a memorization capacity upper limit for the llm with the same size and training epochs. in this section, we explore the scaling laws of llms' fact capacity. we define the fact capacity as the maximum fact quantity that the llm can accurately memorize as: ## redundant fact memorization in this section, we explore whether llms can efficiently memorize redundant facts, i.e., whether llms can save memorization capacity when simultaneously memorizing redundant facts. specifically, we conduct experiments on three types of redundant facts: 1) the forward and reverse versions of the same fact knowledge 2) the correlated facts of the same key 3) single-hop facts and their derivable multi-hop facts. additionally, we analyze whether learning abstract abilities occupies the fact memorization capacity. we set the training epoch as 1000 to make the llm's memorization saturated, unless otherwise specified. ## fact memorization preference of llms we analyze llms' fact memorization preference in three aspects: frequency, difficulty and memorization order. since this section focuses on preference, we select irrelevant facts to conduct experiments. specifically, we use the combination of facts in the company information table and a specialized subset of wikidata facts (@xmath0. frequency we compare the respective memorization rate of simultaneously memorizing two attributes under different frequencies. the results on "longitude & author" and "operator & author" are shown in figure 9 . we see that the higher frequency leads to a significantly higher memorization rate and inhibits low-frequency facts' memorization @xcite . this indicates the importance of increasing the frequency of low-frequency facts in pre-training corpus to facilitate llms' memorization of them. however, since facts in pre-training corpus usually appear in a complicated and mixed manner, it is non-trivial to separately control their respective frequency, which further increases the challenges for llms to memorize low-frequency facts. difficulty we compare the respective memorization rate of three groups: 1) using llm of size 2 * n to simultaneously memorize facts of two attributes with different memorization difficulties; 2) using llm of size n to separately memorize facts longitude credit-no longitude & credit-no training facts 0 15 30 45 60 75 mr (%) longitude mr credit-no mr (a) longitude & credit-no longitude operator longitude & operator training facts 0 15 30 45 60 75 mr (%) longitude mr operator mr (b) longitude & operator figure 10: the effect of difficulty for fact memorization. in this way, we can observe the llm's preference when simultaneously memorizing two attributes. the results on "longitude & credit-no" and "longitude & operator" are shown in figure 10 and more results on other combinations are shown in appendix h. we define the difficulty of facts according to the memorization rate under the same training size. in group 2, the memorization rates of attributes "credit-no" and "operator" are higher than "longitude" and thus they are easier to memorize. compared with group 2, the memorization rate of difficult facts and easy facts in group 1 increases and decreases, respectively. these show that when llms memorize different types of facts, they tend to pay more attention to the facts that are harder to memorize. ## fact generalization of llms beyond the fact memorization, we explore an interesting question: can llms generalize on unseen fact knowledge? specifically, we train the llm to memorize facts of a group of keys and test it on unseen keys' facts. we show each attribute's generalization accuracy (exact match) of 44m model in figure 12 . we also test results of 30m model and observe similar trends (see appendix i). we observe that facts on most of the attributes have a generalization accuracy greater than zero, which indicates that llms can generalize on unseen fact knowledge to a certain level. to analyze why the llm can generalize on fact knowledge, we conduct a case study on facts of three attributes and show the cases in appendix j. we find that llms' fact generalization depends on the correlation between input (key) and output (value) @xcite . for a specific type of fact (attribute), the higher correlation between the key and value leads to higher generalization accuracy. for example, the llm may correctly predict an unseen company's longitude if the company name contains a region name and the training dataset contains the longitude of companies with the same region name. or it can roughly estimate the company's register-capital according to company size indicated by the company name, e.g., "fruit shop"→ (¥10 4 ∼ ¥10 5 ) or "investment company"→ (¥10 7 ∼ ¥10 9 ). meanwhile, different types of facts have different generalizability. for those facts with obvious patterns, the llm can achieve reliable generalization. for those attributes with weak correlation, although the llm does not know exactly the facts, it can identify the rough range of facts. these suggest the potential of adaptively leveraging llm's fact generalization: fact generalization scaling law additionally, we analyze the scaling law of llms' fact knowledge generalization. specifically, we plot the llms' loss values on test fact knowledge under different training fact quantities, following @xcite . the results are shown in figure 11 . we find that the test loss on fact generalization also follows the power-law @xcite as: ## related work understanding the scaling behaviors of llms is important for decisions about the key choice design of llms, e.g., model size or pre-training data @xcite @xcite . most of the existing work focuses on the scenario of general pre-training or downstream tasks. @xcite observe the power law relationships between the llm perplexity and size of llm and dataset. hoffmann et al. (2022b) explore the optimal token quantity and llm size for pretraining under a specified compute budget and find that the llm size and training tokens should be scaled equally for compute-optimal llm training. besides pre-training, researchers find that the performance of downstream tasks can be predicted from the llm size and training data scale @xcite @xcite . different from them, our paper specifically focuses on scaling laws of llms' fact memorization and behaviors of memorizing different types of facts, which is critical for llms' factual responses. @xcite , concurrently to our work, explore scaling laws of llms' memorization on synthetic facts. our work differs in several ways: 1. we analyze llm's fact memorization on real-world facts while they use randomly generated facts, which have a non-negligible gap with real-world facts. according to our findings, we conclude that memorizing all wikidata's facts requires 1000b non-embed parameters, which indicates that using an llm to memorize all public facts is almost not plausible. 2. we additionally analyze llms' behaviors of learning fact knowledge in different aspects, including compatibility, preference and generalization, which further provide directions for fact knowledge augmentation of llms. ## conclusion we analyze llms' fact memorization behaviors and these are our main conclusions: 1) the fact capacity has a linear relationship with model size and a negative exponential law relationship with training epochs. according to the built scaling law, we estimate that memorizing all of wikidata fact triples requires training an llm with 1000b nonembed parameters for 100 epochs, which seems very costly; 2) we find that llms struggle with efficiently memorizing redundant facts. only for redundant facts with the same direction and structure, llms can memorize them in a unified manner.