Using task-specific Cortex LLM functions
1. Using task-specific Cortex LLM functions
Welcome back. Just a quick update of where we are in this module. So we introduced three types of LLM functions available, complete, task-specific, and helper functions. We reviewed each of these types at a high level. And in the previous video, we dove deeper into complete with hands-on work. Now, in this video, we will get some hands-on experience with the four task-specific functions. Translate, sentiment, summarize, and classify text. Note that as the tasks AI is used for continue to mature, we will continue to pull out common tasks and define new task-specific functions in the same way we have already done. So keep an eye out on the docs for the latest set of functions available. Let's get started with translate. We already learned how the translate function allows us to easily translate text from one supported language to another. It helps process an entire column of text strings that are in different languages into a desired target language for use. Before we dive into using the function, this is the time to pause the video and log into your Snowflake account if you haven't already. Navigate to projects on the left panel and select notebooks. Click on the notebook titled using LLM functions and select the start button at the top to start the notebook session. It takes a couple of seconds. We've already run the first half of the notebook. Scroll down all the way to task-specific functions. Let's look at how we call translate in Python. We already know that the call transcripts are available in various languages such as German, French, and so on. In this first example, we filter the German transcripts from the table and do a simple translation to English. Just so we can make sense of it. I don't know German, at least not yet anyway. We pass the transcript column from our data set to translate function. You can see that the entire conversation is translated to English. Fantastic. In the next cell, let's look at an example in SQL. Here, let's try to convert all the transcripts in different languages to English. Since we cannot pass multiple languages as parameters to the function, let's use an empty string to let the function infer the source language by itself. In a few seconds, we have all the transcripts from our data set translated into English. How powerful. Now that we have translated the data, we can start extracting value from it with sentiment analysis. As we saw before, the sentiment function looks at a column of strings and read each string's sentiment on a scale of negative one to one. Once the sentiment is determined, it can also be used downstream, perhaps as a feature for a machine learning model or to power a rules engine. This is a very cost effective function. We are only built for our use of input tokens and not output tokens. Let's look at how we do this in Python. When we run the sentiment in a Python cell, it returns float values with one representing most positive and a negative one representing the most negative sentiment. Let's look at a call transcript and see if it has done a good job. We have the results of the sentiment function here. Let me try to find a more extreme example. Let's look at the transcript. What does it look like? Oh, OK. So the customer does have a proper resolution to the issue they've had, and that explains why they have a higher or a positive sentiment for this entire interaction. Great. You can also run the same using SQL as well. The summarize function, as we learned before, is ideal for distilling large volumes of text to generate quick summaries of meeting notes. This can also be applied to capture the main points of call transcripts, allowing customer service to be more actionable. The function takes one input parameter text that we would like Cortex to summarize. It will return the summary as a string. Let's look at how we do this in Python. When we run the code snippet, it has summarized the text well. Great. But the real question is, can we summarize an entire column of strings from a table using SQL? We pass the EN transcript column from the call transcripts table as input to the function. In a couple of seconds, we were able to summarize long form call transcripts into a couple of sentences. What a time saver for our support teams. Being able to pull out summarized insights and action items from long strings of text is invaluable. Next, we will learn how to use classify text to take larger data sets and bucket them into different categories. Classify text gives us an easy way to classify large volumes of text into target classes that you provide. All we need to do is pass the text or column of text we want classified and the list of categories that we want the function to use. When we run the next cell, we see that the model correctly identifies this query as looking for a recommendation and returns the label recommendations as a classification. You can run the same function using SQL as well. For the SQL function, let us pass the EN transcript column from the call transcripts table as input. Let us look at an example transcript and see if it was classified right. It is interesting we have an unclassified label. And looking at the transcript, it is neither a missing price tag, not a washed out color or a broken zipper. That makes sense. So let's look at another example. It seems like there was a problem about a jacket. And the defective zippers. So the model did a good job by classifying it into broken zipper. Fantastic. Classify text can now classify every call transcript into one of these categories or classes we defined. How cool. That wasn't so hard. In this video, we got some hands on experience using the task specific cortex functions, translation, sentiment analysis, summarization and classify text. They save us a lot of time because we don't have to do prompt engineering or try to decide which model would be best for each case. The functions do their job right out of the box. In the next video, we will learn how to use helper functions. They can be useful both in early prototyping and when our app reaches production.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.