avatarFabio Matricardi

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5319

Abstract

ting the impact on your text’s quality and accuracy. Remember, sometimes a dash less is more.</p><p id="7766">So, let’s try making our AI chef bake the perfect text pastry.</p><blockquote id="08bd"><p>Imagine these two dials: Temperature controls the heat of the oven, how adventurous the AI gets with words. Top_p decides how picky the AI is when choosing ingredients, whether it grabs anything decent or only the top choices.</p></blockquote><p id="1aa8"><b>1. Hot oven, picky eater (High temperature and low top_p):</b> The AI is a bit wild with words thanks to the hot temperature, but keeps things mostly sensible by only grabbing likely ingredients. This can be good for a surprise twist without going off the rails.</p><p id="ea12"><b>2. Cool oven, top gourmet (Low temperature and high top_p):</b> The AI plays it safe with familiar words, like a fancy restaurant picking only the finest ingredients. This makes the text smooth and clear, but maybe a bit boring.</p><p id="59f7"><b>3. Hot oven, free-for-all (High temperature and high top_p):</b> The AI throws caution to the wind, grabbing any word that catches its eye! This can lead to wild, creative dishes, but they might be a bit strange or hard to understand.</p><p id="c519"><b>4. Cool oven, super picky (Low temperature and low top_p): </b>The AI is like a grandma sticking to tried-and-true recipes, choosing only the most common words and never taking risks. This results in safe, predictable text, but it might lack excitement.</p><p id="712a">By playing with these two dials, you can find the perfect recipe for your text, whether you want a zany surprise, a reliable classic, or something in between. So go forth, experiment, and enjoy the delicious possibilities!</p><figure id="d3d6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*0ip4zTqnrQAgxoRHaLvhbQ.png"><figcaption>screenshot from Generative AI Image PlayGround</figcaption></figure><h1 id="f02c">Find your sweet spot — Use a Playground and experiment prompt formats</h1><p id="8857">Every text generation task and desired outcome has its own perfect parameter recipe. Practice makes perfect, so keep experimenting and fine-tuning until you achieve the text that sings to your specific needs.</p><p id="c572">I tried in the last 2 weeks more than 100 Tiny LLMs. These little guys have a lot of potential, but they are like little children:</p><ol><li>they need clear instructions</li><li>they cannot inference with flexibility, so the instructions must like in the primary school textbooks</li><li><b>temperature </b>and <b>top_p </b>must be used with care</li></ol><p id="2584">Furthermore, remember that every model is trained with special tokens: Large Language Models accept instructions only with a special template.</p><p id="85dd">Here 2 examples from <a href="https://gpus.llm-utils.org/llama-2-prompt-template/">this amazing source</a>:</p><div id="e40f"><pre>VICUNA STYLE PROMPT TEMPLATE

A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. <span class="hljs-section">USER: hello, who are you? </span> <span class="hljs-section">ASSISTANT: </span>

ALPACA STYLE PROMPT TEMPLATE

Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n

<span class="hljs-comment">### Instruction:\n{instruction}</span>

<span class="hljs-comment">### Response:"</span></pre></div><p id="2414">Have a look at few of my previous articles to see how it is important to feed the model with the correct prompt template structure.</p><p id="34cb">Remember, also, that every instructed base model treats special delimiters like “-” or “>” in a different way: they can help structure the prompt and guide the model’s output.</p><p id="318b">Delimiters serve as crucial tools in prompt engineering, helping distinguish specific segments of text within a larger prompt. For example, they make it explicit for the language model what text needs to be translated, paraphrased, summarized, and so forth.</p><blockquote id="07f2"><p>Delimiters can take various forms such as triple quotes (“””), triple backticks (“`), triple dashes ( — ), angle brackets (< >), XML tags (<tag> </tag>), or section titles. Their purpose is to clearly delineate a section as separate from the rest.</p></blockquote><p id="ce49">Here two good examples from <a href="https://www.topbots.com/prompt-engineering-chatgpt-llm-applications/">https://www.topbots.com/prompt-engineering-chatgpt-llm-applications/</a></p><figure id="a3eb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*G9Wl_0QSugTgGlpWLCtDoQ.png"><figcaption></figcaption></figure><figure id="ad84"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*PvDazTgmyZgMwRR6-JXp2g.png"><figcaption>different ways to use delimiters</figcaption></figure><p id="7547">As you can understand, even though small/tiny LLMs have a great potential, most of their performance lies on how good we are in finding the perfect recipe balancing all the ingredients.</p><p id="c5bc">So you MUST build your own Playground. I will leave an example in the suggested articles at the end: feel free to take inspiration and do it yourself.</p><figure id="9116"><img src="https://c

Options

dn-images-1.readmedium.com/v2/resize:fit:800/1*o-VnSRVd9AWctFkx6Z0kmg.png"><figcaption>my test Playground's for the <a href="https://huggingface.co/afrideva/Aira-2-1B1-GGUF">tiny model aira-2–1b1</a></figcaption></figure><h1 id="20fc">Conclusions</h1><p id="8203">Mastering the art of parameter tuning might seem daunting, but don’t be discouraged! Just like baking, it’s a process of exploration and discovery. With a little patience, practice, and perhaps a dash of curiosity, you’ll be able to confidently guide your mini LLM chefs, transforming them from brick-makers to language maestros, churning out delectable text creations fit for any occasion.</p><p id="a0e2">So, go forth and tweak! Remember, in the world of small LLMs, every parameter adjustment holds the potential to unlock a universe of possibilities. Bon appétit!</p><p id="46cf">Hope you enjoyed the article. If this story provided value and you wish to show a little support, you could:</p><ol><li>Clap a lot of times for this story</li><li>Highlight the parts more relevant to be remembered (it will be easier for you to find it later, and for me to write better articles)</li><li><b>Learn how to start to Build Your Own AI</b>, download <a href="https://build-your-own-ai.ck.page/97a99ce2f7">This Free eBook</a></li><li>Sign up for a Medium membership using <a href="https://medium.com/@fabio.matricardi/membership">my link</a> — ($5/month to read unlimited Medium stories)</li><li>Follow me on Medium</li><li>Read my latest articles <a href="https://medium.com/@fabio.matricardi">https://medium.com/@fabio.matricardi</a></li></ol><p id="2b9d">If you want to read more here some ideas:</p><div id="f008" class="link-block"> <a href="https://readmedium.com/stablelm-zepyhr-3b-broader-better-boosted-bb659db162a9"> <div> <div> <h2>StableLM-Zepyhr-3B: Broader, Better, Boosted!</h2> <div><h3>The new model from Stability-AI comes in a small form factor: Let’s create our local playground test its capabilities…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*HoLromo8HD8kntRuLxM8ig.jpeg)"></div> </div> </div> </a> </div><div id="5d50" class="link-block"> <a href="https://readmedium.com/does-size-of-llms-matter-e68404c44e86"> <div> <div> <h2>Does SIZE (of LLMs) Matter?</h2> <div><h3>Let’s compare the performance and capabilities of Tiny LLM and verify when too Small is really too much. — Part 1</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*96ArYs1Iz57aO80NDQuFvA.jpeg)"></div> </div> </div> </a> </div><div id="54dc" class="link-block"> <a href="https://readmedium.com/ai-detectors-and-the-big-fear-be6fa1be0fb6"> <div> <div> <h2>AI detectors and the Big Fear?</h2> <div><h3>What is the future of the Education System in a world where Fear of an artificial intelligence who rebels to humans is…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*XQMa1GpNiaR1t2KNEU7t4A.jpeg)"></div> </div> </div> </a> </div><div id="d34a" class="link-block"> <a href="https://readmedium.com/hack-your-home-to-build-the-best-ai-arena-423ea55a5748"> <div> <div> <h2>Hack Your Home to Build the Best AI Arena</h2> <div><h3>Create the Ultimate Testing Ground for Large Language Models, using GGUF quantized model with context window up to 16K…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*f6YfJmP21xlSdIJBuKS8vQ.png)"></div> </div> </div> </a> </div><h1 id="5208">PlainEnglish.io 🚀</h1><p id="748f"><i>Thank you for being a part of the In Plain English community! Before you go:</i></p><ul><li><i>Be sure to <b>clap</b> and <b>follow</b> the writer</i><b></b></li><li><i>Learn how you can also <a href="https://plainenglish.io/blog/how-to-write-for-in-plain-english"><b>write for In Plain English</b></a></i></li><li><i>Follow us: <a href="https://twitter.com/inPlainEngHQ"><b>X</b></a><b> | <a href="https://www.linkedin.com/company/inplainenglish/">LinkedIn</a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw">YouTube</a> | <a href="https://discord.gg/in-plain-english-709094664682340443">Discord</a> | <a href="https://newsletter.plainenglish.io/">Newsletter</a></b></i></li><li><i>Visit our other platforms: <a href="https://stackademic.com/"><b>Stackademic</b></a><b> | <a href="https://cofeed.app/">CoFeed</a> | <a href="https://venturemagazine.net/">Venture</a></b></i></li></ul></article></body>

Tiny Tweaks, Big Impact: Mastering the parameters of your Mini Language Model

Bake off the hidden potential of small LLMs through careful “ingredients” tuning.

Image by the author and Lexica.art

Have you ever tried baking a cake and ended up with something more akin to a brick? We’ve all been there, staring at a disappointing culinary outcome, wondering where we went wrong. Turns out, the answer might be lurking in the measurements! Just like baking, the delicate art of crafting successful text with a small language model (LLM) hinges on fine-tuning its parameters.

But before we dive into the flour and parameters, let’s take a step back.

Click here to get it for FREE

The secret recipe

Imagine an LLM as a highly skilled chef, equipped with a vast recipe book of words and phrases. To whip up the perfect text dish, however, they need more than just ingredients. They need precise instructions, the right amount of each element, and maybe even a dash of creativity. That’s where parameters come in — they act as the recipe guidelines, telling the LLM how to blend and bake words into something delicious.

Now, why is this especially crucial for small LLMs? Think of them as your petite sous chefs, eager to please but still learning the ropes. With fewer ingredients (parameters) at their disposal, every tweak counts. A sprinkle too much of one element can ruin the whole dish, while a timid pinch might leave it bland and uninspired.

So, how do we master these tiny tweaks and unlock the hidden potential of our mini LLMs? Let’s break it down into three key steps.

image from Cohere

Know your ingredients

Understanding what each parameter does is fundamental. Some adjust the model’s temperature, influencing its creativity and risk-taking. Others control the structure and coherence of the generated text.

Imagine you’re a chef writing a recipe using a fancy AI cookbook of words and phrases. You want to choose the best ingredients (words) to create a delicious dish (text), but there are different ways to pick them! Here are three special tools that help you fine-tune your recipe:

Temperature: This is like the oven’s heat setting. A low temperature plays it safe, sticking to common words and grammar, resulting in familiar, predictable text. A high temperature cranks up the creativity, making the AI take bigger risks and potentially surprise you with unexpected or even wacky words.

Top_p: Think of this as picking ingredients from a hat. With high top_p, you grab any word with a decent chance of fitting, leading to more diverse but sometimes nonsensical results. Low top_p focuses on the most likely choices, making the text smooth and consistent, but possibly less exciting.

Repeat_penalty: This discourages using the same word repeatedly. Imagine oversalting your dish! High repeat_penalty puts the brakes on redundancy, ensuring variety and fresh flavors in your text. Low repeat_penalty allows for some repetition, which can be useful for emphasis or rhythm.

By adjusting these tools, you can control the style, creativity, and overall taste of your AI-generated text, just like a chef tailoring a recipe to perfection. So, experiment, have fun, and remember, a pinch of the unexpected can add a delicious dash of magic to your words!

Practical examples?

Here out of the box tips, to give you an idea of how these parameters can be used in different scenarios: taken from OpenAI and Cohere’s blogs.

from OpenaI community blog: link here
image from Lexica.art

Experiment with precision

Don’t be afraid to get your hands dirty! Small changes can yield surprising results. Start with subtle tweaks, testing the impact on your text’s quality and accuracy. Remember, sometimes a dash less is more.

So, let’s try making our AI chef bake the perfect text pastry.

Imagine these two dials: Temperature controls the heat of the oven, how adventurous the AI gets with words. Top_p decides how picky the AI is when choosing ingredients, whether it grabs anything decent or only the top choices.

1. Hot oven, picky eater (High temperature and low top_p): The AI is a bit wild with words thanks to the hot temperature, but keeps things mostly sensible by only grabbing likely ingredients. This can be good for a surprise twist without going off the rails.

2. Cool oven, top gourmet (Low temperature and high top_p): The AI plays it safe with familiar words, like a fancy restaurant picking only the finest ingredients. This makes the text smooth and clear, but maybe a bit boring.

3. Hot oven, free-for-all (High temperature and high top_p): The AI throws caution to the wind, grabbing any word that catches its eye! This can lead to wild, creative dishes, but they might be a bit strange or hard to understand.

4. Cool oven, super picky (Low temperature and low top_p): The AI is like a grandma sticking to tried-and-true recipes, choosing only the most common words and never taking risks. This results in safe, predictable text, but it might lack excitement.

By playing with these two dials, you can find the perfect recipe for your text, whether you want a zany surprise, a reliable classic, or something in between. So go forth, experiment, and enjoy the delicious possibilities!

screenshot from Generative AI Image PlayGround

Find your sweet spot — Use a Playground and experiment prompt formats

Every text generation task and desired outcome has its own perfect parameter recipe. Practice makes perfect, so keep experimenting and fine-tuning until you achieve the text that sings to your specific needs.

I tried in the last 2 weeks more than 100 Tiny LLMs. These little guys have a lot of potential, but they are like little children:

  1. they need clear instructions
  2. they cannot inference with flexibility, so the instructions must like in the primary school textbooks
  3. temperature and top_p must be used with care

Furthermore, remember that every model is trained with special tokens: Large Language Models accept instructions only with a special template.

Here 2 examples from this amazing source:

VICUNA STYLE PROMPT TEMPLATE

A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. 
USER: hello, who are you? 
ASSISTANT: 


ALPACA STYLE PROMPT TEMPLATE

Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n

### Instruction:\n{instruction}

### Response:"

Have a look at few of my previous articles to see how it is important to feed the model with the correct prompt template structure.

Remember, also, that every instructed base model treats special delimiters like “-” or “>” in a different way: they can help structure the prompt and guide the model’s output.

Delimiters serve as crucial tools in prompt engineering, helping distinguish specific segments of text within a larger prompt. For example, they make it explicit for the language model what text needs to be translated, paraphrased, summarized, and so forth.

Delimiters can take various forms such as triple quotes (“””), triple backticks (“`), triple dashes ( — ), angle brackets (< >), XML tags ( ), or section titles. Their purpose is to clearly delineate a section as separate from the rest.

Here two good examples from https://www.topbots.com/prompt-engineering-chatgpt-llm-applications/

different ways to use delimiters

As you can understand, even though small/tiny LLMs have a great potential, most of their performance lies on how good we are in finding the perfect recipe balancing all the ingredients.

So you MUST build your own Playground. I will leave an example in the suggested articles at the end: feel free to take inspiration and do it yourself.

my test Playground's for the tiny model aira-2–1b1

Conclusions

Mastering the art of parameter tuning might seem daunting, but don’t be discouraged! Just like baking, it’s a process of exploration and discovery. With a little patience, practice, and perhaps a dash of curiosity, you’ll be able to confidently guide your mini LLM chefs, transforming them from brick-makers to language maestros, churning out delectable text creations fit for any occasion.

So, go forth and tweak! Remember, in the world of small LLMs, every parameter adjustment holds the potential to unlock a universe of possibilities. Bon appétit!

Hope you enjoyed the article. If this story provided value and you wish to show a little support, you could:

  1. Clap a lot of times for this story
  2. Highlight the parts more relevant to be remembered (it will be easier for you to find it later, and for me to write better articles)
  3. Learn how to start to Build Your Own AI, download This Free eBook
  4. Sign up for a Medium membership using my link — ($5/month to read unlimited Medium stories)
  5. Follow me on Medium
  6. Read my latest articles https://medium.com/@fabio.matricardi

If you want to read more here some ideas:

PlainEnglish.io 🚀

Thank you for being a part of the In Plain English community! Before you go:

Hugging Face
Python
Local Gpt
Artificial Intelligence
Future Of Education
Recommended from ReadMedium