Using Large Language Models with the Cohere API
Key Takeaways
The video demonstrates how to use the Cohere API for large language model tasks, including text generation, semantic search, and information extraction. It provides a hands-on guide to setting up the Cohere API, generating product titles and descriptions, and building a semantic search engine.
Full Transcript
hello everyone and thank you for joining today's code along my name is Rhys and I'll be your moderator today we're going to kick off today's session in a couple of minutes we're just waiting so everyone has the chance to join in the meanwhile though we'd love to hear from you so let us know where you're joining from using the chat or the comments depending on what platform you're watching from and yeah tell us something that you'd like to get out of today's webinar uh today's code along is hosted on datacant workspace I'll be posting a link shortly in the chat so that you can code along with us so yeah if you don't already have a data workspace account please sign up for one and yeah you'll be able to code along with us as well um also today if you'd like the recording and any of the resources sent to you afterwards if you need to leave early or anything like that then please uh register for the event you can do that either by heading over to our LinkedIn page or I'll be posting a link uh to do so in the chat shortly as well so keep your eyes bill for that brilliant I think that's everything from me for the moment I will be back to repeat this message for any new Jordans shortly but until then enjoy the background music hello everyone and thank you for joining today's code long my name is Rhys and I'm going to be your moderator today we're going to kick off today's session in about a minute or so we're just waiting so everyone has a chance to join in the meanwhile though we'd love to hear from you so let us know where you're joining from using the chat or the comments depending on what platform you're watching on and yeah tell us something that you'd like to get out of today's webinar uh we are doing the code long today so if you want to code along with us make sure you've got a data Camp workspace account and uh yeah keep your eye out for the link that I've sent in the chat I will be sending it again shortly um but yeah keep your eyes in the chat for the link to code along with us as well as the link to register for the event so that you get uh the recording and the resources sent to you as well brilliant I think that's everything from Mixon 900 over to your host for today's session Richie Richie please take it away hi there data scamps and data champs this is Richie now we've had a few code alongs recently where we've explored using large language models for well a variety of tasks and I'm very pleased that today we've got a world premiere for you all this is our first ever session on the cohere API so I hope uh you're all dressed up fancy for this premiere and uh we've got a really fun use case around product descriptions uh which is also incredibly useful so I'm sure uh whenever you've done some online shopping you'll know that product descriptions are often absolutely rubbish and so getting AI to help make them better is a huge win for Shoppers all over the world not to mention the people who have to write those product descriptions in the first place now our guest today is Bridget dunluck here he's a machine learning engineer at cohere where his job is to help build and improve the company's large language models and he's got a wealth of experience in both natural language processing and deep learning across banking retail and edtech so with that over to you Richard uh especially for the introduction hello everyone who's joining in uh uh I'm working at cohere as which he said as a machine learning engineer and today I'll be just starting off with some introduction that's what we are going to do what is our goal and you know even as to why we should even pursue learning about cohere or any sort of natural language or machine learning API so let's get started so uh about this case study today that we'll be talking about so with respect to data that we're going to use we're going to do two parts of it one is we are going to generate data using the cohere VPI such as product descriptions for titles and we are going to use a product data set which is something that most of the companies or people might have it in their databases and they would like to make maximum use of those and use artificial intelligence in order to extract informations from them uh so that's the way where we are going to use data then we have a primary goal which is for us to understand how we use cohere API so you all can build your products and power them with AI and the secondary goal is to get an insights into like what are the capabilities that llms have which is not just generating text or something but there's something more and creative that you all can do it we're using just the apis rather than thinking and scratching but how do I maybe train my own machine learning models or maybe even you know think about how do I get this infrastructure so go here provides you this API where you don't need to worry about all that and just focus on your software development process and make creative an amazing products any last question is like why do you attend a webinar or related to AI or related to cohere the thing is because uh in this generation now ai has become the new fuel I would say and with the help of AI you can create so many intelligent agents that will not just help ease your life personally but even help you immensely improve your productivity so that's from me about the case study now I'll talk a bit about what cohere provides so here provides you foundational language models so these are huge machine learning AI models that are trained on lots of text and in order for a person to you know normally train all these sort of texts and everything else it takes lots of millions of dollars of Investments and lots of other sort of infrastructures and hiring machine learning experts and all which might be a tedious task for any sort of a team so coher provides two sorts of models one as the generator model and the embedding models uh these are the two ones that I'm going to discuss today and with the generative models you could do multiple sorts of uh tasks and like text generation text summarization uh and with embedding models you could do classifications search that's something that we'll be looking upon and we even have a latest offering that just came out which is the retrieval augmented generation which I'll just talk a bit about at the end of uh this session uh next we'll go on to like some of the different llms that go here provides via its API so we have something called as the command and the command idle which are the reflection models of cohere for Generation sort of tasks and the command model is something that we It's a larger model which people can use the command my light model is something that people can use for you know making chat box which has low latency and which works much faster and we have the embed models which are not just in English but we have a multilingual model as well which actually can work across multiple languages and can be used to embed most of your text for doing classifications in Magic search so this was just a bit about the different models that cohere has to provide and the API end of it uh now we'll go on to our workspace uh I hope everyone can just open up their workspace uh yeah so cool uh let's get started with it so welcome again to the code along webinar uh this is just a description for people who would want to even look into it later on to see what cohere does and what are the different apis required you all could just click on this link for example and you should be able to go to the website to see you and read more about the apis yeah uh first we all start off with uh sign up so you click over here into the sign up then go on to try now on the website uh or you could just skip then just go straight away to sign up and then enter your email address uh you should be able to create an account and once you create an account you could be you should be able to log in and go to the apis key tab once you go into the apis key tab you all will have your free trial keys that we'll be using for this workspace and for this code along today I'll just give it on a minute so that people can you know create an account and be able to uh you know access the API keys okay uh yeah so now uh I'll start off with setting up the workspace integration which means that you have your API key it's personal to you you don't want anyone to misuse it so that you know you get build up for all the amount of the tokens that have been used or the tokens have been generated and the requests that have been sent across the OKO here so you all could go to environment stack over your on to your left and once you go into the environments tab you can click onto the environment variables in your workspace you could enter the name which is uh go here underscore key that is the name of the key and you could paste in your API key inside the values over here and press create yep you all can hopefully follow those instructions uh and now once that is done we'll have to do some installation of packages for example cohere itself because it's not pre-installed on the workspace so we'll start off with that initially so let's copy this workspace and let's click it does take a while for it to you know install all the requirements now once you're done with installing the requirements please do make sure to restart your kernel because some of the dependencies need to be activated once the kernel has been restarted yeah now once your kernel has restarted all you need to do is just copy out these Imports and add your cohere key into this particular variable that we have in order to activate it so let's do that if I am giving about another 30 seconds or so so that people can just catch up a bit in case yeah okay so we just done with all the housekeeping work uh now let's begin so consider yourself to be uh this is sort of a usage where I've just come up with so let's consider that you are a tech founder of say a company called Nano Goods it's an e-commerce website where you sell wholesale items and do B2B businesses for many other people and you help you know optimize some supply chain and all the other sort of things with respect to uh establishing and accomplishing B2B businesses and now what's happened is that it's a new company there are very few people in and you're actually short of employees who are in the creative space who are able to make good content for you for example in sense write descriptions for your products that you're able to import from somewhere or you know even make a product title for you so for that reason what we'll do is we are going to use the coherence code or generate API to create some interesting uh I could say product titles and product descriptions so uh for us what we'll be doing is we'll be using the command model so coher provides these Auto model one is the command model the command like and the command might click the command nightly is like an experimental model that gets updated every week so you don't have to wait for new new releases and over here when you look below we'll be looking at the code.generate API so the code I'll generate API consists of a few things one is entering your model name which is which sort of model are you using we'll be using command nightly today then it's the prompt the prompts is about The Prompt is mainly you could say uh a text which contains the instruction or the idea that you want the AI assistant to help you out with so uh you could just end up sort of a text which will be looking for the best of what sort of text we're gonna write then we have something called as a Max token so you want to say you you don't want to generate like three or four paragraphs of a description you want to generate short and concise descriptions so you could even say what's the number of maximum number of tokens you should let the model generate the other thing is the temperature the temperature is mainly a tool which could be used for making sure how creative and interesting your content is uh when the generations happen so it's still uh it's a control that's given to you to determine how interesting and or creative do you want your content to be so you could say a bit uh you could have temperature between like between let's say 0 to 5 we'll be considering a bit of a lower temperature today just so that it makes more sense because you go towards really high temperatures you might end up you might email from the basic idea of what your prompt or what you want the AI system to do as such next we say is the stop sequences they stop sequences is technically a list of sequences in order for a model to identify as to when do you stop a particular generation so you could say that the first time I see a period I would like to stop the generation or the first time I see a new line I would like to stop the generation and then you have something called as a return or likelihoods so the likelihoods technically you could say is How likely a word is to be present in this next sort of a generation for a particular prompt which means that what is the probability of selecting that particular word now that we have the particular word being selected you could even return the likelihood or the probability of these particular words that are there so let's start with our exercise one where now we're going to ask an assistant that since we don't have any creators or merchandise Specialists who can help us with you know creating product titles or product descriptions for your product we would say that we would we would actually instruct the model saying that okay you are an apple merchandising specialist now you need to draft a product title and a product description say for a smart watch from Fitbit and you and we give it more description as to what so that the model understands what sort of uh generation are we trying to provide and watch our description we want so we say that it's a fitness brand it's in the new ocean blue color and has accurate tracking now in order to execute this uh let's first copy this particular code snippet over here and now we have this prompt which is just a normal string text let's just remove the string text and enter our variable text that we have and say we want 200 tokens at the max to be generated yeah I'll just execute this one cell yeah sorry this was an execution that had happened before so yeah so here we have a product title that has been generated by coherence code.generate API so it says Fitbit Versa 3 health and fitness Smartwatch and it says the color as well ocean blue and now over here you have creative description that has been generated as you all can see so it says like you have a or get ready to enhance your healthy lifestyle and keep track of your fitness goals and because we said that we had some Fitness brand and we say that it's offered in a new ocean blue colorway so as you can see it even picks up the new ocean blue colorway so this way we are able to use code.generate simply by just inputting our text and generating these sort of work titles and descriptions uh the other Pro tip I would like to give over here is that the way you're able to instruct it more or you could say you know command or provide more specific instructions to the AI model the better it's going to be at generating the sort of text that you would want and be more creative with it yeah uh any questions Richie if anyone has I'll just take a small break so people can catch up to here all right we don't have many questions from the audience yet so uh if anyone in the audience does have any questions then please do add them to the chat now uh I think for now uh we can just carry on with the code along okay sure yeah uh so now this way you've been able to you know generate product title and product descriptions and you're able to make a catalog off your phone now we'll come on our second exercise which is something called as an auto network search now say for example your company is running really well you've got many clients that are buying your products and that to in large quantities and now you have an inventory management issue that happens on your Tech side where say inventory managers facing facing issues with auto stock products so say a client has a product that once uh a new stock of uh say some sort of toys that has gone completely out of stock that is not present in your inventory also from the manufacturer site and then the client asks you that you know what provide me an alternate product not the same one but probably an alternate product and they might say that they might have their own sort of restriction and sense that I want the same sort of a product but with a similar Dimension or I want a similar product with the same pricing or I want a similar product say which can help me increase my profit margins now what happens in this case is that you don't have a catalog or you don't have annotators who have actually made a database containing all these sorts of attributes where you have a price range where you have a price range that connects with your product description and your product name a product title so over here we are going to use an interesting case where we're going to build a semantic search engine and the semantic search engine would do is it would take in initially your query which is your document which is your item that is out of stock and it would generate and search sorry not generate but I would say it could search for other similar products so a question would be like how is semantic search different from say a normal search now a normal uh keyword search would be you would just match up keywords in your context and you would provide search results based on it but what happens in case of semantic search is the search is done based on the meaning of the sentence and based on the meaning of a sentence you even if the sentences don't have similar looking if they don't have the same words that match but they have similar sort of words through synonyms that they understand they will be able to you know retrieve those sorts of documents uh similar documents that you require for your query so over here what we'll be doing is two parts to it where first we'll be building a semantic search engine where we are able to retrieve similar products for the product that is out of stock using our code embed API and then what we are going to do is something called as Dimension extraction because we say we have a client that says that we want a similar product but we want almost similar Dimensions we don't care about the price point so for that say we don't have another database that consists of you know a sort of a category with respect to a product name and a dimension so from the context on from the product name we'll be extracting the dimension as well and for that we'll be using code.generate and once we do that we will rank them on basis of the closest Dimensions to the uh reference product that has been out of stock so this is the pipeline that we'll be following where we have the product name uh that goes into a semantic search engine to find out the alternate products once we get the alternate products we extract the dimension parameter from these product names and then use them to rank our all our our search recommendations for the product that has been out of stock uh hopefully that's clear Richie any questions does anyone have maybe I just so that they're clear bound this point actually uh we have got a couple of questions from the audience uh oh well third one question uh let's put that on screen so this comes from Alex Alex I think um is can cohere crawl the website rather than providing a CSV file or do you need another tool to do this oh yeah so from the previous section uh when you use code.generate it doesn't crawl any sort of website or CSV right now uh this is all embedded within the model that has learned across multiple data sets and all that we have trained at go here so you don't have to worry about it looking into another sort of search a website where it does all these other Generations all these Generations are some things that it has learned over time over multiple sorts of training that has been done on the module you wouldn't need to worry about the fact that it's going on any search engine or anything like that okay so this is all um stuff that's built into the large language model rather than yes yes okay all right uh that was the only question for now so uh you can continue yeah so in order for us to build this semantic search engine we'll be using Co dot embed so code embed is an end point on API endpoint that coher provides for embedding your text and your queries and your documents and what have and the reason why we do that is it converts these embed in this it converts these texts into meaningful representations which can be later used for classifications or it could be used for semantic search or you know toxicity detection and all these other sorts of methods and this is all provided just to an API you don't need to train any sort of a model at the moment you can straight away just use it out of the box and code.embed is multilingual which means there is a multilingual offering as well to code out embed which means that you can do multilingual semantic search which means you can add a query in a in a different language and get results as well in the different language that you want so that's like a multilingual semantic search and you could even do something called as a cross-lingual search which means that you ask it a query in one language and it will return a result to you in another language if that's present for you within the sort of documents or the data set that you're providing for it to search on or for it to uh you know do some sort of classification so that's a really powerful tool I would say because a lot of diversity and reaching out in terms of a huge number of customers and audiences okay so this is semantic search uh where you all could read a bit about what semantic search is still more and to be honest semantic search can be used to even power your internal web search engine where you could write a python script or any sort of a script in order to you know say write a natural language to extract a document of a particular date or say a document that contains some sort of a task that you wanted to do so it's a really powerful it's like a sort of a search engine just built by yourself for your own requirements and the other powerful use case would be like creating a stack Overflow assistant say for your documents using natural language queries because we know that even as coders a lot of time takes a debug you need to search an aquarium say Google search or some other browser and we have to go through a lot of multiple go through multiple sorts of documents to understand what sort of way of identity so this is a powerful tool that way so over here we're gonna follow three steps um one is we will proceed with uh the following steps is get uh the uh product names uh that we have for or for our data set that we need to build and which becomes like an archive for us and the other one is embed these archives it means all these product names need to be embedded and since we need to be able to give a representation for all these and then we do a search our nearest neighbor search on the query which is the item that we provide as the one that has been out of stock yep so over here uh we have this one particular um Imports that we need to do for example we need to import numpy we need to import pandas we need to import torch and we need to import regex so uh re so let's go ahead and execute it uh I'm supposing many of you might have to import this I'm just leaving it on the screen for another 30 to 40 seconds in case people need to import these packages yeah once you all are done importing these we are gonna use a data set and Amazon the data set that has the product names and we are going to retrieve just the product names uh for our use case today yeah so we'll execute that cell as well now that we have these product names it's in a sort of a archive it's in a sort of uh represent it's in sort of like you would say a database and now we need to pass through our representation language model our embedding model and so that you could end up getting like a representation Archive of it which means a representation of each of these particular product names so instead of text you'll have numerical representations of these so we'll be using code on embed and uh quite a few things to unpack here so the code of embed uses text and the text over here is your product name and the set of documents that you want to you know embed it's a list of strings that you can provide and then you have the model uh so the model over here is your uh embed English uh light version too that is the cohere embed model that we'll be using so there are other models that cohere provides which is the English large model English small model and the multiplayer model as well yeah so we'll be using this model which has uh a representation of I think 4096 Dimensions yeah I think that's the one we'll be using we have another uh argument called as truncate so the reason why we use truncate is that the embedding models were required a Max token Max context length or token length of 512 so any context any token length in the string which is greater than five and two will be cut out and you uh you'd be able to truncate them to just five and two number of tokens that would then be passed on to get its representations and there are two ways you could truncate them one is you could truncate them at the end of the string that you have or you could truncate them using the start of the string so that way what we have done is we'll be able to truncate these particular uh things if they are if they have a context in more than five and two uh let's execute that over here yeah uh once we're done with that uh what we'll be doing is we're going to do three things one is we'll convert this into a numpy array uh we'll check its shape and we will convert these embeddings into a tensor using a torture tensor and the reason we do that is because we need it to um I could say uh use it for our similarity check that we do later on after we get all these embeddings so we'll use uh I think I did use NP yeah so we'll use NP dot array of say the embeds now once you have the embeds we print these embeds and check the dimensions just to verify that and we converted into a tensor which is using code and so and the torture tensor would be of our inventory underscore array yeah so you should be able to get this result where you're around 10 000 documents and each of them is a representation of 1024 so it was a 1024 representation for zero 69 sorry about that we are using the light model and not the English and then uh model that's it yeah so once you get these uh what I'm sorry I just remove these so that we could later use it for right yeah so now once you've got these embeddings uh we use a DOT product to check how similar one embedding is to the other and in case of a semantic search we have something called as a query and documents so documents is the list of the entire embedding archive that we have like these the all the product names that you have present in your stock and query in our situation is say uh the item that has gone out of stock so over here we have a data set that consists of toys and some Goods so we'll be using this one particular toy where we have it like Marvel black panther Legend series and it's of some 12 inch Dimension and that has gone out of stock for a particular client and the client wants say another Marvel black panther branded uh Toy itself but with similar Dimensions so that we consider is our query now what we need to do is we need to embed these queries first of all so to embed this query we'll be using the same embedding method which is let's copy the embedding over here let's paste it over here to replace these product names and since our query is a string we need to pass it in as a list because the text accepts uh a list of strings right yeah and we do the same and embeddings and we convert into a torch.tensor sensor of the aquarium weddings that we have here so now that we have these tensors we calculate the dot product between the query embedding and all the other product and bearings to see which one matches and which are some of our top uh dot products that we can achieve to say that these are the products that are the similar alternates to the product that have been out of stock so we use a torch or matrix multiplication between the aquarium weddings and the embed tensor and we retrieve the top five dot products that we have we execute that and we then execute this I'll just hide the result just in case people might want to execute it and over here what we do is that we retrieve the product names of the top five uh of the top five similar products with respect to our reference product let's print it out yeah you could just ignore the first uh I could say the first uh uh document the first recommendation because that's the same product since that's present in their data set as well and now you can see that you have these four products that are there so that way you have built uh you know a semantic search engine where you have a powder stock product and you're able to leave similar such products uh just using the coherent API without using a lot of other you know technical functionalities and having to know a lot about machine learning as such uh which any questions um there are some people saying they're having problems with the trial key here so um I suspect is the solution to this just to create a new trial key if you're hitting the rate limit Ed okay yeah so there are instructions near the top of the notebook so basically click on that link there dashboard.govia.aa slash API Geeks there should be a button there saying create a new trial key and then you can save that um in your uh in your workspace environment variables so um if anyone's struggling with this instructions are at the top try creating a new trial key see where you get to we do have quite a lot of questions for the audience perhaps we'll go through with them at the end just uh we just need to make sure 10 15 minutes or so at the end to go through all the questions oh yeah sure yeah uh so now that we have the semantic search that's been built we as we can see we have these the mega six and scale or a 12-inch action figure we would want these to come up on top of our recommendations as compared to the other items which are which now have a dimension or which the which are not close enough to the dimension of an item that is on out of stock so this is just an example where your four items to do it for like 10 000 items 400 500 items and it should be pretty easy to do with just using the embed API that way now we come to another exciting part which is the information extraction so now over here what we would want to do is we would want to extract information from our input text and this too and that too we do this just using natural language without you know instructing the model using any sort of a technical code we will just instructed in a way saying that you know what passed me a sort of a dimension from this text so that's another cool magical feature that I think is really useful that people can just use it out of the box and they don't need to you know have a separate sort of a database where you can annotate stuff or you need a separate database to you know store a lot of these uh separate attributes I could say saves up a lot of your memory and a lot of maintenance on those yeah and to do that we aren't going to use any other if we are right now but we'll be using the same Coda generate API so the code.generate apis you also have seen is can be used for Creative purposes but it can even be used for these sort of information extraction and entity extractions as such so if you try to do this in without using say a coda generate API what you'd have to do is you have to build a regex method in order to understand all sorts of dimensions in order to understand all sorts of different formatting that are being used for the dimensions which could be quite time consuming and you might not be able to take in some edge cases and it might be frustrating due to the upcoming developments it may be in the catalog of your product so we'll be moving forward with this and uh the code I generate a model is going to help to extract Dimensions right now from these descriptions and these are like the four different ways that we are going to work with it first is we're going to prepare an example for prompt which means that an example of a prompt I'll come later to it will create uh the extraction prompt we'll get the data that we have already and we'll run the extraction function on this data what do I mean by prepare the example of for the prompt so what this means is that you have a sort of text but you cannot just go and tell the model you know or just extract the dimension it's like telling a child you know without learning anything that go and do something go and you know give sort of an exam or go and you know uh do a sort of a task that is not that it does not have an idea about so what we do is we provide the model with some sort of example that you know what this is the task I want and this is the sort of an extraction I want so we provide it with some sort of examples like this is a particular product description or product name and from that I want to extract 41 inch which is our Dimension similarly we provided some sort of example so it understands what is it that we actually want from The Prompt that we pass again and as you can see over here we have another product name and over here in this part name we have a thousand inch that has been provided as a dimension that has been extracted in technical terms uh this is called as few short prompting where we provide in some examples of some of the tasks that that we would wanted to achieve over multiple different uh you know instances so let's do one thing is Let's uh initially paste this uh Dimension examples which is a few short prompts into our Courier and run that once we run that what we end up doing is we end up creating these sorts of we'll have to we end up creating these sorts of examples and these examples will then be concated with our input which is all the alternate products that we need to get the dimensions extracted from so I'll give you an example of what we are trying to do over here is we are trying to create this sort of an extraction prompt where we have all are examples and we have the other example from which we'd like to get our dimension and for that I've created this uh complex this class which is called as a dimension extractor the dimensional extractor takes in the example which is the product name the example labels which is the extracted Dimension and the example prompt and the example prompt is something I'll come to it later as to what it means and then we do and then we have a function called as make prompt which actually ends up making the prompt which is the text that gets passed on to the model in order for you to retrieve your uh dimensions and we have the extract which uses the code.generate function and we have changed it to a maximum token of 10 and a temperature of 0.1 because we want a more deterministic answer rather than very interesting and creative answers and we have put in a stop sequence of say you know a new line over here as an example so let's just paste that over here and run that part of the code yeah now once we're done with that said that we have something called as an example prompt now what an example prompt argument does is it instructs your model telling what actually are we trying to achieve so I'll give an example over here uh we can go ahead over here and execute this one particular bus that we have and initialize it so this should help you all over here I'll just keep it on for another 30 to 40 seconds so people can just get acquainted yeah and so now over here what we do is we have this coher mentioned extractor class we do something called the make prompt and say we just pass in an example something called as an input text string what happens over here is you can see that this is the way the input is being presented to the model so you have some sort of context or you could say a preamble tool and you pass in this sort of an instruction extract product description from product name so we have the label we had the product name and this is our example prompt this over here that you can see that our personal assistant is our example prompt and we do that for these examples where we say that you know what this is a product name extract product Dimension from product extract product Dimension from product name and it you give it the answer so the model at the time of inference right now understands the fact that you know what this is the particular context this is what I'm supposed to do and this is sort of resulted once similarly what happens over here is you pass in your input over here input text which I could say is your alternate products uh that we have that we just searched so I'll just take an example uh let me just go back ahead so that it doesn't confuse you on yeah I'll just take in this example over here so that people understand what you're trying to do and let's just replace this input text over here with this context so over here what happens is this is the entire Preamble or the text that has been passed on to the model in order for them to retrieve your dimension for your alternate products so over here you can see that this is what we'll be passing which is the Avengers Marvel black panther six inch scale Marvel superhero action figure and we say it extract the product Dimension from this product name so this is just the make prompt part of it and this make prompt is passed on to your extract function so let's go ahead and execute this particular Loop where it takes every single dimension in your result and it ends up uh providing you your uh it ends up providing you all the sorts of extracted dimensions this might take a bit all right yeah so we have done that and let's okay so here you go so just through natural language just understand your natural language is able to extract six inch 12 inch and for these other product items they did not already mention it returned back month which is a really amazing thing that happens where you just provide a natural language you don't have to worry about any other sort of Maintenance or any sort of other piece of code to take care of it all you could do is just pass in your sort of instructions and in natural language on what you want to do and what sort of information you need and you'll be able to extract it this way now that we have been able to extract these Dimensions we'll be moving forward to working these products now uh in intrusive time what I've done is created this function that is used to rank your product and provide you the most similar products based on the reference of your outer stock products so all you could do is just copy this product and paste it over here it will copy the sorry the snippet and paste it over here and should be able to execute that and once you're done executing that you could execute this other piece of code sorry yeah over here so you can see that we have been able to rank these items based on the most similar dimension for an alternate product so for the product that was out of stock which was a 12 inch laptop of black of say uh an Avengers Marvel black panther item we are able to get a similar product which is the Avengers Marvel and game Titan hero series Black Panther 12 inch action figure and then a six inch scale of some action figure toy that we have so that way you have been able to create an alternate product search engine where you're able to customize it based on any sort of natural language inputs and just using and embedding search method that's there so I hope you all have understood and been able to enjoy through this process of understanding the cohere API and how you can use the code.generate and the code.embed models for your particular purposes and can do all this in like less than you know like 200 lines of code and like less than 100 lines of code and everything in natural language and without the need to worry about maintaining your own sort of an ml system and all those other things yeah thanks that Rishi that was really good I'd say I especially liked a bit about extracting information because that seems like it's really useful for data cleaning because quite often you end up with data which is like a massive text and a lot of this nonsense you want to make it a bit more structured so that seems incredibly useful for that uh we're gonna go to audience questions in a moment I have a question for you so since this was like mostly product focused is that like the the main use case for the cohere API or other other use cases that different teams or different areas of data might be interested in yeah there are multiples so you can use it in like fintech for extracting things from your documents uh it's not just product product was something I thought of taking up because uh this was personally my own experience uh so previously where I work we didn't have cohere API uh we didn't have any sort of a model to do this sort of extraction and I had faced this same personal use case where we had a client who had asked us to give us an alternate product that can help you know increase your profit margin and we didn't have enough data to you know get these sort of Rejects and you know be able to uh get uh recommendations in terms of these sort of rankings and this was a really difficult task this didn't take me much time to you know execute and do it in just like it's a day so that's the reason why this was a bit close to me and I thought of going to the e-commerce product side of it no it's pretty I mean it's such a widely applicable use case and yeah I can certainly see how some of you his cases you know that they take a lot of code and a lot more effort to kind of build up uh but all right uh let's go to audience questions uh so this question comes from uh D analyst 007 a bit of a bonding there all right so I was talking about the semantic search and how it works uh okay maybe can you just go through like how the semantic search just finds does the ranking like how's it oh okay yeah yeah so away you could do multiple things like so semantic search what it does is uh you have content which uh so you have a coheres model that has been trained on a huge number of content and you have representations representations means that these are the numerical meanings of a particular document so whenever you pass any sort of a query or any sort of a text to that particular model it has gone through a lot of text previously and learned all from and the model is learned a lot that it knows what it means now once you have What that particular Vector means in a numerical representation we use a mathematical method called as a DOT product so dot product is technically used to find out similarity so between two vectors because it takes into consideration considering the orientation and magnitude uh and we use a DOT product to find the similarity between the two items and the one with uh which has the highest score would come up on top with respect to a DOT product so that is how you would use a semantic search for similarity purposes okay okay uh nice uh next question comes from Eliza so Elijah asks um is the API multilingual so we were just doing English content here does it work with the languages yeah yeah definitely like that's an offering we have as well uh over here so if you could click onto uh multilingual search you should be able to find uh I'll go to the document yeah you should be able to find document on how you could use multilingual semantic search over here so we do have some multilingual embeddings as well all right do you have a sense of Which languages are supported there I'm not sure yeah there are over 100 languages supported so I'm not okay I'm not gonna list them all then episode yeah yeah I imagine okay so most popular languages supported that's that's good to know yeah yeah I think it's I'm not completely sure of that so yeah you can just check out into the modeling World semantic search document I think it's spelled it in the docs if you go on to multilingual embed models here you have over here where you can go furthermore and do it yeah yeah you have over 100 languages yeah nice nice okay uh we've got one more question for the audience so uh if anyone else uh in the audience if you've got questions for Richard please do ask them in the chat now we've got a couple of minutes left uh this question comes from Matt so is it possible to extract information with the confidence parameter to gauge how confident the model is that the response is represented with the examples you provide okay so yeah uh do you have some sort of measure of how good the answers are uh So currently we just have the likelihoods that we represent uh we return we don't have another sort of uh you know a confidence metric that we use to tell how good as such the answers are but we could say based on the likelihoods that you have to say how probable the outputs are for you to be able to understand on you know the confidence of a particular input that we have yeah okay see I've got some score of just you know yeah yeah okay uh all right that seems pretty good uh okay so next question comes from I don't know from Alex so it's possible to use presidentials election data oh there's another part of this based on sentiment analysis explored that personally myself on uh so we do have a content uh so you could write out yourself and see if you're able to use it across you know like I think based on history it would be able to do but uh the model would not end up providing an opinion for you so I think you should be able to use it yeah but we even go through a sort of toxicity detection and to be able to understand is is there a sort of a bias or is there some sort of toxicity in the content uh before you do a sort of semantic classifications yeah much in the tons of social science use cases there aren't you like so much text Data available all right brilliant uh so before we finish up I just want to talk about uh upcoming webinars so on Thursday we've got a session on best practices for hiring data scientists so this is particularly for managers anyone involved in hiring uh a lot of job interviews are a bit rubbish and so this talks about how you do uh do things better if your job seeking might also be useful to learn a little bit more about the uh the interview process we've got a break from webinars next week uh so I'm around and then we're returning again but there's another section on generative another session on generative AI next one is Wednesday October 18th please do go to datacap.com webinars to sign up for those so uh yeah thank you once again Richard that was a really great session uh yeah I learned a lot uh and thank you to Bruce for moderating thank you to everyone who asked a question thank you to everyone who showed up today hope to see you again on Thursday or in two weeks time uh see you again soon bye
Original Description
Generative AI, and generating text with large language models in particular, is the biggest AI innovation in recent times. Leading this innovation wave are a select few organizations building the most cutting-edge large language models, Cohere being one of them.
Cohere provides an LLM for solving business problems. In this session, you'll learn to use the Cohere API with Python to generate content based on a given prompt, extract information from documents, and build a semantic search engine.
Key Takeaways:
Understand common uses large language models and how to get started with the Cohere API
Learn how to perform language generation tasks using the Cohere API
Learn how to solve common business text problems with the Cohere API
[SKILL TRACK] AI Fundamentals: https://bit.ly/3LNsFGh
[WEBINAR] Buy or Train? Using Large Language Models in the Enterprise: https://bit.ly/3thh8sn
[CHEAT SHEET] The Generative AI Tools Landscape: https://bit.ly/46tMDhP
[WEBINAR] An Introduction to GPT & Whisper with the OpenAI API in Python: https://bit.ly/3rsmDUN
[CHEAT SHEET] The OpenAI API in Python: https://bit.ly/3ZN8KNt
[TUTORIAL] How to Train a LLM with PyTorch: https://bit.ly/3ZHzbUO
[BLOG] What is LaMDA?: https://bit.ly/48v0DJk
[PODCAST] Why AI will Change Everything—with Former Snowflake CEO, Bob Muglia: https://bit.ly/3ZHzvmu
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: LLM Foundations
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Medium · AI
Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Medium · Programming
IntelliBooks: Classic RAG vs Graph RAG vs Agentic RAG – Choosing the Right AI Retrieval Architecture for Enterprise AI
Dev.to AI
Fluid, natural voice translation with Gemini 3.5 Live Translate
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI