<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayodele Oniosun</title>
    <description>The latest articles on DEV Community by Ayodele Oniosun (@ayodeleoniosun).</description>
    <link>https://dev.to/ayodeleoniosun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054872%2Fc4e78571-1f78-4ba5-9088-6b764058cc60.png</url>
      <title>DEV Community: Ayodele Oniosun</title>
      <link>https://dev.to/ayodeleoniosun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayodeleoniosun"/>
    <language>en</language>
    <item>
      <title>Say More with Less - Prompt Compression</title>
      <dc:creator>Ayodele Oniosun</dc:creator>
      <pubDate>Mon, 30 Nov 2026 08:31:23 +0000</pubDate>
      <link>https://dev.to/ayodeleoniosun/say-more-with-less-prompt-compression-4n98</link>
      <guid>https://dev.to/ayodeleoniosun/say-more-with-less-prompt-compression-4n98</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;When telling a story or sharing information, there are two types of people: Those who say less with more words and those who say more with less words.&lt;/p&gt;

&lt;p&gt;Picture two people trying to share the exact same update with their team:&lt;/p&gt;

&lt;p&gt;Category 1:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Apologies, one more thing, there’s been a slight change to our meeting. We were originally going to meet on Thursday, but we’ve decided to move it to Friday and we will stick with 10 a.m. And one last thing before I let you go. Please remember to bring your laptop, because you’ll be needing it and please be punctual, as we want to start by exactly 10 a.m.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Category 2:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Apologies everyone. The meeting has been moved to Friday at 10 a.m. Bring your laptop and be punctual.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You’ve most likely met both categories.&lt;/p&gt;

&lt;p&gt;The first category can be exhausting, especially when they speak slowly, because they waste time with filler and repetition. The second category respects your time, gets straight to the point, and communicates more clearly.&lt;/p&gt;

&lt;p&gt;This mirrors how many of us approach AI prompting.&lt;/p&gt;

&lt;p&gt;AI is everywhere right now, and you don’t need to be a tech expert to put it to work on all kinds of tasks.&lt;/p&gt;

&lt;p&gt;However, you should be conscious of how your tokens get exhausted faster, especially when you’ve got a lot on your plate and a limited budget.&lt;/p&gt;

&lt;p&gt;Did I say &lt;em&gt;tokens&lt;/em&gt;? Yes, tokens.&lt;/p&gt;

&lt;p&gt;Let’s get a bit technical with one more illustration.&lt;/p&gt;

&lt;h1&gt;
  
  
  What’s a Token?
&lt;/h1&gt;

&lt;p&gt;Imagine teaching a child how to read and write.&lt;/p&gt;

&lt;p&gt;Instead of taking in an entire word at once, the child starts by recognizing individual letters and letter combinations to piece each word together in their head.&lt;/p&gt;

&lt;p&gt;For example, a child just learning to read might come across the word &lt;code&gt;Unbelievable&lt;/code&gt;. They’ll pronounce the smaller pieces, &lt;code&gt;Un&lt;/code&gt;, &lt;code&gt;believ&lt;/code&gt; and &lt;code&gt;able&lt;/code&gt;, individually to figure out the pronunciation, which might turn out right or wrong.&lt;/p&gt;

&lt;p&gt;As they grow and become stronger readers, they start reading sentences word by word, rarely needing to break them down into letters or smaller chunks anymore.&lt;/p&gt;

&lt;p&gt;AI, on the other hand, doesn’t read sentences as a whole, but rather breaks them down into smaller chunks called &lt;strong&gt;tokens&lt;/strong&gt; via tokenizers.&lt;/p&gt;

&lt;p&gt;A token might be a whole word, part of a word, a space, or even a punctuation mark. &lt;/p&gt;

&lt;p&gt;As a rough guide, &lt;a href="https://help.openai.com/en/articles/4936856-understanding-and-counting-tokens" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt; estimates that a token generally corresponds to ~4 characters of text for common English text. This translates to roughly ¾ of a word (so 100 tokens ~= 75 words).&lt;/p&gt;

&lt;p&gt;The exact token count depends on the text and the tokenizer. &lt;/p&gt;

&lt;p&gt;Models within and across families can share a tokenizer, and different tokenizers can split the same text in different ways.&lt;/p&gt;

&lt;p&gt;Each token maps to a number called a token ID. &lt;/p&gt;

&lt;p&gt;The model uses that ID to look up an embedding, which is a set of numbers that represents the token in its calculations. It then uses the context and patterns it learned during training to predict which token could come next to build its response.&lt;/p&gt;

&lt;p&gt;Take the word &lt;code&gt;unbelievable&lt;/code&gt; as an example.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;th&gt;Token IDs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI GPT-5.x&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;un&lt;/code&gt;, &lt;code&gt;bel&lt;/code&gt;, &lt;code&gt;ievable&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[373, 9880, 45794]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI GPT-4&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;un&lt;/code&gt;, &lt;code&gt;bel&lt;/code&gt;, &lt;code&gt;ievable&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[359, 32898, 24694]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Anthropic Claude Sonnet 5.5&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;un&lt;/code&gt;, &lt;code&gt;belie&lt;/code&gt;, &lt;code&gt;vable&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All three examples produce 3 tokens. &lt;/p&gt;

&lt;p&gt;The two GPT tokenizers split the word into the same tokens but with different token IDs. &lt;/p&gt;

&lt;p&gt;The Claude example shows how a tokenizer can split the word into an entirely different token but with the same token count.&lt;/p&gt;

&lt;p&gt;Having grasped a basic understanding of how tokens work, let’s now look at the two major types of tokens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Input tokens:&lt;/strong&gt; These are tokens in the content supplied to the model for a request, which can be your prompt, system instructions, conversational history or attached documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output tokens:&lt;/strong&gt; These are tokens generated by AI in response to your input.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  How LLM APIs charge for tokens
&lt;/h1&gt;

&lt;p&gt;When you use a commercial LLM API, whether OpenAI, Gemini, or Anthropic, the provider typically tracks how many tokens a request uses. &lt;/p&gt;

&lt;p&gt;Providers charge different rates for input and output tokens. Some even also offer a discounted rate for cached input tokens, which are eligible tokens from a reused portion of the input. &lt;/p&gt;

&lt;p&gt;Rates are often quoted per million tokens and vary by provider and model.&lt;/p&gt;

&lt;p&gt;You can view different model pricing here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/pricing" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aistudio.google.com/docs/pricing" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://claude.com/pricing#api" rel="noopener noreferrer"&gt;Anthropic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more verbose your prompt is, the higher the input tokens, and this can be hundreds or even thousands of tokens per request.&lt;/p&gt;

&lt;p&gt;Many commercial LLM APIs charge a higher rate for output tokens than for input tokens.&lt;/p&gt;

&lt;p&gt;While you can’t always control how many output tokens an LLM generates, you have significant control over your input tokens.&lt;/p&gt;

&lt;p&gt;So, how do you cut down your input tokens without sacrificing response quality? &lt;/p&gt;

&lt;p&gt;How do you say more with less, keeping all the key facts intact, while slashing token usage by over 40% and getting faster, sharper responses?&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;Prompt Compression&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Prompt Compression?
&lt;/h1&gt;

&lt;p&gt;Prompt compression is simply an optimization technique for shortening a long, verbose prompt before sending the request to an LLM, while preserving the essential meaning and the instructions that the model needs.&lt;/p&gt;

&lt;p&gt;Think of it like leaving a sticky note for a coworker or writing a text message, being fully aware of the character limit. You strip out words that are fluff and keep only the words that pass across the important information and trigger action.&lt;/p&gt;

&lt;p&gt;I put this into practice during a token usage audit for &lt;a href="https://prepmie.com" rel="noopener noreferrer"&gt;Prepmie&lt;/a&gt;, a product I’m building to help learners turn their study materials into guided study sessions and prepare for exams. I found repeated instructions and wording that could be shortened without changing the task.&lt;/p&gt;

&lt;p&gt;After rewriting those prompt templates, I measured roughly 45% fewer tokens in the templates themselves. The accuracy of the LLM response was noticeably improved as well.&lt;/p&gt;

&lt;p&gt;You can do the same and achieve even better results with prompt compression.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Prompt Compression Matters
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lower Token Usage &amp;amp; Cost Savings.&lt;/strong&gt; This is the biggest win.&lt;/p&gt;

&lt;p&gt;LLMs bill you based on the number of input, cached, and output tokens they process.&lt;/p&gt;

&lt;p&gt;If done right, prompt compression can cut your input tokens by up to 40% without hurting response quality.&lt;/p&gt;

&lt;p&gt;It’s important to note that the prompt you shorten may be only one part of the API request. The model may also receive conversational history, retrieved documents or tool definitions. If the compressed prompt uses 30 fewer tokens and the rest of the request stays the same, then, the full request uses 30 fewer input tokens.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Latency.&lt;/strong&gt; A compressed prompt can reduce the work the model does before it starts generating, which may improve time to first token. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Improved Performance.&lt;/strong&gt; Long, verbose prompts can overwhelm LLMs and cause them to lose contextual accuracy. &lt;/p&gt;

&lt;p&gt;Compressed prompts enhance the output model’s quality by focusing on the most relevant information in the prompt.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With prompt compression, redundant instructions are eliminated from the prompt, key facts are preserved, input tokens and LLM costs are reduced and decision-making is faster for the model.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prompt Compression Techniques
&lt;/h1&gt;

&lt;p&gt;Like most technical concepts, prompt compression comes with both traditional and advanced techniques.&lt;/p&gt;

&lt;p&gt;While the advanced techniques save time and do the heavy lifting for you, understanding the fundamentals and knowing how to compress prompts manually first is key.&lt;/p&gt;

&lt;p&gt;In this section, I will walk you through both ends of the spectrum.&lt;/p&gt;

&lt;p&gt;Better yet, these techniques work regardless of whether you’re using ChatGPT, Claude, Gemini, or any other LLM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Traditional Compression Techniques
&lt;/h2&gt;

&lt;p&gt;Traditional compression techniques require no tooling or dependencies.&lt;/p&gt;

&lt;p&gt;If done carefully, it reduces the input tokens by up to 50% or more, and does not lead to quality regression.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The token counts for the original and compressed prompts below are estimates based on OpenAI GPT-5.x tokenizers. As mentioned earlier, the same text can yield different token counts depending on the tokenizers&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A simple token reduction formula is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;( (Original tokens - Compressed tokens) / Original tokens ) * 100%&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove conversational filler and politeness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While AI models may respond to the tone of a prompt, but politeness alone doesn’t guarantee a better answer.&lt;/p&gt;

&lt;p&gt;Greetings, repeated requests, long introductions, polite words like &lt;code&gt;Please&lt;/code&gt;, &lt;code&gt;Kindly&lt;/code&gt;, &lt;code&gt;Thank you&lt;/code&gt; consume more input tokens without positively impacting the output quality.&lt;/p&gt;

&lt;p&gt;Let’s look at the examples below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Original version (Wordy and polite prompt) - About 59 tokens:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hi there! I hope your day is going well. I am working on a marketing campaign for a new coffee brand, and I was wondering if you could please help me out? Could you kindly write three short, catchy words for me? Thank you so much. I really appreciate your help!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Compressed version (Token efficient) - About 18 tokens :&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Act as a copywriter. Write 3 short, catchy slogans for a new coffee brand&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This leads to about a 69% reduction in the input tokens and would reduce the LLM cost.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Assign a role.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;This saves input tokens while helping the AI produce more consistent and relevant results.&lt;/p&gt;

&lt;p&gt;Just like in the compressed prompt above,  simply telling the AI to act as a copywriter, automatically brings in the skills, tone, and mindset of a real copywriter without you having to spell every single one out in your prompt.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Audit for duplicate instructions.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Instead of telling an AI the same thing in different ways, you communicate the requirements once, clearly and directly.&lt;/p&gt;

&lt;p&gt;Original version (Instruction duplication) - About 87 tokens:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are a professional customer support assistant. Always communicate politely with customers. Maintain a friendly and respectful tone. Never use offensive or disrespectful language. Ensure that customers feel valued and respected. Provide clear and understandable answers. Avoid complicated technical language. Explain solutions in simple language. Make sure your responses are easy to understand. Keep your answers short and concise. Avoid unnecessary explanations. Do not provide irrelevant information. Focus on resolving the customer's problem.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Compressed version (Concise and instruction duplication removal) - About 54 tokens:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are a professional customer support assistant. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Maintain a polite, friendly, and respectful tone. &lt;/li&gt;
&lt;li&gt;Provide clear, concise, relevant understandable answers using simple
language. &lt;/li&gt;
&lt;li&gt;Avoid unnecessary explanations. &lt;/li&gt;
&lt;li&gt;Focus on resolving the customer's problem.&lt;/li&gt;
&lt;/ol&gt;


&lt;/blockquote&gt;

&lt;p&gt;This leads to about 33% reduction in the input tokens and would reduce the LLM cost.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Replace prose with structured lists&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Just like in the compressed prompt above, rather than having lengthy paragraphs, use bullet points instead. &lt;/p&gt;

&lt;p&gt;This makes instructions more organized, communicates specific expectations, and makes it easier for the LLM to scan and evaluate instructions, directly impacting the output positively.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Token-Efficient Delimiters.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This technique involves replacing lengthy section headings, labels and separators with shorter, but communicates the same or even better meaning.&lt;/p&gt;

&lt;p&gt;The following are practical examples of token-efficient delimiters:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Before Compression&lt;/th&gt;
&lt;th&gt;After Compression&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Instructions for the assistant:&lt;/td&gt;
&lt;td&gt;Rules:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;User question:&lt;/td&gt;
&lt;td&gt;Q:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model answer:&lt;/td&gt;
&lt;td&gt;A:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Additional information:&lt;/td&gt;
&lt;td&gt;Context:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Expected output format:&lt;/td&gt;
&lt;td&gt;Output:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Important considerations:&lt;/td&gt;
&lt;td&gt;Notes:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Beginning of new section&lt;/td&gt;
&lt;td&gt;——&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;End of instructions&lt;/td&gt;
&lt;td&gt;END&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Original version - About 59 tokens.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;======= ROLE DEFINITION =======&lt;/p&gt;

&lt;p&gt;Your assigned role:&lt;br&gt;
You are a professional copywriter.&lt;/p&gt;

&lt;p&gt;======= INSTRUCTIONS =======&lt;/p&gt;

&lt;p&gt;Instructions for the assistant:&lt;br&gt;
Write clearly and professionally.&lt;br&gt;
Avoid unnecessary words.&lt;/p&gt;

&lt;p&gt;======= OUTPUT FORMAT =======&lt;/p&gt;

&lt;p&gt;Expected output format:&lt;br&gt;
Provide a well-structured response&lt;br&gt;
using appropriate headings.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Compressed version - About 30 tokens&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Role
&lt;/h4&gt;

&lt;p&gt;Professional content writer.&lt;/p&gt;
&lt;h4&gt;
  
  
  Rules
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Write clearly and professionally.&lt;/li&gt;
&lt;li&gt;Avoid unnecessary words.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;p&gt;Use appropriate headings and structure.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The compressed version is shorter, easier to scan, and retains the essential instructions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, let’s move to the advanced prompt compression techniques.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Advanced Compression Techniques&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The LLMLingua series is a collection of prompt compression techniques developed by Microsoft Research.&lt;/p&gt;

&lt;p&gt;Unlike the manual techniques we've discussed so far, LLMLingua uses Smaller Language Models  (SLM) to automatically identify and remove less important tokens from a prompt.&lt;/p&gt;

&lt;p&gt;The main goal is to reduce the number of tokens sent to an LLM while preserving the information needed to complete the task.&lt;/p&gt;

&lt;p&gt;This approach is useful when working with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large system prompts.&lt;/li&gt;
&lt;li&gt;Long documents and conversations.&lt;/li&gt;
&lt;li&gt;Retrieval-Augmented Generation (RAG).&lt;/li&gt;
&lt;li&gt;Large amounts of contextual information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use the LLMLingua library to compress prompts programmatically, install the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install llmlingua
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The LLMLingua family has three main approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;LLMLingua.&lt;/li&gt;
&lt;li&gt;LongLLMLingua.&lt;/li&gt;
&lt;li&gt;LLMLingua-2.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. LLMLingua&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;LLMLingua leverages small models’ perplexity to measure the redundancy within a prompt.&lt;/p&gt;

&lt;p&gt;It identifies less important words and phrases and removes some of them, while still retaining the communication of the intended information.&lt;/p&gt;

&lt;p&gt;According to Microsoft, up to 20x compression can be achieved, with minimal performance loss.&lt;/p&gt;

&lt;p&gt;Use LLMLigua when you want to remove redundant words from your prompt.&lt;/p&gt;

&lt;p&gt;A code snippet is as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llmlingua&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;

&lt;span class="n"&gt;compressor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"""
You are an experienced software architect.
Review a web application built with React, Python,
and PostgreSQL. Identify potential performance
bottlenecks, security risks, and scalability issues.
Provide practical recommendations and explain
the tradeoffs of each proposed improvement.
"""&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;compressor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compress_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;target_token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"compressed_prompt"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Original:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"origin_tokens"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Compressed:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"compressed_tokens"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;2. LongLLMLingua&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;LongLLMLingua is an improvement over the original LLMLingua. &lt;/p&gt;

&lt;p&gt;It is designed for situations where prompts contain large amounts of information.&lt;/p&gt;

&lt;p&gt;It considers the user's question when deciding what information to retain in a process called &lt;strong&gt;query-aware compression&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine you give an AI a 7-page company report and ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What are the company's biggest financial risks?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The report might contain information about the company’s history, management structure, financial performance, operational costs, business expansion, and financial risks.&lt;/p&gt;

&lt;p&gt;Unfortunately, not all this information is equally relevant to the question, and this is where LongLLMLingua shines.&lt;/p&gt;

&lt;p&gt;It prioritises information that is useful for answering the question.&lt;/p&gt;

&lt;p&gt;Use LongLLMLingua for compressing prompts for RAG applications and document-based question answering.&lt;/p&gt;

&lt;p&gt;A code snippet is as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llmlingua&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;

&lt;span class="n"&gt;compressor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="s2"&gt;"Prepmie was established in 2015."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"The company currently operates in five countries."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"It has a marketing department of 25 employees."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"Revenue increased by 15% last year."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"However, operating expenses increased by 35%."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"The company also has outstanding loans worth $50 million."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"Customer satisfaction improved by 10%."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"The company plans to expand into three additional countries next year."&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"What are the company's biggest financial risks?"&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;compressor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compress_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;rank_method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"longllmlingua"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"compressed_prompt"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;3. LLMLingua-2&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;LLMLingua-2 takes a different approach to prompt compression.&lt;/p&gt;

&lt;p&gt;Instead of relying primarily on perplexity to identify less important tokens, it uses a model trained to classify tokens according to whether they should be retained or removed.&lt;/p&gt;

&lt;p&gt;In simple terms, the smaller model learns which parts of a prompt are important and which can be removed.&lt;/p&gt;

&lt;p&gt;Unlike LongLLMLigua, it is task-agnostic. It does not need the user's question to perform its basic compression process.&lt;/p&gt;

&lt;p&gt;A code snippet is as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llmlingua&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;

&lt;span class="n"&gt;compressor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PromptCompressor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"microsoft/llmlingua-2-xlm-roberta-large-meetingbank"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;use_llmlingua2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"""
You are an experienced business consultant.
Analyse the company's business strategy.
Identify opportunities for improving profitability.
Provide practical recommendations.
"""&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;compressor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compress_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"compressed_prompt"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Considerations for LLMLingua&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Advanced compression techniques can remove critical instructions and negatively impact the model’s output quality.&lt;/p&gt;

&lt;p&gt;Always test the compressed prompt against the original, especially when dealing with system instructions, and structured outputs.&lt;/p&gt;

&lt;p&gt;For more understanding of Microsoft LLMLingua series, check here - &lt;a href="https://www.microsoft.com/en-us/research/project/llmlingua" rel="noopener noreferrer"&gt;https://www.microsoft.com/en-us/research/project/llmlingua&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also check here for the demo - &lt;a href="https://huggingface.co/spaces/microsoft/LLMLingua" rel="noopener noreferrer"&gt;https://huggingface.co/spaces/microsoft/LLMLingua&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Just like communicating with a busy team, the best AI prompts say more with less. &lt;/p&gt;

&lt;p&gt;Every unnecessary word costs you tokens, slows down responses, and can negatively impact accuracy. &lt;/p&gt;

&lt;p&gt;Whether you start by manually trimming conversational fluff and structuring your instructions, or leverage the usage of Microsoft’s LLMLingua series, prompt compression is one of the highest-leverage optimizations you can make. &lt;/p&gt;

&lt;p&gt;Audit your prompts today. &lt;/p&gt;

&lt;p&gt;Your latency, accuracy, and API bill will thank you.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
