Talk to YOUR DATA without OpenAI APIs: LangChain

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a lot of you have been asking how to do inflammation retrieval in leg chain without using open AI so I thought it would be nice to make this video and showing how to use other open source models with land chain so in this video I am going to show you how to do information retrieval from text and PDF files without using open AIS embeddings and without using open area large language model in this video we will be looking at two applications first we will deal with text documents and introduce different concepts and models and then we will look at how to work with multiple PDF files so first we need to install some of the required packages in this case we are installing link chain hugging face Hub and sentence Transformers next we need hugging face Hub API token since we're going to be using models from having face in order to get the token go to your hugging face account click settings and then under settings you will have these access tokens you can create a new token or use an existing one if you already have one uh side note always make sure if you're sharing Google collab notebooks always remove your tokens in one of my previous videos I forgot to remove my openai API token and it was a costume mistake next we need some data to work with so in this case I am just using state of the unit address but that is an example provided within like chain Library so what we are doing it here is we are importing the request Library so here is the URL of the text file that we are going to read then based on the URL we used request library to get the text file and we write it to a file name state of the unit dot dxt when I execute this cell the file will be stored on my Google Drive next we are using the text lower function from documents loader to load a text document now if you run this we can actually look at the content of our document now we have our document next we want to divide it into smaller chunks so that we can fit this into our large language models or embeddings each model has a specific token size so in this case we are choosing a token size of 1000 and you want to make sure that it doesn't exceed the token limit of the model that you're going to be working with so we're using character text splitter this will convert a document into chunks of 1000 tokens and those are going to be stored in this documents object there are a total of 42 chunks and here is the first chunk next we want to compute embeddings from our documents so in this case we're using embedics from hugging face instead of open AIS embeddings now this is not the only type of Open Source synthetics that like change supports there are actually a number of different embeddings that you can use so here is a list of text embedding models you have the open AI that is Nama CPP cohere you can use fake it bitings and there is instructor bearings as well so have a look at these depending on the application that you're working on you want to select specific type of embeddings keep in mind that the best embedding is currently available are opened Aisa beddings but those are not free so in this case I'm simply creating an object of embeddings right now we need a vector store for information retrieval so in that case in this case we are using this face CPU and so you just need to install it I think I already have it okay there are other Vector stores as available in the LinkedIn you can check out a comprehensive list here next using these embeddings we need to embed our document so in this case we're using from document pass on our documents or the chunks that we create right and the corresponding buildings and this variable is now going to have embedded document so let's run this it's essentially a database a vector store of the embeddings from our document I have a very detailed video on the topic so I'm going to put a link to that video if you're interested watch that out for more comprehensive coverage now in order to do a query on our documents so we get the query calculates its embeddings and then do a similarity search between the creating and the document set battings so for example in this case the query is what did the president say about the Supreme Court using similarity search it will find the documents that had the text closest to this text so it came up with a few answers yeah so for example here Justice Stephen prayer talking about the United States Supreme Court then again here right so there's a couple of places based on the similarity search it found now these results are solely based on the similarity search now you can also integrate this with a large language model to do a q a based on your text files next I want to show you how you can integrate this as a part of question answer chain using under action language model so in this case we're loading the question answer chain from question answering then we're using the hugging face Hub right the large language model instead of openness model we are using is the Google man D5 Excel right so it will get the large language model from hockey face next we need to create a chain so in this case instead of open here I added I'm going to pass on this llm that I created and let's run this we have our chain in order to run a query or a prompt here is what we do so we have a query then find it then do the similarity search on the documents based on the embeddings that we provided and then the change will simply change the creating and the documented together to get the response let's run this all right and here is a response based on the information we've provided so one of the most serious constitutional responsibility for president has is nominating someone to serve on the United States Supreme Court now this is basically a question answered what that you can create here is just another prop the diagram using the same chain so what did the president say about the economy that he said the responses built the economy from the bottom up and middle out not from the top down all right just keep in mind that the responses may not be really accurate because uh the model that we're using this is not as good as open air as models but it's free and you can experiment with it next I wanted to show you how you can do the same with multiple PDF files this is going to be a little different than what I had in another video but I think it would be something interesting we're going to be using the same basic concepts that we just know so first you need to install the required packages next we import two different functions so unstructured PDF loader and Vector store index created this is the function when all the magic is going to happen next we accept the connecting Google drive to this Google column DOT book so I have a folder within my Google Drive called Data underscore 2 and it has two different PDF files one the first is this paper and or the technical report on GPT for all and then there's another paper related to lip syncing next we are creating Lotus to load our files now since there are two PDF files the result will be list of two loaders next we will look at how do we create Webster store so this function Vector store index created accepts embeddings in this case we are passing on the hanging phase embeddings that we had already earlier defined and then we are dividing our documents into different chunks right so a chunk size of 1000 and then pass on the loaders that we had so this will basically has embeddings uh created from these documents now if you read this you would probably seen this warning decline 2 is not installed uh that's absolutely fine you can simply ignore it it's simply uh defects the speed but I have found that if I try to install this it throws an error so I'm going to ignore this next we need our large language model that we are going to be using for question answer so in this case again I'm using the hugging face a hugging phase Hub and getting a flan T5 model from Google instead of openness DaVinci models for our information retrieval we are using retrieval with q a chain so in this case uh we pass on the large language model that we just created uh chain type is stuff and then the retriever is the index store that we created by default it's using chroma DB we could actually change this but uh I think I left it to default so instead of files it's going to be using Chrome ADB and then the input key is going to be a question so that's the prompt or the query that we're going to do it passing it on all right so let's run this so now we are ready to turn our query so that the way you do it is you have a chain.front and you pass in your query so let me ask it how is the GPT form or trade and it says using Pandora now uh let's run another one so let's see we'll call our key authors typically for all technical report okay yes and I think it's uh it got only the first author uh you can play around with the maximum length and stuff so you get better responses so there you have it I just may want to make this quick tutorial on how you can use open source models instead of open AIS models if you don't want okay uh hook you found this helpful if you have any questions or comments please put them in the comment section I would love to answer them if I can't thanks for watching see you in the next one
Info
Channel: Prompt Engineering
Views: 68,737
Rating: undefined out of 5
Keywords: prompt engineering, Prompt Engineer, natural language processing, GPT-4, chatgpt for pdf files, ChatGPT for PDF, langchain openai, langchain in python, embeddings stable diffusion, Text Embeddings, langchain demo, long chain tutorial, langchain, langchain javascript, gpt-3, openai, vectorstorage, chroma, train gpt on your data, train openai, train openai model, train openai with own data, langchain tutorial, how to train gpt-3, embeddings, langchain ai
Id: wrD-fZvT6UI
Channel Id: undefined
Length: 11min 6sec (666 seconds)
Published: Tue Apr 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.