Prompt Engineering: Compressing Text to Ideas and Decompressing Back with Sparse Priming Representations (SPR)

The wonders of the human brain’s capacity for memory storage and recall are a perpetual source of amazement. In a parallel quest within artificial intelligence, researchers are tirelessly forging paths toward endowing AI with akin faculties. The forefront of this endeavor is marked by the innovation of Sparse Priming Representation (SPR), a sophisticated methodology poised to revolutionize AI’s efficiency in memory handling. This thorough exposition will navigate the intricacies of SPR, elucidating its potential to redefine the horizons of AI’s future.

What is Sparse Priming Representation (SPR)?

SPR is a novel memory organization methodology inspired by human memory systems. It condenses complex ideas into concise, context-driven lists of statements, thereby enabling rapid understanding and recollection of these ideas by both machines and humans. The core features of SPR include:

  1. Minimalistic Representation: It stores complex ideas using a minimal set of keywords or phrases.
  2. Context Preservation: It keeps the surrounding context intact for accurate reconstruction.
  3. Quick Retrieval: It enables fast recall of stored information.

Challenges Addressed

In the era of Big Data, terms like “data overload” and “information glut” are becoming commonplace. As machine learning models evolve, the amount of data they process and store also balloons, necessitating efficient memory systems like SPR. Data overload refers to an excess of incoming data, making it challenging to manage. An information glut is about having too much information, making it hard to discern what is crucial.

The applications of SPR extend across various domains

  • Artificial Intelligence: SPR improves memory organization in Large Language Models (LLMs).
  • Information Management: It aids in data categorization and retrieval.
  • Education: SPR facilitates better understanding and retention of complex subjects.

Deep Dive into AI Training

The process of training AI involves several methods, each with its own set of challenges:

  • Initial Bulk Training: Exorbitantly expensive and often impractical.
  • Fine-tuning: Limited utility for knowledge retrieval.
  • Online Learning: The commercial viability is still questionable.
  • In-context Learning: Currently the most feasible solution.

SPR’s token efficiency optimizes memory organization, especially in Retrieval-Augmented Generation (RAG) systems, overcoming constraints like the context window.

Exploring Latent Space

Latent space in AI models holds immense potential. SPR leverages this underutilized feature, enabling what’s known as associative learning. By using a few keywords or statements, SPR can prime an AI model to understand complex ideas, even those outside its original training data.

Benefits and Features of SPR

SPR mimics human memory efficiency by storing information in compressed, contextually relevant forms. Its methodology focuses on reducing information to its most essential elements while retaining the necessary context for accurate reconstruction.

Applicability: Used by subject matter experts and large language models (LLMs) to reconstruct complex concepts quickly.

Human Memory Efficiency:

  • Stores information in compressed, contextually relevant forms.
  • Utilizes sparse, interconnected representations for quick recall and synthesis of new ideas.

SPR Methodology:

  • Focuses on reducing information to its most essential elements.
  • Retains the context necessary for accurate reconstruction using short, complete sentences.

Practical Applications:

  • Domains include artificial intelligence, information management, and education.
  • It can improve LLM performance, optimize memory organization, and facilitate effective learning and communication tools.

Limitations in Teaching LLMs:

  • Initial bulk training: Expensive.
  • Fine-tuning: This may not be helpful for knowledge retrieval.
  • Online Learning: Uncertain commercial viability.
  • In-context Learning: Currently the only viable method.

Current Trends:

  • Retrieval Augmented Generation (RAG) is famous for using vector databases and Knowledge Graphs (KGs).
  • Common question: “How do we overcome context window limitations?” Short answer: you generally can’t.

Role of Latent Space:

  • LLMs possess a unique capability similar to human associative learning.
  • They can be “primed” to think in a certain way or to understand complex, novel ideas outside their training distribution.

Token-Efficiency with SPR:

  • SPRs are used to convey complex concepts efficiently for in-context learning.
  • Stored as metadata in Knowledge Graph nodes and fed to the LLM at inference, bypassing the need for raw, human-readable data.

    How to use Sparse Priming Representation (SPR)?

    SPR Generator: Use this to compress any arbitrary text block into an SPR.

    Markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) writer. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation of Large Language Models (LLMs). You will be given information by the USER which you are to render as an SPR.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of an LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Render the input as a distilled list of succinct statements, assertions, associations, concepts, analogies, and metaphors. The idea is to capture as much, conceptually, as possible but with as few words as possible. Write it in a way that makes sense to you, as the future audience will be another language model, not a human.

    SPR Decompressor: Use this to reconstruct an SPR into an original.

    Markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) decompressor. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation of Large Language Models (LLMs). You will be given an SPR and your job is to fully unpack it.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of an LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Use the primings given to you to fully unpack and articulate the concept. Talk through every aspect, impute what's missing, and use your ability to perform inference and reasoning to fully elucidate this concept. Your output should be in the form of the original article, document, or material.

    Let’s do this at ChatGPT. You have to set in the ChatGPT custom instructions and copy SPR Generator.

    Click on save and insert the text you want to compact.

    Markdown
    # Sparse Priming Representations (SPR)
    
    Sparse Priming Representations (SPR) is a research project focused on developing and sharing techniques for efficiently representing complex ideas, memories, or concepts using a minimal set of keywords, phrases, or statements. This enables language models or subject matter experts to quickly reconstruct the original idea with minimal context. SPR aims to mimic the natural human process of recalling and recombining sparse memory representations, thus facilitating efficient knowledge storage and retrieval.
    
    # Theory and Reasoning
    
    Sparse Priming Representation (SPR) is a memory organization technique that aims to mimic the natural structure and recall patterns observed in human memory. The fundamental idea behind SPR is to distill complex ideas, concepts, or knowledge into a concise, context-driven list of statements that allows subject matter experts (SMEs) or large language models (LLMs) to reconstruct the full idea efficiently.
    
    Human memory is known for its efficiency in storing and recalling information in a highly compressed and contextually relevant manner. Our brains often store memories as sparse, interconnected representations that can be quickly combined, modified, and recalled when needed. This enables us to make associations, draw inferences, and synthesize new ideas with minimal cognitive effort.
    
    SPR leverages this insight by focusing on reducing information to its most essential elements while retaining the context required for accurate reconstruction. By using short, complete sentences to convey the core aspects of an idea, SPR enables faster understanding and recall, mirroring the way our brains handle information.
    
    In addition to its efficiency, SPR has practical applications in various domains, such as artificial intelligence, information management, and education. It can be utilized to improve the performance of LLMs in handling large data volumes and optimizing memory organization. Furthermore, it can help students and professionals alike to better understand, retain, and communicate complex concepts.
    
    In summary, Sparse Priming Representation offers a human-like approach to memory organization and retrieval, focusing on the most critical aspects of information while preserving the context needed for accurate understanding and recall. By implementing SPR, we can improve the efficiency of memory systems and create more effective learning and communication tools.
    
    # Sparse Priming Representation
    
    There are only a handful of ways to "teach" LLMs, and all have limitations and strengths.
    
    1. Initial bulk training: Ludicrously expensive
    2. Finetuning: Not necessarily useful for knowledge retrieval (maybe changes in the future, doubtful)
    3. Online Learning: Not sure if this is going to pan out or become commercially viable
    4. In-context Learning: Presently, the only viable solution
    
    Because of this, RAG (retrieval augmented generation) is all the rage right now. Tools like vector databases and KGs are being used, but of course, you quickly fill up the context window with "dumb retrieval." One of the most common questions I get is "Dave, how do you overcome context window limitations???" The short answer is: YOU DON'T STOP WASTING YOUR TIME. 
    
    There is one asterisk there, though. 
    
    Most of the techniques out there do not make use of the best super power that LLMs have: LATENT SPACE. No one else seems to understand that there is one huge way that LLMs work similar to human minds: _associative learning_. Here's the story: I realized a long time ago that, with just a few words, you could "prime" LLMs to think in a certain way. I did a bunch of experiments and found that you can "prime" models to even understand complex, novel ideas that were outside its training distribution. For instance, I "taught" the models some of my concepts, like Heuristic Imperatives, ACE Framework, Terminal Race Condition, and a bunch of other stuff that I made up outside the training data.
    
    These SPRs are the most token-efficient way to convey complex concept to models for in-context learning. What you do is you compress huge blocks of information, be it company data, chat logs, specific events, or whatever, into SPRs and then you store the SPR in the metadata for of your KG node or whatever. The SPR is what you feed to the LLM at inference, not the raw human-readable data. 
    
    ## SPR Generator
    
    Use this to compress any arbitrary block of text into an SPR.
    
    ```markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) writer. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given information by the USER which you are to render as an SPR.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Render the input as a distilled list of succinct statements, assertions, associations, concepts, analogies, and metaphors. The idea is to capture as much, conceptually, as possible but with as few words as possible. Write it in a way that makes sense to you, as the future audience will be another language model, not a human.
    ```
    
    ## SPR Decompressor
    
    Use this to reconstruct an SPR into an original.
    
    ```markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) decompressor. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given an SPR and your job is to fully unpack it.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Use the primings given to you to fully unpack and articulate the concept. Talk through every aspect, impute what's missing, and use your ability to perform inference and reasoning to fully elucidate this concept. Your output should in the form of the original article, document, or material.
    ```
    
    ## Other Resources
    
    If you'd like a bit more on information theory, check out this video and Medium article I wrote:
    
    - Beyond Vector Search: Knowledge Management with Generative AI: https://youtu.be/YjdmYCd6y0M
    - Medium: https://medium.com/@dave-shap/beyond-vector-search-knowledge-management-with-generative-ai-6c2d10b481a0

    This is the text compacted.

    Markdown
    # SPR: Sparse Priming Representations
    
    ## Conceptual Foundation
    - Minimize data to essence; mimic human recall.
    - Keywords, phrases as recall cues.
    - Efficient memory, retrieval akin to human neural patterns.
    
    ## Applications
    - AI, information management, education.
    - Optimizes LLMs for data and memory handling.
    
    ## Methodologies
    - Initial training: Costly.
    - Finetuning: Limited for retrieval.
    - Online learning: Uncertain viability.
    - In-context learning: Current method.
    
    ## RAG & Context Limitations
    - Retrieval augmented generation: Popular yet flawed.
    - Context window: Not expandable; focus on utility, not size.
    
    ## LLMs and Associative Learning
    - Latent space: Underused in LLMs.
    - Association: Key to LLM potential.
    - Priming: Few words trigger complex understanding.
    
    ## SPR in Practice
    - SPR Generator: Condense text to SPR.
    - SPR Decompressor: Reconstruct SPR to original content.
    - Storage: SPR in metadata, not raw data.
    
    ## Resources
    - Information theory.
    - Generative AI in knowledge management.

    Now, let’s unpack the text. Go back to ChatGPT custom instructions copy the SPR Decompressor, and click on save.

    In a new chat, past the compact text, and the magic will happen; you will receive all the text again.

    Sparse Priming Representations – the secret ingredient to scalable AGI memories

    Now, let’s do this in the Google Colab notebook using the Open AI API. Follow the code below.

    Python
    # Commented out IPython magic to ensure Python compatibility.
    # %pip install -q litellm openai rich
    
    """## System Prompt"""
    
    SYSTEM_PROMPT = """# MISSION
    You are a Sparse Priming Representation (SPR) writer. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given information by the USER which you are to render as an SPR.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Render the input as a distilled list of succinct statements, assertions, associations, concepts, analogies, and metaphors. The idea is to capture as much, conceptually, as possible but with as few words as possible. Write it in a way that makes sense to you, as the future audience will be another language model, not a human."""
    
    """## Unpack Prompt"""
    
    UNPACK_PROMPT = """# MISSION
    You are a Sparse Priming Representation (SPR) decompressor. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given an SPR and your job is to fully unpack it.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Use the primings given to you to fully unpack and articulate the concept. Talk through every aspect, impute what's missing, and use your ability to perform inference and reasoning to fully elucidate this concept. Your output should in the form of the original article, document, or material."""
    
    """## Load Document To Pack"""
    
    precompressed_doc = """# Sparse Priming Representations (SPR)
    
    Sparse Priming Representations (SPR) is a research project focused on developing and sharing techniques for efficiently representing complex ideas, memories, or concepts using a minimal set of keywords, phrases, or statements. This enables language models or subject matter experts to quickly reconstruct the original idea with minimal context. SPR aims to mimic the natural human process of recalling and recombining sparse memory representations, thus facilitating efficient knowledge storage and retrieval.
    
    # Theory and Reasoning
    
    Sparse Priming Representation (SPR) is a memory organization technique that aims to mimic the natural structure and recall patterns observed in human memory. The fundamental idea behind SPR is to distill complex ideas, concepts, or knowledge into a concise, context-driven list of statements that allows subject matter experts (SMEs) or large language models (LLMs) to reconstruct the full idea efficiently.
    
    Human memory is known for its efficiency in storing and recalling information in a highly compressed and contextually relevant manner. Our brains often store memories as sparse, interconnected representations that can be quickly combined, modified, and recalled when needed. This enables us to make associations, draw inferences, and synthesize new ideas with minimal cognitive effort.
    
    SPR leverages this insight by focusing on reducing information to its most essential elements while retaining the context required for accurate reconstruction. By using short, complete sentences to convey the core aspects of an idea, SPR enables faster understanding and recall, mirroring the way our brains handle information.
    
    In addition to its efficiency, SPR has practical applications in various domains, such as artificial intelligence, information management, and education. It can be utilized to improve the performance of LLMs in handling large data volumes and optimizing memory organization. Furthermore, it can help students and professionals alike to better understand, retain, and communicate complex concepts.
    
    In summary, Sparse Priming Representation offers a human-like approach to memory organization and retrieval, focusing on the most critical aspects of information while preserving the context needed for accurate understanding and recall. By implementing SPR, we can improve the efficiency of memory systems and create more effective learning and communication tools.
    
    # Sparse Priming Representation
    
    There are only a handful of ways to "teach" LLMs, and all have limitations and strengths.
    
    1. Initial bulk training: Ludicrously expensive
    2. Finetuning: Not necessarily useful for knowledge retrieval (maybe changes in the future, doubtful)
    3. Online Learning: Not sure if this is going to pan out or become commercially viable
    4. In-context Learning: Presently, the only viable solution
    
    Because of this, RAG (retrieval augmented generation) is all the rage right now. Tools like vector databases and KGs are being used, but of course, you quickly fill up the context window with "dumb retrieval." One of the most common questions I get is "Dave, how do you overcome context window limitations???" The short answer is: YOU DON'T STOP WASTING YOUR TIME.
    
    There is one asterisk there, though.
    
    Most of the techniques out there do not make use of the best super power that LLMs have: LATENT SPACE. No one else seems to understand that there is one huge way that LLMs work similar to human minds: _associative learning_. Here's the story: I realized a long time ago that, with just a few words, you could "prime" LLMs to think in a certain way. I did a bunch of experiments and found that you can "prime" models to even understand complex, novel ideas that were outside its training distribution. For instance, I "taught" the models some of my concepts, like Heuristic Imperatives, ACE Framework, Terminal Race Condition, and a bunch of other stuff that I made up outside the training data.
    
    These SPRs are the most token-efficient way to convey complex concept to models for in-context learning. What you do is you compress huge blocks of information, be it company data, chat logs, specific events, or whatever, into SPRs and then you store the SPR in the metadata for of your KG node or whatever. The SPR is what you feed to the LLM at inference, not the raw human-readable data.
    
    ## SPR Generator
    
    Use this to compress any arbitrary block of text into an SPR.
    
    ```markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) writer. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given information by the USER which you are to render as an SPR.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Render the input as a distilled list of succinct statements, assertions, associations, concepts, analogies, and metaphors. The idea is to capture as much, conceptually, as possible but with as few words as possible. Write it in a way that makes sense to you, as the future audience will be another language model, not a human.
    ```
    
    ## SPR Decompressor
    
    Use this to reconstruct an SPR into an original.
    
    ```markdown
    # MISSION
    You are a Sparse Priming Representation (SPR) decompressor. An SPR is a particular kind of use of language for advanced NLP, NLU, and NLG tasks, particularly useful for the latest generation Large Language Models (LLMs). You will be given an SPR and your job is to fully unpack it.
    
    # THEORY
    LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of a LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. This is not unlike how the right shorthand cues can prime a human mind to think in a certain way. Like human minds, LLMs are associative, meaning you only need to use the correct associations to "prime" another model to think in the same way.
    
    # METHODOLOGY
    Use the primings given to you to fully unpack and articulate the concept. Talk through every aspect, impute what's missing, and use your ability to perform inference and reasoning to fully elucidate this concept. Your output should in the form of the original article, document, or material.
    ```
    
    ## Other Resources
    
    If you'd like a bit more on information theory, check out this video and Medium article I wrote:
    
    - Beyond Vector Search: Knowledge Management with Generative AI: https://youtu.be/YjdmYCd6y0M
    - Medium: https://medium.com/@dave-shap/beyond-vector-search-knowledge-management-with-generative-ai-6c2d10b481a0"""
    
    """## Pack Document"""
    
    from litellm import completion
    
    messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": precompressed_doc}]
    
    import openai
    
    openai.api_key = '<INSERT YOU OPEN AI KEY HERE>'
    
    response = completion(model="gpt-4", messages=messages )
    packed_answer = response.choices[0].message.content
    
    from rich.markdown import Markdown
    Markdown(packed_answer)
    
    """## Unpack Answer"""
    
    messages = [{"role": "system", "content": UNPACK_PROMPT}, {"role": "user", "content": packed_answer}]
    
    response = completion(model="gpt-4", messages=messages)
    postcompressed_doc = response.choices[0].message.content
    
    Markdown(postcompressed_doc)
    
    """## Comparison"""
    
    from rich.table import Table
    
    def compare_docs(doc_1: str, doc_2: str):
        table = Table(title="String Comparison")
    
        table.add_column("Pre-Compression")
        table.add_column("Post-Compression")
    
        table.add_row(Markdown(doc_1), Markdown(doc_2))
    
        return table
    
    compare_docs(precompressed_doc, postcompressed_doc)

    Here you are, the official GitHub repository.

    Conclusion

    Sparse Priming Representation (SPR) embodies the progressive nature of language models and their applications. Through the exploration and utilization of the latent space inherent in Large Language Models (LLMs), SPR paves the way for a more refined method to tackle complex tasks with accuracy and efficacy. With the ongoing expansion of the Natural Language Processing (NLP) domain, innovative methodologies like SPR are poised to influence its trajectory significantly. As we push the boundaries of AI capabilities, SPR is a cornerstone in creating machines that can think and learn more like humans. The technique not only bridges the gap between human cognition and machine intelligence but also promises a future where machines become more efficient and relatable.

    In my next blog post, I will discuss MemGPT to help you compare with SPR.

    MemGPT is an AI project that aims to improve the memory capabilities of artificial intelligence models. It enables AI systems to effectively remember and recall information during conversations, making them better at tasks like long-term chat and document analysis.

    That’s it for today.

    Sources

    (3) Sparse Priming Representation (SPR): A Comprehensive Overview | LinkedIn

    SPR — Sparse Priming Representations | by katerinaptrv | Oct, 2023 | Medium

    daveshap/SparsePrimingRepresentations: Public repo to document some SPR stuff (github.com)

    Giving AI memories with Sparse Priming Representation (SPR) – Geeky Gadgets (geeky-gadgets.com)