4. OpenAI GPT-3 - Prompt Engineering For Financial NLP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
prompt engineering is the process of Designing the input text or the prompt that a model such as gpt3 will use to generate its output the quality and effectiveness of this output is dependent upon the design of your prompt so it's important to understand how to craft a good prompt for gpt3 in this tutorial we will explore the basics of prompt engineering for gpt3 we'll discuss how to perform common natural language processing tasks on financial text including data extraction named entity recognition sentiment analysis and text classification let's get started the first test we'll discuss is data extraction so data extraction is the process of extracting structured text out of big long blob of unstructured data so in the last video we did a we process an earnings transcript so we took the earnings call from Nvidia right and we summarized it and basically compressed it down to a shorter version of the call that had all the key points now now what we want to do with data extraction here is try to extract some more insight of this try to extract maybe some numbers some people places keywords all kinds of different data and pull that out of the text without writing some custom python parser we're just going to use tpt3's natural language processing capabilities to pull this state out for us and we just need to prompt it the right way so to learn how to use these prompts we're going to use the openai playground so you just go to openai.com you can log in and you click on playground and you'll be able to input some text here as a prompt and submit it and see what open AI what gpt3 returns so to demonstrate data extraction tasks we need some text to operate on so if you didn't follow the last tutorial video three I recommend you do that but if you're too lazy to do that I've included the text of the transcript right here off the website and you can copy it or you can find your own copy of the transcript this is the summary that I'll be operating on so this is a summary of the transcript I could include the entire transcript but there's an input limit on the amount of text Data you can process in gpt3 all at once in the last video I told you how to take the entire transcript and divide it into chunks and make multiple API calls and then summarize it and collate the responses into a single a longer summary so if you like the output on the summary that we're operating on here you can technically Chunk Up the document and send the same prompt to uh for chunks of the text and process the entire document so I've pasted in the earnings call transcript summary that we generated Right Here and Now above this I'm just going to start using some prompts and see what gpt3 returns and you'll find it's very easy to return some very useful data so the First Data extraction task we'll perform is named entity recognition and so this is a common natural language task that you may have heard about before and there's various python libraries for this like python to nltk so the natural language toolkit and there's also Spacey which is used for text processing as well and they have named entity recognition functionality but you can use gpt3 for this by just typing some prompts and so let's try these prompts so I'm going to take this prompt right here and put it right above this text right here and I'm going to click submit and see what it does in the playground and so just like that I say extract named entities and look at that named entities Simona Jankowski collect Cress Nvidia RTX 4090 gen Sun Huang AI China gen Sun Q4 2021 internet service companies cloud computing providers and blockchain so you can recognize these are named entities so those are company names that's a product name that's the CEO's name those are various people on the call I believe the CFO is on there and there's a quarter here and then there's like a sector or type of company so cloud computing providers internet service companies and blockchain so that right there is pretty cool that we can just take this big long blob of text and extract all these named entities out of it so you might say to yourself sure that's useful you could extract these name entities and that might be useful for like a keyword search or a way to do tagging and linking documents together but these are kind of jumbled all together right so that's a person that's a product that's a sector so that's not very organized well if you know about prompting you can organize this a little bit better so what happens if we say extract people job titles and product names from the following text so we're kind of giving a little bit more data of what we want and so we're learning how to prompt it and be a little bit more specific and so I'm going to do that I'm going to delete this from one here and I'm going to submit that and see what it says now and you can see it's able to figure out how to categorize and classify all these things so I say how I want to classify it here people job titles and product names and so now I have the people Simona Jankowski collect Crest Jensen we got job titles so we got the CFO and the CEO CEO and we have the product name so we have the RTX 4090 which is an upcoming graphics card we have the Ada Lovelace GPU architecture that's coming out Nvidia gpus and blockchain now if we don't just care about people we want some just keywords so that we can build some kind of document tagging and classification system or organizing system where we can get a big Corpus of documents and put them all on a searchable website we might may be able to search by keyword or have documents linked together we can do a prompt like this and just extract all the keywords from the text and so if I type this in the playground and try this out you can see It'll get us some additional keywords that we might not have picked up before and so we get words like general purpose Computing uh Cloud purchases large installations internet service companies software licenses and you can see a lot of these are businesses that Nvidia is involved in and ways that they generate revenue and it might be worth it to dive into some of these kind of double click on these a little more and see you know Cloud purchases from where what are other companies that are connected to Nvidia who are they using to uh produce all these semiconductor right and you'll find like Taiwan semiconductor makes everything and GPU instance instance hours and think about you know how there's going to be a huge growth in all these machine learning companies and them using gpus by the hour in cloud computing environments uh to train these machine learning environments and so you can kind of parse through this and think and maybe even figure out some investment ideas and themes here that you might not have picked up if you don't have time to go through all these earnings transcripts or you don't want to just take someone else's word for it now you might say named entities keywords who cares I'm a numbers person I care all about the numbers and so the other type of data that we can extract is financial information so how do we extract all the key financial information and numbers from the text well it can do that too so we can do something like extract all Financial numbers from the following text and let's see what it produces here so I'm going to put that in and tell it to find me all the numbers in the text 5.93 billion 12 17 1 31 lots of percentages and a million dollar numbers here and so you know it's cool that I can find all the numbers even if there's a percent sign or a million and billion next to it and it knows that context but that output there is not very useful to me and so I need to figure out how to make my prompt a little more specific and a little bit better to be able to extract the meaning of all these numbers and so I can modify that prompt right and say extract all Financial numbers and what they represent in the following text and so gpd3 relies on these prompt and you got to be more specific and talk to it and tell it what you mean and it'll usually do a pretty good job of finding what you want but if you're just vague about it and you don't know how to communicate then you know you're not you're not going to get exactly what you want and so one of the things you'll find with prompt engineering I've I've watched a few other YouTube videos where people have talked about this is that um being good with language and able being able to explain and communicate is going to be a very valuable skill for having these these models do what you want and while it's very valuable to know all the advanced math and how to train your own models and have that academic background what you'll find is this provide is providing nice little shortcuts for us to just communicate with this model as a service as they're calling it their software as a service where you pay by the month but now there's these models as a service that you can just use and if you can communicate and ask these models the right questions then it becomes very simple to get the answers and meaning you want and so it's very empowering so there's going to be very creative individuals who have ideas for startups Financial products Etc who know how to use language and can come up with ways to combine their own domain expertise so maybe they're an expert in finance or music and art and they can use these as kind of a superpower to allow them to perform tasks really really quickly and so I can say extract all Financial numbers and what they represent and all of a sudden look at this financial numbers I have 5.93 billion dollars revenue for Q3 a 2021 I have my sequential growth in data set on Revenue year on your growth and so we know there's a large decline in Gaming revenue both sequential Decline and year-on-year decline we see the inventory change and also we have this description here and so I was curious about this inventory chart for instance and where'd that come from inventory charts you to expected changes in demand for China data center so that's pretty cool right there and if I want to prompt it a bit more and get this output to look a little bit differently like that seems a bit redundant but we can prompt this and be more and more specific Civic to get this data exactly how we want and so when you think about it providing this type of service where you can summarize a document in an article form you can have it write or rewrite an article for different levels of audience and you can extract these key points and numbers does that put someone out of a job maybe it does if it's not automated already if you've ever been to CNBC or Motley Fool or any types of these investment websites that have all these ads popping up all over them so you get XML become a member pay for this do I need these people right they say data center growth remains strong sure enough I know that data center growth was strong I just asked a GPT key points oh look at that I know all the key points I've extracted the keywords right and oh tell me more about this EPs and revenue of 5.93 billion oh I knew this because GPT 3 did I need someone to write this article did a person write this article I'm sorry if I don't want to offend the person that read this article but yeah if you did this a gpd3 can definitely uh do this job it talks about China right here and I already know that and all I did is type A few words that I copied from this YouTube video and I got all this information right there so that's pretty cool right another useful bit of information you might want to extract involves dates so you can extract all dates and what they represent and so I found this useful because it talks about which quarter they're referring to but also it gives you the release date of certain products so you can see in mid-october is when the RTX 49 becomes available and you can also see what they think about the fourth quarter so they're expecting that to be stronger in Q4 during the upcoming holiday so expect a lot of sales there and then the third quarter they talk about the inventory charge right so if we want to bucket this and summarize it in a lot of different ways whether by person place thing or time we can do this all with gpt3 now while it's very cool to be able to get this natural language response you know and have it type back to me you might say well this is a computer programming Channel this is a Python Programming channel so you know what is a computer program going to be able to do with this well what if we're able to return this output not just as a list here as natural language what if we can format this output in such a way that a computer can understand it or we can import it into a spreadsheet well good news is gp3 is very well aware of how to return structured output if you just tell it to do that and so right here I have a prompting for structured output so if you'll remember we did named entity recognition and we asked it to extract people job titles and product names but if I say return the response as a bulleted list it'll return it just like that as a bulleted list so you see the people you see the job titles and you see these different product names which is very useful right there but what if I want to return this in a CSV format what can I do so I can tell to do that as well and maybe I want to import some data into a spreadsheet and if I want to go further I can tell it the exact columns and structure of the CSV file as well and so you can see we have a comma separated list right here but more interesting than that on this channel we often work with Json format and so what I can do is say extract all the people job titles and product names and return it in Json format and I'll do that for me just like this so now look we have a Json object right here and then you can see it's it's created a key for each category automatically so I have a key for people and that's the people notice Ada Lovelace is in there who is actually associated with a product name there so that one's kind of a weird special case we got the job titles executive fives President Chief Financial Officer CEO and we have the product names and these are all in lists that are under keys for each category which is pretty nice because now I could actually run a Python program called the open AI API on this document and I can obtain a response in Json format parse this out and maybe populate a database or do something else with it so as a programmer if I'm using chat gbt or G apt-3 as my peer programmer performing these tasks for me I might have a little bit of feedback maybe I don't want this capitalization in people or the space and job title right these keys are kind of difficult furthermore these job titles are actually associated with people so why do I have this list of two job titles down here and list of four people up there that's not really exactly what I want so the one thing that I found pretty mind-blowing is that I can provide a specific example of the output and so what we've done so far is give it a prompt so we've given it a prompt and told it to do something and we didn't give it any examples and so you'll hear these uh these terms like zero shot learning so you're not giving it any examples you're just given a prompt and getting something back but we can also do is give it some examples of what you want and so after this text what I can do here is return the response right here and so I'm just going to type an example of the response I actually want as a programmer and see what gpt3 does with it so I have prompt I have my text and down here I'm going to say instead of that Capital One I'm going to say people right and what I'm going to do is I'm going to have a list of people and I want a list of objects here and I want a key for the person's name so I'm going to call it a name and I'm going to just leave an empty string right there and then I'm also going to do a job title so I'm going to see if it can associate the job title with the person's name automatically from that test and return it as a list of objects and then I'm going to say what I say products and so I'm going to say a products down here and then this one I just want a list and I'll just leave that list empty right and so let me submit this and see what it does and this is pretty amazing right I have the people and their role in the call right there and they're grouped into this list of objects so I have the name Simona Jankowski and the job title and there wasn't a job title in the summary that I put here but her role I guess in the uh in the call was welcoming everyone to the Nvidia third quarter earnings call so that is included as the job title Colette Cress Executive Vice President and CFO Jensen which is NVIDIA CEO and then we have the product and not and it's pretty cool since I guess Ada Lovelace didn't have a job title it included as a product so I was able to figure out that Ada Lovelace GPU architecture wasn't you know Ada Lovelace wasn't a person in this particular case when I framed my prompt that way I have gpus Enterprise software stack and the dynamic Computing environment in RTX 4090 so that's pretty awesome that I can get that structured data like that and so when you think about it what we could do is like build our own custom API or we could build this pipeline that automatically pulls all the different earnings transcripts SEC filings all these other financial documents we can push them to some queue uh process them ask GPT questions get the structured output and populate a database build some search engine build our own cnbc.com and run our own new service we just need to know how to craft left these specialized prompts parse the output with python send API requests the right way to and the openai API and how to use a pipeline and I'm going to talk about databases and hooking all that up as well and we can build very complex things and have it solve a lot of these problems for us so that we don't have to worry about oh I don't know how to do natural language processing or build my own model to extract sentiment and all these things I'll just have gpt3 do that part for me and then build my idea that I have in my head now speaking of applications and databases we've built many web apps we've built mobile apps and trading Bots and financial price databases on this channel how do we go about building a database with all of this information well chat GPT or gpt3 has an answer it can actually generate SQL statements so we've talked about gpt3 and codex being a subset that is trained on code and we talked about these example output formats I've provided a prompt here extract people and product names from the following text return an SQL database structure for storing this data so let's say we wanted to design this database for us like we want a database for string people and product names for earnings calls so we process them in mass and we want a database and we don't know how to design it or maybe we want to store open high low close volume technical indicators all those type of things people are interested in and we want it to return that database structure because we don't know how to do it we know how to do it but we want to take shortcuts here right and look at that we got table one it says suggest create table one called people and we have some column names so we have person ID and name and then so the person ID there is the primary key one two three and we got the names right there the product product ID product name and so that's the start of some suggestions on how to design this database and we could probably craft this and and refine a bit more to actually generate the SQL statements so I kind of had it generate mock a database design for me right there but I also have a prompt here where I say extract people and product names from the following text return a SQL insert statements to populate a database with this information so let's say I want actual SQL and let me fix this return SQL insert statements just like that and so let's say we designed the database now we want it to actually populate there you go insert into people so it starts into the name column the values Simona so it knows not only does it not it doesn't generate three insert statements for people it actually use this it has some knowledge of SQL and so it knows it can just do commas like this so these are three different records and then starts into products so a product name so it uses like product name column RTX 390 and so so on and so forth and so we're able to actually generate code here so this is SQL code that we're able to generate that came out of extracting information from this document so we have a database design and a data loader that we're able to generate just using this natural language that we wrote right here and in the next video I'm going to use chat GPT as a pair programmer to actually write python programs so we'll be able to prompt it to write python programs and parse documents and build a crawler and then we could even combine this database stuff and crawl the web for and extract data and and populate that into a database we could generate a flask web application and build a front end for that and I'll explore peer programming and walk you through that I already have a a whole a whole tutorial written on that that I'm going to do right after this so that's pretty badass we learned a lot just by taking that transcript that we did in the last video and just running a bunch of commands on and seeing what we can do with gpt3 what else did we do well we have that fed speech right we can probably do something interesting with the FED speech so I'm going to talk about sentiment analysis and text classification using prompts and we're going to operate on that so now you can kind of see some people are like well what's the point of transcribing this fed transcript that already exists or what's the point of this summary well these lessons that I'm making here I've actually I have a thought process of showing you these smaller simpler building blocks and then we're gradually putting them together into larger and larger things and applying those Concepts to what we did in the last video and these are going to build until we have entire applications and so the reason why we transcribe the FED is to demonstrate open AI whisper and speech recognition and the reason why we did an earnings call summary is so we had a small chunk of text to work on that we could do a natural language processing task on so now we're going to demonstrate sentiment analysis and text classification on the FED speech using gpt3 so let's go ahead and do that so this year 2022 Jerome Powell has said some words that have caused the markets to react in a very negative way at least in the short term and so we used openai whisper to perform speech recognition on the audio of one of his live streams and so naturally some people in the comments were like well how do we further analyze this text I want to do sentiment analysis or we want to figure out whether he was dovish or hawkish classify this and you know we have a bunch of degenerates on the channel so they naturally want to trade on this piece of text and so let's see what gpt3 says about this bit of text do we need to train some special model or can it figure out the sentiment or how to class classify a drone Pals text without us doing much or writing much code so let's let's check it out here and so what can we do with this well sentiment analysis as you probably know is a way of classifying uh Speech or text as positive or negative so it's pretty generic here so you can say oh this is positive sentiment or negative sentiment right and so we can do something very generic here and so I have a prompt here that says analyze the sentiment of the following text and so if I just put that this will give a pretty a simple answer here so I can do this but then we can craft more complex prompts to do more complex things right and so it says the sentiment of this Texas neutral the speaker is outlined the actions so emphasize these so it kind of does a little summary and says the sentiment of this text is neutral so this type of sentiment analysis isn't very useful to me but let's try a little bit more let's say return a list of the sentiment of each sentence in the following text and so let's do this and provide an example of exactly what we want because that that seems like garbage to me so I'm going to say return this and remember we said we can provide some type of example of the output we want and so what I'm going to do there's the text and I'm going to say I want a pipe delimited uh table here and let's say I want this number remember we returned it Panda's data frame and so we got the text from openai whisper we got price data we populated a a pandas data frame with price data and we knew the start and end time stamps and then we populated the sentences in the pandas data frame just to go crazy so let's number these sentences and then say we want the sentiment next to the text for each so not only do we want to classify the whole thing we want sentiment of each sentence so I'm going to do that and look at that good afternoon good afternoon it's very positive way to start right it starts pretty positive here and then it says negative restoring price stability will likely require maintaining restrictive stance of policy for some time negative that sounds pretty negative I'll have more to say that's neutral not positive or negative right and so positive and negative like that's this is kind of cool that it's able to break it down by sentence so it knows to divide it by sentence analyzes each of those individually and says positive or negative and so it seems to be working as sort of okay now this sentiment analysis of positive or negative to me isn't that useful or interesting right here positive and negative sentiment is useful for like restaurant reviews and stuff like that so I could organize all the Yelp reviews and say oh this is a positive review put it over here and some people just want to read negative reviews about a restaurant or a movie or whatever but a lot of people when they're trying to trade on this or make financial decisions and they're making short-term decisions based on this they're interested in whether a Jerome Powell is a hawkish or not and they're updating these these plots of where they think interest rates are going to be and so they want to know is he dovish is he hawkish right or is you know some of these statements are just neutral so what we can do here is a text classification so look at this prompt I have here classify each sentence in the following text as neutral or hawkish so I just want to know whether he's hawkish or not and I say return turn the hawkish sentences in Json format and so I'm giving it a format of the response and I say I want a list of all the sentences and their classification right here and I just want the hawkish sentences I paste I didn't classify each sentence return hawkish in Json format and I tell it an example of the response I want let's see if it can figure it out boom just like that what's hawkish here today the fomc radar policy and trade by 75 basis point that's hawkish we're moving our Posse stance purposely to a level that we sufficiently restrictive to return inflation at two percent hawkish restoring price stability will likely require maintaining a restrictive policy stance for some time hawkish tastes mean the commission committee race the target range by 75 basis points continuing the process of significantly reducing the size of our balance sheet to place an important role in firming The Stance of entree policy also hawkish it will take time however and what we want to do is increase the token length since this is a pretty long input and response I'm going to run this one more time with a higher token length so these are the input parameters on the side which we haven't talked about much yet since we haven't need them but we'll be experimenting them as we do more complex things so that's how you increase the maximum length that it returns it will take time however for the full effects of monetary restraint to be realized especially on inflation we will stay the course until the job is done Jerome Powell is not around right here and so if we look in our second video on open AI whisper we looked at the sentences that led to this particular Decline and indeed we pinpointed here we anticipate ongoing increases in minus 0.33 percent in uh in five seconds at a time at some point significant uncertainty so on and so forth and so you can see a gpt3 did a pretty good job here of taking all these sentences and returning whether they are hawkish or not so if you want to take my open AI whisper code from the previous video that processes uh audio data and you want to hook it up to a microphone so run the live stream whenever uh Jerome Powell is talking you can actually hook that up to the microphone feed it through in chunks transcribe that text you could send that over to openai's gpt3 classify it as hawkish and I've done interactive brokers videos that show how to buy put options and you could YOLO every time he says something hawkish that's classified by gpt3 is that crazy probably that's probably a bit of a gamble there but it's pretty cool how you can take all these Concepts and chain them together into something more complex and interesting right and if people actually want to see me demonstrate the full example on how you do that I'm happy to do that but I'm not going to recommend anyone try that it's just one of those crazy ideas you get when you make a lot of financial videos and look a lot of data you start to see these weird patterns in and think of these crazy things you can do so um that's it for this video I hope you learned a lot about prompt Engineering in the next video I'm going to talk more about chat gpt3 and code generation so we're going to use chat gbt to generate python code to build a web scraper and yeah stay tuned I got that one coming up that'll probably come out Friday so thanks a lot happy holidays everyone got my prince Merry Christmas Prince on the revolution shirt right there on the motorcycle so thanks a lot bye
Info
Channel: Part Time Larry
Views: 31,176
Rating: undefined out of 5
Keywords: gpt3, chatgpt, prompt engineering, nlp, finance, financial data, trading, natural language processing, named entity recognition, text classification, sentiment analysis, machine learning, earnings, transcript, python
Id: Nl2Cdbao5Ws
Channel Id: undefined
Length: 27min 54sec (1674 seconds)
Published: Fri Dec 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.