How to Improve LLMs with RAG (Overview + Python Code)

  Рет қаралды 77,192

Shaw Talebi

Shaw Talebi

Күн бұрын

Пікірлер: 85
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
👉More on LLMs: kzbin.info/aero/PLz-ep5RbHosU2hnz5ejezwaYpdMutMVB0 -- References [1] github.com/openai/openai-cookbook/blob/main/examples/Question_answering_using_embeddings.ipynb [2] kzbin.info/www/bejne/m5fFn2BpqbV8la8 [3] docs.llamaindex.ai/en/stable/understanding/loading/loading.html [4] kzbin.info/www/bejne/kJuYg3atmrp7f80
@saadowain3511
@saadowain3511 8 ай бұрын
Thank you Talebi. No one explains the subject like you
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Thanks :) Glad it was clear!
@abhijitroy8931
@abhijitroy8931 3 ай бұрын
Agreed
@SathishkumarKarunamoorthy
@SathishkumarKarunamoorthy 2 ай бұрын
That was a very clear and concise explanation. I am learning Data Science and find this very useful in understanding RAG. Thankyou so much
@aybmab2
@aybmab2 Ай бұрын
Wow. This was such an amazing explanation of the topic. I know very little of LLMs, but understood this very clearly. Thank you!
@yarinshaked
@yarinshaked 6 күн бұрын
Hey! Thanks a lot for the great detailed content :) Why did you choose to use a fine-tuned model and not just the base model? Does applying RAG without fine-tuning also work? I guess it depends on the case, but just out of curiosity
@florisbokx
@florisbokx 6 күн бұрын
Very helpful, thanks! I found that getting an answer to a prompt takes quite a long time though (2-3 minutes), also using the T4 GPU from Colab. Is there a way to reduce this?
@inishkohli273
@inishkohli273 3 ай бұрын
Finally completed, thank you so much for this content, waiting for the agents video
@ifycadeau
@ifycadeau 8 ай бұрын
This is so helpful! Thanks Shaw, you never miss!
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Glad it was helpful!
@e-Course.
@e-Course. 3 ай бұрын
Thank you for the clear, visually appealing, and easy-to-understand information.
@juliamadeleineheinze2932
@juliamadeleineheinze2932 Ай бұрын
This is a great video, super helpful, thank you so much! Also love the helpful links you provide in the description. Honestly, great content, I'm glad I found your videos, going to watch some more now :D
@ShawhinTalebi
@ShawhinTalebi Ай бұрын
Thanks for the great feedback :)
@nistelbergerkurt5309
@nistelbergerkurt5309 8 ай бұрын
great video as always 👍 does a reranker improve the quality of the output for a RAG approach? like that we could take the output directly from the reranker, right? or what is your experience with reranker?
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Great questions! That's the idea. A reranker is typically applied to the top-k (say k=25) search results to further refine the chunks. The reason you wouldn't use a reranker directly on the entire knowledge base is because it is (much) more computationally expense than the text embedding-based search described here. I've haven't used a reranker in any use case, but it seems to be most beneficial when working with a large knowledge base. This video may be helpful: kzbin.info/www/bejne/i5mck4yfi9eKldU&ab_channel=JamesBriggs
@PayneMaximus
@PayneMaximus 2 ай бұрын
Is it possible to select a "dynamic" chunk size? I want to be able to separate documents in chunks that are of varying sizes; this is because I want to chunk specific sections in the documents that have varying sizes.
@ShawhinTalebi
@ShawhinTalebi 2 ай бұрын
Yes definitely! Chunking docs in this way can lead to better performance than blindly chunking across sections.
@firespark804
@firespark804 7 ай бұрын
Awesome video, thanks! I'm wondering if instead of using top_k documents/batches one could define a threshold/distance for the used batches?
@Anonymous-or5hq
@Anonymous-or5hq 23 күн бұрын
Good work Shaw, appreciate it
@AlusineBarrie
@AlusineBarrie 4 ай бұрын
Thank you for the valuable content - clear, concise
@nataliatenoriomaia1635
@nataliatenoriomaia1635 Ай бұрын
Great video! Thanks for sharing
@vamsitharunkumarsunku4583
@vamsitharunkumarsunku4583 8 ай бұрын
So we get top 3 similar chunks from RAG right, We are adding 3 chunks to prompt template?
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Yes exactly!
@beemdude2
@beemdude2 Ай бұрын
Super nice ! Great practical content
@interess95
@interess95 3 ай бұрын
Awesome, thank you for the video!
@biomedicalit
@biomedicalit 3 ай бұрын
Nice lecture, very informative! I didn't watch the video related to fat tails, but I noticed N.N. Taleb's influence, my favorite author. :-)
@ShawhinTalebi
@ShawhinTalebi 3 ай бұрын
Same here! I actually did his summer school recently: medium.com/the-data-entrepreneurs/i-spent-2-995-on-nassim-talebs-risk-taking-course-here-s-what-i-learned-c442a55a2c64
@michelleming6465
@michelleming6465 2 ай бұрын
Thank you for the useful content. Where could we find the exemplar code for soft prompt and prefix tuning as shown in your video? 😊
@ShawhinTalebi
@ShawhinTalebi 2 ай бұрын
Example code is available here: github.com/ShawhinT/KZbin-Blog/blob/main/LLMs/rag/rag_example.ipynb
@Allin1UniversalChannel
@Allin1UniversalChannel 2 ай бұрын
Great content! One question, please: in your example, is everything local and private, or does the data leave your execution environment?
@ShawhinTalebi
@ShawhinTalebi 2 ай бұрын
This example code doesn't make any external API calls so it can run entirely locally given. However, I ran it on Google Colab since the quantized model I used cannot run on Mac (I only have Apple machines)
@candidlyvivian
@candidlyvivian 5 ай бұрын
Hey Shaw, thanks so much for such a helpful video. I''d love to seek your advice on something :) Currently we are using OpenAI to build out a bunch of insights that will be refreshed using business data (i.e. X users land on your page, Y make a purchase) Right now we are doing a lot of data preparation and feeding in the specific numbers into the user/system prompt before passing to OpenAI but have had issues with consistency of output and incorrect numbers. Would you recommend a fine-tuning approach for this? Or RAG? Or would the context itself be small enough to fit into the "context window" given it's a very small dataset we are adding to the prompt. Thanks in advance 🙂
@ShawhinTalebi
@ShawhinTalebi 5 ай бұрын
Glad it was helpful! Based on the info provided here, it sounds like a RAG system would make the most sense. More specifically, you could connect your data preparation pipeline to a database which would dynamically inject the specific numbers into the user/system prompt. If you have more questions, feel free to email me here: www.shawhintalebi.com/contact
@examore-lite
@examore-lite 7 ай бұрын
Thank you very much!
@jagtapjaidip8
@jagtapjaidip8 6 ай бұрын
very nice. thank you for explaining in details.
@drewgranieri3629
@drewgranieri3629 2 ай бұрын
Thanks for the content! Quick question: when setting up the knowledge base in your example code, you process the medium articles to not include specific chunks. how much of a difference does this actually make in your output? I only bring this question up because lets say you were going to use RAG to make an LLM application where the inputted documents do not follow same concrete structure of medium articles. it would then be pretty challenging to identify all the useless chunks you would not like to include right? do those embeddings make a significant difference in the quality of your output?
@ShawhinTalebi
@ShawhinTalebi Ай бұрын
Great question. How you chunk documents can make a big difference in the quality of your RAG system. Doing this right will require data exploration so you can define a pre-processing strategy for your specific use case. I often find that this isn't as challenging as it might seem at the outset.
@BookshelfJourney
@BookshelfJourney Ай бұрын
Well explained
@zahrahameed4098
@zahrahameed4098 6 ай бұрын
Thankyou so much. Becoming a fan of yours! Please do a video on Rag with llamaIndex + llama3 if it's free and not paid.
@ShawhinTalebi
@ShawhinTalebi 6 ай бұрын
Great suggestion. That's a good excuse to try out Llama3 :)
@edsleite
@edsleite 6 ай бұрын
Hi Talebi. Thanks for all you show us. But one question : I did your code with mine database, without the fine tuning and it works, very quickly answers but poor contents. That is the point of fine tuning make better answers ?
@ShawhinTalebi
@ShawhinTalebi 6 ай бұрын
It sounds like you may need to do some additional optimizations to improve your system. I discuss some finer points here: towardsdatascience.com/how-to-improve-llms-with-rag-abdc132f76ac?sk=d8d8ecfb1f6223539a54604c8f93d573#bf88
@michaelpihosh5904
@michaelpihosh5904 8 ай бұрын
Thanks Shaw!
@ariel-dev
@ariel-dev 8 ай бұрын
Really great
@deadlyecho
@deadlyecho 7 ай бұрын
Very good explanation 👏 👌
@lplp6961
@lplp6961 7 ай бұрын
good work!
@parkerblake-l6e
@parkerblake-l6e 3 ай бұрын
Can we connect this with a Rasa chatbot? I'm building a Rasa chatbot to ask customized questions from users and provide output according to their responses. Can I integrate this model with my chatbot?
@ShawhinTalebi
@ShawhinTalebi 3 ай бұрын
While I haven't used rasa before, it seems they support RAG. rasa.com/docs/rasa-pro/building-assistants/chat-with-your-docs/
@TheLordSocke
@TheLordSocke 6 ай бұрын
Nice Video, any ideas for doing this on PowerPoints? Want to build a kind of knowledge base from previous projects but the grafics are a problem. Even GPT4V is not always interpreting them correctly. 😢
@ShawhinTalebi
@ShawhinTalebi 6 ай бұрын
If GPT4V is having issues you may need to either 1) wait for better models to come out or 2) parse the knowledge from the PPT slides in a more clever way. Feel free to book office hours if you want to dig into it a bit more: calendly.com/shawhintalebi/office-hours
@halle845
@halle845 8 ай бұрын
Any recommendations or experience on which embeddings database to use?
@ShawhinTalebi
@ShawhinTalebi 7 ай бұрын
Good question! Performance of embedding models will vary by domain, so some experimentation is always required. However, I've found the following 2 resources helpful as a starting place. HF Leaderboard: huggingface.co/spaces/mteb/leaderboard SentenceTransformers: www.sbert.net/docs/pretrained_models.html
@bangarrajumuppidu8354
@bangarrajumuppidu8354 7 ай бұрын
superb explanation Shaw !😍
@TheRcfrias
@TheRcfrias 6 ай бұрын
Rag is great for semi-static or static content as knowledge base, but which path do you use for dynamic, time-relevant data like current sales from a database?
@ShawhinTalebi
@ShawhinTalebi 6 ай бұрын
That's a great question. The short answer is RAG can handle this sort of data (at least in principle). The longer answer involves taking a step back and asking oneself "why do I want to use RAG/LLMs/AI for this use case?" This helps get to the root of the problem you are trying to solve and hopefully give more clarity about potential solutions.
@TheRcfrias
@TheRcfrias 6 ай бұрын
@@ShawhinTalebi Its a common use case at work to know how sales have been improving during the current day or week. It would be nice to know how to link the LLM with the corporate database for current information and reporting.
@orvirt8385
@orvirt8385 6 ай бұрын
Great video! What is fat-tailedness?
@ShawhinTalebi
@ShawhinTalebi 6 ай бұрын
😉 kzbin.info/www/bejne/jZTUpWdvmb2no5osi=E_R7A7IrkbAUVaOs
@tomasbusse2410
@tomasbusse2410 7 ай бұрын
Very useful indeed
@Pythonology
@Pythonology 8 ай бұрын
Happy Nowruz, kheyli khoob! Question: how would you propose to evaluate a document on the basis of certain guidelines? I mean, to see how far it complies with the guidelines or regulations for writing a certain document. Is RAG any good? shall we just embed the guidelines in the prompt right before the writing? or shall we store the guidelines as a separate document and do RAG? Or ...?
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Happy New Year! That's a good question. It sounds like you want the model to evaluate a given document based on some set of guidelines. If the guidelines are static, you can fix them into the prompt. However, if you want the guidelines to be dynamic, you can house them in a database which is dynamically integrated into the prompt based on the user's input.
@nirmalhasantha986
@nirmalhasantha986 5 ай бұрын
Thank you so much sir :)
@Blogservice-Fuerth
@Blogservice-Fuerth 8 ай бұрын
Great 🙏
@halle845
@halle845 8 ай бұрын
Thanks!
@ShawhinTalebi
@ShawhinTalebi 7 ай бұрын
Thank you! Glad it was helpful 😁
@ridg2806
@ridg2806 6 ай бұрын
Solid video
@jjen9595
@jjen9595 8 ай бұрын
hello, do you have a video showing how to make a datasett and upload it to huggind face?
@ShawhinTalebi
@ShawhinTalebi 8 ай бұрын
Not currently, but the code to do that is available on GitHub: github.com/ShawhinT/KZbin-Blog/blob/main/LLMs/qlora/create-dataset.ipynb
@peymannaji
@peymannaji Ай бұрын
I found good content here, are you Iranien ?
@ShawhinTalebi
@ShawhinTalebi Ай бұрын
Thank you! Yes I am :)
@CppExpedition
@CppExpedition 5 ай бұрын
what do you mean with 'not to scale?' isn't the book at the size of the earth?
@ShawhinTalebi
@ShawhinTalebi 5 ай бұрын
LOL 😂
@raviyadav2552
@raviyadav2552 4 ай бұрын
super helpfull
@scubasquadsteve
@scubasquadsteve 2 ай бұрын
tailEDEDness! can't unhear it 18:44
@ShawhinTalebi
@ShawhinTalebi 2 ай бұрын
LOL made up words can be hard to pronounce 😂
@JavierTorres-st7gt
@JavierTorres-st7gt 5 ай бұрын
How to protect a company's information with this technology?
@ShawhinTalebi
@ShawhinTalebi 5 ай бұрын
Great question! One can approach data security with RAG in the same way as other contexts. In other words, you can set up a permissions layer so that the LLM can only access information consistent the user's permissions.
@susdoge3767
@susdoge3767 5 ай бұрын
great channel subbscribed!
@arshakcms
@arshakcms 3 ай бұрын
8:20 Large Language Models Only Understands Text? They Can Recognize images and all right?
@ShawhinTalebi
@ShawhinTalebi 3 ай бұрын
Great question. Language models only understand language (text). However, we see products like ChatGPT and Claude handle them just fine. There are two ways to do this. 1) Pass image to img-to-text then pass it to a language model 2) Create a multi-modal model (e.g. GPT-4o) which can take text, images, and audio as input
@yameen3448
@yameen3448 5 ай бұрын
Vector retrieval is quite shite. Trust me. To improve accuracy of retrieval, you need to use multiple methods.
Fine-tuning Large Language Models (LLMs) | w/ Example Code
28:18
Shaw Talebi
Рет қаралды 358 М.
What is RAG? (Retrieval Augmented Generation)
11:37
Don Woodlock
Рет қаралды 171 М.
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 101 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 27 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Qwen Just Casually Started the Local AI Revolution
16:05
Cole Medin
Рет қаралды 84 М.
QLoRA-How to Fine-tune an LLM on a Single GPU (w/ Python Code)
36:58
RAG vs. Fine Tuning
8:57
IBM Technology
Рет қаралды 62 М.
RAG + Langchain Python Project: Easy AI/Chat For Your Docs
16:42
Generative AI in a Nutshell - how to survive and thrive in the age of AI
17:57
OpenAI Embeddings and Vector Databases Crash Course
18:41
Adrian Twarog
Рет қаралды 499 М.