Akshay πŸš€ Profile picture
Feb 5 β€’ 13 tweets β€’ 4 min read β€’ Read on X
How LLMs work, clearly explained:
Before diving into LLMs, we must understand conditional probability.

Let's consider a population of 14 individuals:

- Some of them like Tennis 🎾
- Some like Football ⚽️
- A few like both 🎾 ⚽️
- And few like none

Here's how it looks πŸ‘‡ Image
So what is Conditional probability ⁉️

It's a measure of the probability of an event given that another event has occurred.

If the events are A and B, we denote this as P(A|B).

This reads as "probability of A given B"

Check this illustration πŸ‘‡ Image
For instance, if we're predicting whether it will rain today (event A), knowing that it's cloudy (event B) might impact our prediction.

As it's more likely to rain when it's cloudy, we'd say the conditional probability P(A|B) is high.

That's conditional probability for you! πŸŽ‰
Now, how does this apply to LLMs like GPT-4❓

These models are tasked with predicting the next word in a sequence.

This is a question of conditional probability: given the words that have come before, what is the most likely next word? Image
To predict the next word, the model calculates the conditional probability for each possible next word, given the previous words (context).

The word with the highest conditional probability is chosen as the prediction. Image
The LLM learns a high-dimensional probability distribution over sequences of words.

And the parameters of this distribution are the trained weights!

The training or rather pre-training** is supervised.

I'll talk about the different training steps next time!**

Check this πŸ‘‡ Image
But there a problem❗️

If we always pick the word with the highest probability, we end up with repetitive outputs, making LLMs almost useless and stifling their creativity.

This is where temperature comes into picture.

Check this before we understand more about it...πŸ‘‡ Image
However a high temperate value produces gibberish

Let's understand what's going on...πŸ‘‡ Image
So, the LLMs instead of selecting the best token (for simplicity let's think of tokens as words), they "sample" the prediction.

So even if β€œToken 1” has the highest score, it may not be chosen since we are sampling. Image
Now, temperature introduces the following tweak in the softmax function, which, in turn, influences the sampling process: Image
Let take a code example!

At low temperature, probabilities concentrate around the most likely token, resulting in nearly greedy generation.

At high temperature, probabilities become more uniform, producing highly random and stochastic outputs.

Check this outπŸ‘‡ Image
That's a wrap!

Hopefully, this guide has demystified some of the magic behind LLMs.

And, if you enjoyed this breakdown:

Find me β†’ @akshay_pachaar βœ”οΈ
For more insights and tutorials on AI and Machine Learning.

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Akshay πŸš€

Akshay πŸš€ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @akshay_pachaar

Feb 1
Let's compare OpenAI o3-mini and DeepSeek-R1 using RAG:
OpenAI just dropped o3-mini in response to DeepSeek-R1!

Today, we build a Streamlit app to compare and evaluate them using RAG.

Tech stack:

- @Llama_Index for orchestration
- @Cometml Opik for evaluation
- @Streamlit for the UI

Let's go! πŸš€
The architecture presented below illustrates some of the key components & how they interact with each other!

For those who are new, I've provided detailed descriptions & code for each component. Image
Read 11 tweets
Jan 30
Let's build a text-to-image generation and understanding app, using DeepSeek-Janus (100% local):
Before we start, here's a quick demo of what this app does!

It's a 2-in-1:

Tech stack:
- @Deepseek_AI's Janus-pro as LLM
- @Streamlit for UI

1️⃣ Text-to-image generation demo:
2️⃣ Multimodal chat and image understanding demo

User uploads an image and ask questions about it:
Read 14 tweets
Jan 27
Let's build a browser-use agent, similar to OpenAI operator, but utilizing open-source tools:
Simply put, browser use is making agents use websites just like us.

Before we start, here's a quick demo of what we're building!

Tech stack:

- @Gradio for the UI
- @browser_use to create the agent
- @Google's latest gemini-2.0-flash-exp as LLM

Let's go! πŸš€
0️⃣ Installation and Setup

Install dependencies and setup the required env vars. Image
Read 9 tweets
Jan 26
Let's compare DeepSeek-R1 and OpenAI-o1 using RAG:
DeepSeek-R1 delivers OpenAI-o1 level intelligence at 90% less cost.

Today, we build a Streamlit app to compare and evaluate them using RAG.

Tech stack:

- @Llama_Index for orchestration
- @Cometml Opik for evaluation
- @Streamlit for the UI

Let's go! πŸš€
The architecture presented below illustrates some of the key components & how they interact with each other!

For those who are new, I've provided detailed descriptions & code for each component. Image
Read 12 tweets
Jan 23
Let's build a multi-agent YouTube video analyst, powered by DeepSeek-R1 (100% local):
This app can scrape videos from the multiple YouTube channels and report trends & insights.

Tech stack:

- @crewAIInc for multi-agent orchestration.
- Bright Data for reliable web-scraping at scale.
- @Streamlit for the UI.

Here's a quick demo of what we're building:
Before we start coding, I have provided a simplified architecture diagram that highlights all the key components and their interactions.

This will be followed by detailed descriptions and code for each component:
Read 14 tweets
Jan 22
Let's build an Agentic RAG app using DeepSeek-R1 (100% local):
DeepSeek-R1 delivers OpenAI-o1 level intelligence at 90% less cost.

This agentic app searches your docs and falls back on web search if needed.

In the video, I test it for both types of queries.

Tech stack:

- @CrewAIInc for agent orchestration
- @firecrawl_dev for web search
The architecture diagram presented below illustrates some of the key components & how they interact with each other!

It will be followed by detailed descriptions & code for each component: Image
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(