Show HN: Compress GPT-4 Prompts (promptreducer.com)
Hey HN!
I recently built Prompt Reducer, an app that makes it easier to compress GPT-4 prompts. The main goal is to reduce the number of tokens in each prompt, thereby reducing the cost of running GPT-4. I figured since @gfodor tweeted about compressing GPT-4. It’s still early, and it does not work perfectly, but I’d love to hear any feedback or suggestions for how to make it faster or more efficient.
46 comments
[ 11.9 ms ] story [ 346 ms ] threadThe second try reduced the same prompt by only 20% and the results were worse than the first try.
Both missed a key detail about using a specific term in the response.
Interesting idea. Not sure how useful it will be with costs dropping fast. But if you can get it to work better, it might be useful for recursive prompt-chains like Auto-GPT or babyAGI.
I guess this might have uses and it's neat. But it won't be for saving money.
https://platform.openai.com/tokenizer
The string "The GPT family of models process text using tokens" is 10 tokens.
Feeding that string to the "compressor" results in "GPT models: process_text(tokens)", which is...12 tokens. The OP site incorrectly estimates that this is 8 tokens, likely using a naive word boundary regex or something similar.
This is because stuff like punctuation are their own token, and complex words or abbrevations are broken down into one token per piece in the dictionary. The string "ABCDEFGHIJKLMNOP" (16 characters) is 8 tokens (consisting of the bigrams AB, CD, EF, etc), while the string "Counterintuitive" (also 16 characters) is a whopping 2 tokens (likely the tokens for "counter" and "intuitive").
Fewer characters doesn't equal fewer tokens, and in fact, the more esoteric the string, the more likely it is that it consumes an unintuitively large number of tokens.
"summarize the following while retaining all functional data:"
doesn't seem to do the trick.
Source: https://platform.openai.com/tokenizer
-- compress the following text in a way that fits in a tweet (ideally) and such that you (GPT-4) can reconstruct the intention of the human who wrote text as close as possible to the original intention. This is for yourself. It does not need to be human readable or understandable. Abuse of language mixing, abbreviations, symbols (unicode and emoji), or any other encodings or internal representations is all permissible, as long as it, if pasted in a new inference cycle, will yield near-identical results as the original text: --
There is no reason to think GPT-4 has any special knowledge about prompts, or how they should be effectively compressed so that it will treat it as equivalent to the original. It does an interesting job of faking it. But they are basically asking GPT-4 for a stylized version of "summarize the following:".
(Uses recurrent langchain loops for introspection and learning about itself and its capabilities as they grow + vector databases like Pinecone for long term memory)
We used soft prompts, not emojis.
You do need full access to the model in order to do this, but we found that prompts can be severely compressed an still retain a lot of information.
I would erase “and still get the same results” completely until you’re certain it can actually do that reliably.
Full Prompt: Please write 5 funny jokes about Santa. Please do not mention that Santa isn't real - the audience for these jokes are children. It would be preferable if there were references to Santa's elfs within the jokes!
Compressed Prompt: 5jokesrealprefer ref (note: emojis were omitted)
ChatGPT response to full prompt: Sure, here are five funny jokes about Santa that are appropriate for children and include references to Santa's elves: Why did Santa's elf go to school? To learn his ABC-elfs! Why did Santa's helper go to the doctor? Because he had a low "elf"-esteem! What do you call an elf who sings? A wrapper! Why did Santa's elf put his bed in the fireplace? Because he wanted to sleep like a log! What did Santa's elf say when he met Frosty the Snowman? "Can I take a elfie with you
ChatGPT response to compressed prompt: Sure, here are five Santa jokes that are not based on real events and are suitable for children and adults alike: Why did Santa go to art school? Because he wanted to learn how to draw his sleigh! What do you call Santa when he stops moving? Santa Pause! Why did Santa Claus refuse to eat at the pizzeria? Because he was worried he'd end up with too many ho-ho-holes in his belly! What does Santa Claus use to keep his garden healthy? Elf fertilizer! What do you get if you cross Santa Claus with a duck? A Christmas Quacker! I hope these jokes bring some joy and laughter to your day!
Alpaca 13B response to full prompt: 1) What did one reindeer say when he saw another? "Ho, ho!" 2) Why was it so hard for Rudolph and his friends to get into a nightclub on Christmas Eve? They didn’t have any ID. 3) How does Santa keep track of all the presents that are given out every year at Christmastime? He uses an elf-tracking system! 4) Why did Santa's wife leave him for another man? She wanted to be Mrs Claus instead of just "Mrs".
Alpaca 13B response to compressed prompt: I prefer real jokes over fake ones
ChatGPT lost a little bit of context with a shortened prompt, but Alpaca completely lost the prompt. It's only one example, but I'm confident that it can't necessarily be used like that.
[0] https://www.youtube.com/watch?v=_K-L9uhsBLM
Either way, whatever weird thing you do you're probably burning reasoning time on decoding the question
https://i.imgur.com/ImBcUuU.png
There might be gains to be had in understanding which tokens produce the lowest attention weights in the prompt, and then trimming those out. However, that's not something that I think you could do at API length; you need access to the direct attention weights to get that. You can get them running local GPT models, and could possibly pre-process a prompt using LLaMa or similar to get a guess at what the least important tokens are, but it won't be exactly right since it's not the same model. However, to the extent that LLaMA and GPT-4 have learned the same things about the English language, it might yield fruit.
> Explain the first law of robotics while speaking like a pirate, and in enough carefully considered detail that a seven year old child could understand
The "compressed" prompt it gave me was "1stLoRb:pirate,7yoChild"
When I fed that to GPT-4, it started a story called "Title: The Adventures of Captain Little Pirate". I stopped it early, but it was clearly not heading towards anything to do with robotics. I don't think it was able to decode "1stLoRb" at all. I gave ChatGPT the original prompt, and of course it started completing the task.
I don't think this approach is going to work, because as others have noted, GPT-4 doesn't have this kind of introspection. It's kind of the equivalent of if I asked you to take notes for yourself on a lecture, and make them as compact as possible, so you just wrote down random letters from words you heard. You might feel in the moment like you've found a system, but later on, your notes will be as much gibberish to you as they are to anyone else.
What I wonder, though, is if it would be possible to take the embedding vector for a prompt and then do some kind of math on it so that it could be decoded as a much more compact version of roughly the same prompt. Basically something akin to quantization.
(For that matter, what happens if you literally quantize embeddings and then decode them? Do they become more vague, or just slightly off, or do they become total nonsense?)
Like, "explain first law robotics as pirate, target seven year old" generates a similar result
FGPT=FitnessGram™ Pacer Test; MST=multistage aerobic capacity test; PGMD=progressively gets more difficult; 20mPT=20 meter pacer test; 30s=30 seconds; LU=start; RS=running speed; SS=slowly; GF=faster; M=minute; S=signal; [!]=beep; L=lap; SL=single lap; CS=completed; H=hear; [?]=ding; R=run; SL=straight line; LP=long as possible; FT=fail; T=test; O=over; W=start; Y=your mark; G=get ready;
FGPT(MST(PGMD))=20mPT(30s(LU(RS(SS(GF(M(S([!]))(L(SL(CS(H[?]))))R(SL(LP(FT(T(O(W(Y(G))))))))))))
Please convert this JSON to a Typescript interface:
ChatGPT: Based on the provided JSON keys, here's the TypeScript interface you requested: :D