The easiest way to chat with Knowledge Graph using LLMs (python tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey wison yeah what is knowledge craft do we need it to enhance our LM performance oh and also do you know how to integrate it with L chain okay guys hold on take it easy I will explain to you in detail step by step stuff from the per and how to set up our Na 4y databas and then how to integrate it using L chain and of course all of that we will use an open source all app so without further ado let get started what is no squas Once Upon a Time way back in 1736 there was a sweet M named Leonard eer who faced a mindbending challenge the seven breach of kbur problem is there a way to walk across all bries ones starting and ending at the same place eer heis something more crucial what matter was how things were connected so you turn the city's lanmark into dots or nodes and its preaches into lives for ages creating a neat little Network known as the origin of the graph Theory story time is both for SP hold on instead of just buing about landmarks and Brides now Las thing be so he mention notes as to the adjective such as people buildings schools bands and many more and that the ages as the relationship B them for example there is ammy working at a bank and chatting away in Mand now house and Brian also B bound who loves fried R oh there's also an Brian's friend who is btic for fried R too and also FL in Mandarin sounds a bit Tangled right but look at the graph we have got suddenly all starts to make SS now with the idea of notes and ages and the team in relationship with this VRA hey let's get our world is not just a and Amy and Brian it's not just about B and fr price too right so it's a fast thrill of people teams ads and all of those have this special relationship and that's what we call as a knowledge craft so once again knowledge craft is a network of real world entities and and illustrates the relationship between them over we store the no scub in a graph database such as na Forge database and process it using cyber query language n cyber query language includes claes like use match read rer and more you can delve into them further with this new 4G chit now let's talk about how ncft EMP powering alen so using a noge graph you can identify the links even Sly disconnected C what do it means so February 2024 researchers from Microsoft conducted a research to compare Bas retrieval out Meed generon system or rack and graph rack danus filot incident information for a news article data set and the posit questions what has no forus yet done the result baseland white not able to answer it because sometimes using factor is not was a facted especially when the query does not provide enough context about its true intent or when the context is fragment across large corus of tax you probably have hearded about Plus in the middle things and that's the problem and they Pro that gra able to answer this questions because first the about entities which has no FIA this allows the El them to gr itself and then provide a fair to answer in November 2023 there is also a resarch that show how noge gra optimize the SE in a SQL database the researchers revealed that question answering using gbd4 with zero shut problems directly on SQL database achieves an accuracy of 16% notably this accuracy increases 54% when questions are posed over a Knowledge Graph representation on the Enterprise SQL database okay so that's the reason why learn knowledge SC our LM is very interesting and important and before we go into code it's better for us to understand how it works so first in here we will get the user question and then we'll pass this user question to our LM in this TP our LM will also receive a database schema database schema means like the entities and relationship that we already Store to our new forg database and the whole process in here we call it as the graph chain and then from the graph team it will generate a cyber query and then we will run the Cyber query to our new for database to get a result and the result we will pass it to the LM in here the LM will pass the result we create result into our final answer and this St we will get the final one okay th the Cod so actually all the code the data I've already provided in this GitHub and I already put it in the description so the first thing that we need to do is just to clone this so just copy and then go to our FAS code and do K Club here okay guys what stand our next St will be creating a virtual environment so just go to our folder and then do pip install it this it will take a few seconds so I will skip this part now let's open the notep that we have in here so since three already installed all the buttons they from the install that we've just done before so let's run this one so in here all go say we going to use open source L which is the Gemini and then having face and also near so I'll go work on how to get the API for all this but before that we need to cre F to sa B variable and just do this the Google API key so just go over this URL and then or create API if you can have it and for Hing face just follow this link and then use new token but since I already have this tokens so just copy and then save our envirment fre aable and for near forg actually can use my near forg desktop or for this I'll use near hour is uh little simpler so if you don't have a con you should sign up in here okay so the instant is ready and now like click open okay so in here we have the connection URL in here we have the database user and also password make sure to also copy the connection URL and the database username to the environment variable the file so right next is copy paste the password and like connect now the database is connect connected and now the next test is how to connect the python in here to the our database in n4g so actually lch ready provide us with a very simple connector which is this one lch Comm manity to C na for C here so just click run it's all done okay guys so we have done to set up everything so now let's talk about the data itself so the data that we will use in here I will keep it simple we won process a data from the unstructured format such as the PDF the text file no but in here we will use from data from Koo so that is for Manus Kumar for providing this data set so basically is a Linkin data set at professional information like the me the CP and and caring company that they work in the position and many more and actually year we did a little bit preprocessing to finally get this final data the next thing is how to insert this data to na for database so as you can see here says our data in na forg is still empty to know zero and the relationship zero and you can also check it by run to cell you can in here there's nothing in here so how to input it so the first thing that in here is by using the Cyber query to interact with our databit now I'll explain one by one startop from here load CSV with headers from blah blah blah blah so actually it's loading the CSV file from this gith repository and then as R me file for each row and in here is a cyber query inside so we known that okay in here name is the entity of name is person so we make it to Define The Entity that we have in our database so here it's a little bit different with the previous one right so basically we use for is because if you see in the language in here sometimes one people speaks man languages such as Roberto Mira he can speaks English Italian France Dutch and German so here we separate with this s and this line is talking about the relationship if you don't remember about the explanation about relationship entity so this one is the relationship or the ages just run this one okay and let's check it okay so now our data is already in the Nao forg database and check once again let's reload this okay see now we have the company now we have ocated at Country industrial language all the data in from CSP is already imputed in our NE for okay guys now let's talk about the most interesting part of this video how to operate the light L model to interact with our knowledge gra in NE so here we are using chap Google generative AI German Pro open source and then the API can here is the parameter that we have saved if we in file and in here we set the temporate to zero the question is why do you not set it to 0.5 or 0.9 the reason is because in this test we need the LM not to do a creative writing but we needed to translate the natural language to a cyber query language and then here the chain with the chain with graph cyber Q L has provided very easy to use so the graph is the graph that we have defining here and LM is the model that we want to use and for both I set it to close through what does it mean because I want to understand what happened Beyond LOL so right to and then in here we have several questions I've already created a table that contains a pair of the question and the correct answer so it becomes easier for us to check whether the answer resulted from the LM is correct or not we want to know how it's perform so let's run it okay that's cool okay so now let's talk how about result so the first questions L companies and advertising Serv industry in here it gener that cyber Under full contacts is said and J is Tob creative B advertising that's perfect and the second question is a working graduated from cyber FR University is currently employed at okay I'm not sure why but the J cyber query in here look a bit messy and that's why there's a no in the Contex are the result is I do not have the information we filed here and then the third question where is Power LS working okay so sure the J cyber query is correct and the full contact in here tobox cre if this is correct but I don't sure why the Finish Ching here IEM at the answer the four questions we see po here which actually if you remember about the schema of our database the relationship there's no spoken in in our database right so that's why it's no and I didn't have that information the last one is okay problem is the same is not actually it's kind of hting about relationship by the properties by entities right because we don't have relationship is native of in our schema so that's why it's also wrong the answer is zero the correct answer is one now let's do quick recap the result that we have got before so here we have two correct answer and three false answer from the elet right and from this result we can identify some problems the first one is not being able to accurately translate text into a cyber query and the second one is hallucinates properties relationship and entities this one is one of the biggest problems in llm in generating a cyber query so what's the solution we called it as prompting strategies so in short we provide examples to our model to help it understand the structure correctly similar to how parents guide us when we learn to work right more examples makes the models learns and smarter now let's jump to code so the first thing that we need to do is to create pairs of question and sever query so I do it manually just copy this and paste the jity okay once we got a result so just copy and paste it to our psod for example in here I want to copy this questions and the most important part is to treat attack once again if the jtic query from the jity is already not we can do this by going to our new copy paste and check okay good we have this the C queries right just do all that and copy ping here the last thing that you need to do is to add places in here because if you don't do it you I've already have this one so I won't use it I'll use mine to this friends and in here actually langin already provide us with a f shot prom template and so prom template this is the problem that we want to use that we use as a parameter in here and the example is is example that we have already divid in here so it will take the top three examples from it and then the perfect s and here is the input variables which is equation and schema we'll use it equation in this and the schema in here so run this one this is the example of the problem let's create our second change and check this for the first question the answer is correct to box creative big advertising into people school and for the second question we get a correct answer which is elastic pad and in here we got toolbox creative but the four question the Gen cqu is also correct and we get here fali new and then for the last one okay we got a card corre answer though which is one so using the problem strategies will enhance our model right now we have all correct answer okay guys our job is done but as I've told you before that I have a bonus for you so if you're still remember we have this question where do Michael work and the problem that we got is which workers friends what industries a workers named animal associated with and we workers live in Canada and speak German so actually there's no correlation right between which workers friend and where do Michael and the reason is this line so in here we are taking top three from this list in fact we have more than three questions so what's the point to just only take this top three and that's why we need a dynamic problem so to create a dynamic problem we need a semantic similarity example selector so basically you calculate which one is the closest between the question and the Leist that we have so the first one that you need is the haing fees eddings and then the for Factor so previously we are taking the top three question from the examples list now we will use the example selector to create a dynamic Pro if you run this so where do Michael work what companies the workers named John working it's makes sense where the workers named Alice live and and what industrious of workers named amul Associated so right now the generative prom is more Dynamic and we're not just take top three from our list okay guys so we have learned about what is NOLA gr why is it important how to set up our data in May for database how to chat with our data using lank chain and open source Lam and last but not least how to enhance our model I hope this video is useful for you guys and if you have any thoughts pleas for commment so please let me know in the comment section below bye-bye
Info
Channel: Geraldus Wilsen
Views: 6,993
Rating: undefined out of 5
Keywords:
Id: KMXQ4SVLwmo
Channel Id: undefined
Length: 18min 35sec (1115 seconds)
Published: Tue Apr 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.