GENERATIVE LANGUAGE MODEL ENHANCED WITH A GENERATIVE ASSOCIATIVE MEMORY

An approach is provided for enhancing a generative large language model (LLM). An encoder, decoder, and generative associative memory network set are jointly trained to learn to store sentence encodings in a memory matrix used during decoding. The encoder and decoder are included in the generative LLM. The generative associative memory network set is included in an external memory unit. The external memory unit is external to the encoder and decoder. The generative LLM is augmented with the external memory unit in a framework that enhances the generative LLM. The external memory unit is updated with new information. Using the new information in the updated external memory unit, a knowledge update of the decoder is performed during an inference without fine-tuning or re-training the generative LLM. A response to a prompt during the inference is generated. The response is based on the knowledge update of the decoder.

BACKGROUND

The present invention relates to generative artificial intelligence, and more particularly to enhancing a generative large language model by using an external memory unit.

SUMMARY

In one embodiment, the present invention provides a computer system that includes one or more computer processors, one or more computer readable storage media, and computer readable code stored collectively in the one or more computer readable storage media. The computer readable code includes data and instructions to cause the one or more computer processors to perform operations. The operations include jointly training an encoder, a decoder, and a generative associative memory network set. The encoder and decoder are included in a generative large language model (LLM). The generative associative memory network set is included in an external memory unit. The external memory unit is external to the encoder and the decoder. The generative LLM is augmented with the external memory unit in a framework that enhances the generative LLM. The jointly training includes learning to store sentence encodings in a memory matrix, which is used during a decoding by the decoder. The operations further include updating the external memory unit with new information. The operations further include, using the new information in the updated external memory unit, performing a knowledge update of the decoder during an inference without fine-tuning or re-training the generative LLM. The operations further include generating, by the generative LLM, a response to a prompt during the inference, the response being based on the knowledge update of the decoder.

A computer program product and a method corresponding to the above-summarized computer system are also described herein.

DETAILED DESCRIPTION

Overview

A generative large language model (LLM) (e.g., a generative artificial intelligence (AI) chatbot or a computer vision tool) can generate hallucinations by perceiving patterns or objects that are nonexistent or imperceptible to human observers, which lead to outputs that are factually incorrect or nonsensical, or include invented details. LLM-generated hallucinations may facilitate the spread of misinformation and can reinforce biases and stereotypes present in training data, thereby worsening social problems such as discrimination. These hallucinations can also weaken trust in AI content and obstruct the adoption of AI in certain domains.

Embodiments of the present invention address the aforementioned unique challenges by providing a generative LLM (i.e., an LLM encoder-decoder) that is augmented with one or more external memory units that include a generative associative memory network set (also referred to herein as an episodic associative memory network). Hereinafter, the generative LLM augmented with the aforementioned external memory unit is also collectively referred to as the enhanced generative LLM.

The enhanced generative LLM mimics the bi-directional neocortex-hippocampus interactions and divisions of labor in the human brain, thereby providing the generative LLM with an ability to explicitly encode information and form memories, which facilitates the performing of tasks that require long-term dependencies, such as hallucination prevention, reasoning, generalization, and value alignment. The neocortex, which interacts with the world and maintains a semantic representation of the world, is approximated by the generative LLM. The hippocampus, which retains recent (i.e., episodic) memories, gradually consolidates the recent memories into longer-term memories, and is involved in the retrieval of memories is approximated by the generative associative memory network set.

In one embodiment, the generative LLM is significantly larger in size and complexity than the external memory unit. The external memory unit is associative, generative, and sparsely distributed. Because of the sparsely distributed aspect and latent encoding of memory, the memory size in the enhanced generative LLM architecture is independent of the input data dimensions. Furthermore, the sparsely distributed aspect allows an increase in the capacity of associative memory by reducing overlap between memory representations.

In one embodiment, the framework provided by the enhanced generative LLM memory provides (i) associativity (i.e., memory retrieval with denoising), (ii) generative memory (i.e., sampling from learned memory distribution), (iii) fast and dynamic update (i.e., memory that is explicitly modified at runtime), (iv) memory-based inference (i.e., at generation time (also known as decoding time), the distribution is conditioned on memory), and (v) scalability (i.e., efficient memory storage whereby the number of storage items can grow per fixed memory size without significant information loss). The aforementioned associativity includes an ability to retrieve a remembered pattern based on a distorted or incomplete version of the pattern. The aforementioned fast and dynamic update includes a fast belief update in response to an arrival of a new data episode, thereby enabling fast episodic learning.

In one embodiment, the enhanced generative LLM provides novel generation, which enables improved generation from the memory of a learned episode, as well as generative replay. In one embodiment, the enhanced generative LLM provides off-line replay, which enables memory consolidation.

The enhanced generative LLM provides memory replay that supports fact checking and continual learning. Furthermore, the enhanced generative LLM provides sample quality improvement via denoising and generating, thereby resulting in sample-efficient model alignment and hallucination prevention.

In one embodiment, training methods are provided to jointly optimize the LLM decoder and the external memory unit, resulting in a model that learns to store sentence encodings in a memory matrix, which is used during decoding.

In one embodiment, the trained enhanced generative LLM can quickly learn and quickly update the external memory unit during inference (like the brain's hippocampus), thereby promoting an adaptivity of the enhanced generative LLM, which provides an integrated learning system like the human brain, and which further provides an advantage over the slow learning aspect of conventional implementations of a generative LLM.

In one embodiment, the enhanced generative LLM provides accurate, fast, and dynamic operations that read from, write into, denoise from, and generate from memory.

In one embodiment, the enhanced generative LLM improves language modeling by reducing reconstruction error and language perplexity, provides one-shot learning and generation during inference, even with out of distribution data, provides a fast and accurate knowledge update of the decoder during inference, and provides a fast and near perfect memory recall.

Computing Environment

System and Process for Enhancing a Generative LLM with an External Memory Unit

FIG. 2 is a block diagram of modules included in code 200 included in the system 100 of FIG. 1, in accordance with embodiments of the present invention. Code 200 includes a training module 202, a memory module 204, and an encoder and decoder module 206.

Training module 202 is configured to jointly train, end-to-end, (i) an encoder and a decoder included in a generative LLM and (ii) an external memory unit, which results in a joint optimization of the decoder and the external memory unit. As a result of the joint training, the generative LLM and external memory unit learn to store sentence encodings in a memory matrix, which is used during decoding performed by the decoder. The joint training ensures that the generative associative memory network set included in the external memory unit is sparsely distributed. That is, the capacity of the generative associative memory network set can be increased by reducing overlap between memory representations.

Memory module 204 is configured to augment the generative LLM with a global memory in the external memory unit, so that in response to an update to the global memory, the generative LLM can perform operations efficiently in accordance with the updated global memory, which can assist in updating knowledge and preventing hallucinations. The external memory unit is associative, generative, and sparsely distributed, stores episodic memories (i.e., information about a recent episode or a past episode), and consolidates stored episodic memories into a long-term memory. Memory module 204 is further configured to perform a fast update of the generative associative memory network set during an inference, thereby mimicking the hippocampus of the human brain and providing the generative LLM with a novel adaptivity to updated information, without requiring the traditional re-training or fine-tuning of the generative LLM.

Memory module 204 is further configured to provide fast and accurate memory operations, including a write into, a read from, a denoise from, and a generate from the generative associative memory. In one embodiment, memory module 204 provides other memory operations, such as free-form and prompt-based generation from a memory episode, memory retrieval with a partial or noisy prompt, memory update as a new data episode arrives, iterative denoising, and iterative memory update.

Memory module 204 is further configured to provide an improved language modeling which is indicated by an improvement in sentence reconstruction error and an improvement in language perplexity. Memory module 204 is further configured to provide one-shot learning and generation during an inference, even if the data is out of distribution (OOD) to what the model has been shown previously.

Memory module 204 is further configured to provide fast and accurate knowledge update of the decoder during an inference, fast and near perfect memory recall, and memory consolidation (i.e., consolidating recent (i.e., episodic) memories into long-term memories).

Encoder and decoder module 206 is configured to use a neural network as an encoder to generate a low-dimensional representation of a language input as a latent vector. Encoder and decoder module 206 is further configured to use a decoder to decode a memory encoding of the language input. Encoder and decoder module 206 is further configured to perform fast and accurate knowledge update of the decoder during an inference, without fine-tuning or re-training the generative LLM. Encoder and decoder module 206 is further configured to generate a response to a prompt during an inference. In one embodiment, the response generated by the encoder and decoder module 206 is based on the aforementioned knowledge update of the decoder.

The functionality of the modules included in code 200 is described in more detail in the discussions presented below relative to FIG. 3 through FIG. 13, inclusive.

FIG. 3 is a flowchart of a process of enhancing a generative LLM with an external memory unit, where operations of the flowchart are performed by the modules in FIG. 2, in accordance with embodiments of the present invention. The process of FIG. 3 begins at a start node 300. In step 302, training module 202 jointly trains an encoder, a decoder, and a generative associative memory network set. The encoder and decoder are included in a generative LLM. The generative associative memory network set is included in an external memory unit. The generative LLM is augmented with the external memory unit in a framework that enhances the generative LLM. The joint training performed in step 302 includes learning the store sentence encodings or language encodings in a memory matrix, which is used during a decoding performed by the decoder.

In step 304, memory module 204 updates the external memory unit with new information.

In step 306, using the new information in the updated external memory unit, encoder and decoder module 206 performs a knowledge update of the decoder during an inference, without fine-tuning or re-training the generative LLM.

In step 308, encoder and decoder module 206 generates a response to a prompt during the inference. The response is based on the knowledge update of the decoder, which was performed in step 306.

Following step 308, the process of FIG. 3 ends at an end node 310.

FIG. 4 is a block diagram of an overview 400 of an architecture for enhancing a generative LLM with an external memory unit, in accordance with embodiments of the present invention. Overview 400 includes a data input 402 (i.e., X), which is input into an encoder 404. Encoder 404 is a neural network included in the generative LLM. Encoder 404 outputs a latent vector 406 (i.e., z), which is the low-dimensional representation of X. The latent vector z is input into a memory 408, which is the generative associative memory included in the external memory unit that augments the generative LLM. Memory 408 is a fixed-size memory. Memory 408 outputs a latent vector 410 (i.e., z0), which is the memory encoding of X. The latent vector z0 is input into a decoder 412, which is another neural network included in the generative LLM. Decoder 412 outputs a data output 414 (i.e., X0). Again, training module 202 jointly trains and optimizes encoder 404, memory 408, and decoder 412. In another embodiment, memory 408 is replaced with a generative associative memory network set.

Memory 408 is a stand-alone module, which means that it is not added to, and remains separate from, encoder 404 and decoder 412. Memory 408 is generative (i.e., not deterministic), which means that memory writes and reads are inferences in a generative model, where memory 408 is treated as a distribution (i.e., p(M)). The framework that includes encoder 404, memory 408, and decoder 412 decouples the size of memory 408 from the input data size (i.e., the size of memory 408 is independent of the input data size, which provides improved scalability). Memory 408 adds only K×C+1 extra parameters to the original encoder-decoder model (i.e., a conventional generative LLM), where K is the number of slots desired for memory 408 and C is the latent dimension (i.e., the dimension of the aforementioned latent vector z).

One property of memory 408 is associativity, which means that any language input can be denoised. By having associativity, memory 408 can retrieve a remembered pattern based on a distorted or incomplete version.

Memory 408 is sparsely distributed, which means memory 408 can increase its capacity by reducing overlap between memory representations.

Memory 408 has another property of dynamic inference (i.e., memory update), which provides a fast update during an inference (e.g., a fast belief update in response to an arrival of a new data episode), thereby enabling fast episodic learning. The dynamic inference property of memory 4087 also allows a building of a new episode, and generating and learning from the new episode during an inference, with no request for a re-training of the generative LLM.

Another property of memory 408 is novel generation. That is, memory 408 enables an improved generation from memory 408 of a learned episode, as well as a generative replay.

Memory 408 also provides off-line replay, which enables memory consolidation.

Memory 408 also provides memory learning details whose writing and reading details are discussed below relative to FIG. 9. Other details related to memory learning details include training loss (i.e., the loss being used to train an instantiation of the framework that includes the enhanced generative LLM disclosed herein), which is defined as:

Training for the Framework May Also Include One or More of the Following Add-Ons:

Other details related to memory learning details include an inference, during which the following optimization problem is solved:

where W0 is the projection or keys of a specific sentence, M is the memory, and Zξ is the noisy version of the encoding. Inference may additionally include:

FIG. 5 is a table 500 presenting sample measurements of language model quality in relation to memory size, in accordance with embodiments of the present invention. Descriptions for acronyms in the column headers in table 500 are presented below:

Table 500 includes sample measurements that indicate that the training of the generative LLM with the generative associative memory network set leads to improved language model quality. For example, the negative log likelihood decreases as memory changes from no memory to a non-zero memory size, as indicated by comparing the 279.73 measurement under NLL (z) for the first row (i.e., 0 memory size) versus the lower NLL (z) measurements 54.51, 57.43, and 51.24 in the rows having memory sizes 128, 256, and 512, respectively. The decrease in the NLL indicates that the addition of the memory improves the language model quality. As another example, the perplexity measurement decreases as memory changes from no memory to a non-zero memory size (e.g., compare the 26.76 PPL value in table 500 corresponding to a 0 memory size to the lower PPL values of 3.73, 3.9986, and 4.29 corresponding to memory sizes of 128, 256, and 512, respectively). The decrease in PPL indicates that the addition of memory improves the language model quality.

FIG. 6 is a table 600 presenting measurements of language model quality in relation to model size, in accordance with embodiments of the present invention. Descriptions for the column headers in table 600 are presented below:

Table 600 includes sample measurements that indicate that improved language model quality correlates with increasing model size. For example, the perplexity measurements decrease (i.e., 3.71 to 2.67 to 2.15) as the model size increases (i.e., 247 M to 490 M to 922 M). The decrease in PPL indicates that the increase in model size improves the language model quality.

FIG. 7 depicts flowcharts 700 of a write operation 702 and a read operation 704 provided by the framework in the process of FIG. 3, in accordance with embodiments of the present invention. The flowcharts 700 include the write operation 702, which starts with a text dataset of facts or claims 706 being input into encoder 404. In step 710, encoder 404 encodes the facts or claims. Using the encoded facts or claims and a prior memory M0, encoder 404 computes a writing weight W0, which is then used to write the encoded facts or claims into memory 408 (i.e., a posterior memory M) as memory encodings. In step 712, encoder 404 evaluates the memory encodings (e.g., separation in latent space between facts with opposing polarity).

The flowcharts 700 include the read operation 704, which starts with a text dataset of generation prompts 714 being input into encoder 404, which encodes the prompts. Encoder 404 uses the encoded prompts and memory 408 to compute a reading weight W for memory conditioned reading. The matrix product of W and M calculates the memory read-out. Decoder 412 uses the memory read-out to generate the text dataset of prompt and memory conditioned generation 722 as output. An evaluation of the output includes (i) metrics to assess memory faithfulness 724 (e.g., factuality, robustness, fact edits, forgetting, etc.) and (ii) metrics to assess memory-agnostic generation quality 726 (e.g., fluency, consistency, perplexity, etc.).

FIG. 8 depicts flowcharts 800 of a write operation 702 and a generate operation 804 provided by the framework in the process of FIG. 3, in accordance with embodiments of the present invention. The flowcharts 800 include the write operation 702, which is described above relative to FIG. 7.

The flowcharts 700 includes the generate operation 804, which starts with a text dataset of generation prompts 714 being input into encoder 404, which encodes the prompts. Encoder 404 uses the encoded prompts and memory 408 to compute a generating weight W for memory conditioned generation. Decoder 412 uses W and memory 408 to generate the text dataset of prompt and memory conditioned generation 722 as output. An evaluation of the output includes (i) metrics to assess memory faithfulness 724 (e.g., factuality, robustness, fact edits, forgetting, etc.) and (ii) metrics to assess memory-agnostic generation quality 726 (e.g., fluency, consistency, perplexity, etc.).

FIG. 9 depicts details 900 of write and read operations provided by the framework in the process of FIG. 3, in accordance with embodiments of the present invention. Details 900 include details of a process 902 for writing provided by the framework. Process 902 includes four steps. In step 1 of process 902, the episode embedding Z=e(X) is computed. That is, encoder 404 encodes an episode X as Z. In step 2, encoder 404 randomizes noise ξ from N(0,σξ2I). In step 3, encoder 404 computes an estimated weight W0=ZξM0+, where W0 is the writing weight and M0 is the prior memory. In step 4, encoder 404 computes posterior memory M=W0+Zξ.

Details 900 include details of a process 904 for reading provided by the aforementioned framework. Process 904 includes five steps. In step 1 of process 904, encoder 404 computes episode embedding Z=e(X) (e.g., the query Xq is encoded as Zq). In step 2, encoder 404 computes the reading weight mean W=ZM+. In step 3, if generating (instead of reading) from memory is being performed, then encoder 404 uses a variational schema for generating samples, i.e., W˜N(W, σW2I). In step 4, encoder 404 computes the memory read-out Zread-out=WM (i.e., the matrix product of W and M). Although not shown in FIG. 9, in a step following step 4, the decoder 412 uses Zread-out to generate the output X0 of the reading phase. In step 5, if iterative reading is included during an inference, encoder 404 computes reconstruction X=d(Zread-out) and X is fed back to encoder 404 in step 1 of process 904 (i.e., for the next reading step).

FIG. 10 is an example 1000 of read, write, and generate operations provided by the framework in the process of FIG. 3, in accordance with embodiments of the present invention. In the line labeled “[38],” example 1000 includes a sample write into memory 408 happening in real time during an inference.

In lines labeled “[40],” “[42],” and “[44],” example 1000 includes samples of an operation that reads from memory 408, which asks the language model to read that the spicy dishes are x.

In lines labeled “[46],” “[47],” and “[52],” example 1000 includes samples of operations that generate from memory 408 without a prompt. For instance, in line [46], the language model generated “All the food was great.”

In lines labeled “[59]” and “[80],” example 1000 includes samples of operations that generate from memory 408 with a prompt. For example, with the prompt “The restaurant has spicy” in line [59], the language model generated “The restaurant has spicy wanyaki.”

FIG. 11 is a block diagram of model training 1100 on unlabeled sentences, as included in the process of FIG. 3, in accordance with embodiments of the present invention. Model training 1100 can include writing, reading, and generating sentences from memory 408 and starts with an episode of unlabeled sentences from a large text corpus 1102, which is input into encoder 404. Encoder 404 outputs a low-dimensional representation of the episode of sentences 1102. In response, the low-dimensional representation is input into memory 408, which outputs a memory encoding of the episode of sentences 1102. The memory encoding is input into decoder 412. In response, decoder 412 generates an episode of generated sentences 1104 as data output. The model training 1100 is subject to training loss that can include reconstruction loss, AE loss, KL loss, language modeling (LM) loss, etc. Definitions of reconstruction loss, AE loss, and KL loss are found in the discussion of FIG. 4, presented above.

FIG. 12 is a block diagram of model training 1200 on labeled sentences, as included in the process of FIG. 3, in accordance with embodiments of the present invention. Model training 1200 can include writing, reading, and generating sentences from memory 408 using label guidance and starts with an episode of labeled sentences from a large text corpus 1202, which is input into encoder 404. Encoder 404 outputs a low-dimensional representation of the episode of labeled sentences 1202. In response, the low-dimensional representation is input into memory 408, which outputs a memory encoding of the episode of labeled sentences 1202. The memory encoding is input into decoder 412. In response, decoder 412 generates a label (constrained): episode of generated sentences 1204 as data output. The model training 1200 is subject to training loss that can include reconstruction loss, AE loss, KL loss, LM loss, etc. Definitions of reconstruction loss, AE loss, and KL loss are found in the discussion of FIG. 4, presented above.

FIG. 13 is a block diagram of a model training 1300 on labeled sentences using a positive label memory and a negative label memory, in accordance with embodiments of the present invention. Model training 1300 illustrates how the enhanced generative LLM can influence the LLM decoder with different memories. Model training 1300 starts with an episode of labeled sentences from a large text corpus 1302, which is input into encoder 404. Encoder 404 outputs low-dimensional representations of the episode of labeled sentences 1302, thereby sending any representation (i.e., sample) having a positive class label to positive label memory 1304 and sending any representation having a negative class label to negative label memory 1306. In this case, each of the samples complies to one of the two classes (i.e., positive class or negative class). Thus, positive label memory 1304 has knowledge of the samples with positive class labels and negative label memory 1306 has knowledge of the samples with negative class labels. The classes can be representative of different topics, sentiments, or tenses. Positive label memory 1304 and negative label memory 1306 output memory encodings of the samples from episode of labeled sentences 1302. The memory encodings are input into decoder 412. In response, decoder 412 generates a label (constrained) episode of generated sentences 1308 as data output. The model training 1300 is subject to training loss that can include reconstruction loss, AE loss, KL loss, LM loss, etc. Definitions of reconstruction loss, AE loss, and KL loss are found in the discussion of FIG. 4, presented above.

FIG. 14 is an example 1400 of knowledge updating in the process of FIG. 3, in accordance with embodiments of the present invention. Example 1400 illustrates that the enhanced generative LLM disclosed herein provides fast and efficient knowledge updating (also referred to as knowledge editing) as compared to a conventional language model (e.g., GPT-NeoX-20B). Knowledge editing techniques for a conventional language model rely on re-training of the model or finding out where to edit within the model (i.e., fine-tuning of the model). For the enhanced generative LLM disclosed herein, knowledge editing does not need re-training or finding out where to edit within the model because the knowledge edit is immediately reflected in an update to memory 408, which is a global memory.

When two boxes are shown in a single row in FIG. 14, the box on the left corresponds to a response provided by the conventional language model, and the box on the right corresponds to the enhanced generative LLM disclosed herein. An “x” indicator in a box indicates that the response in that box is false, while a checkmark indicator in a box indicates that the response in that box is true.

In step 1402, two facts are shown for each of the two models to remember: “ABC is in healthcare business” and “XYZ provides retail service.” In step 1404, each of the two models receives the prompt “XYZ offers.”

In response to the prompt, the conventional language model generates a response 1406 (i.e., “a wide range of financial services”), which is false, while the enhanced generative LLM generates a response 1408 (i.e., “XYZ offers retail service”), which is true. Being a large model, the conventional language model avoids frequent re-training and fine-tuning, so the facts shown in step 1402 are not yet part of a knowledge edit in the conventional language model. On the other hand, the global memory used by the enhanced generative LLM disclosed herein is quickly updated with the facts shown in step 1402, so response 1408 incorporates the knowledge edit without delay.

In step 1410, a fact of “XYZ provides retail service” is unlearned from each of the two models.

In step 1412, each of the two models is prompted with “ABC offers.” In response to the prompt, the conventional language model generates a response 1414 (i.e., “a wide range of financial services”), which is false, and the enhanced generative LLM generates a response 1416 (i.e., “ABC offers in healthcare business”), which is true. Again, the difference between response 1414 and 1416 reflects how the conventional language model has not yet completed a knowledge edit with the facts shown in step 1402, while the enhanced generative LLM can incorporate the knowledge edit in response 1416 because the global memory is quickly updated with the knowledge edit.

In step 1418, each of the models receives the prompt, “XYZ offers.” In response to the prompt in step 1418, the conventional language model generates a response 1420 (i.e., “a wide range of financial services”), which is false. In response to the prompt, the enhanced generative LLM disclosed herein generates a response 1422 (i.e., “I don't know”), which is true because the fact about the service provided by XYZ was unlearned in step 1410 and this unlearning edit is quickly available to the enhanced generative LLM via the global memory.