Summarize the following text in less than 50 words. Let's think step by step: how to train chatgpt on your own text (chat with your own data, train a text ai to generate content about your docs, book, website, etc) create your own text ai hello! josh from mythical ai here. i had pineapple on my pizza twice this week and loved it. this week, we learn how to use your own text and data to make text ais way more useful! large language models (llms) are so hot right now. thanks for reading mythical ai! subscribe for free to receive new posts and support my work. using large language models, ai systems can summarize articles, write stories and engage in conversations. a large language model or llm, is a deep learning algorithm that can recognize, summarize, translate, predict, and generate text and other content based on its knowledge of the relationship of words, gained from training on huge datasets. (if you don't know what deep learning or training means, check out this crash course of ai terms article) to train an llm, large amounts of text are given to the ai algorithm using unsupervised learning. the large language model learns words, as well as the relationships between and concepts behind them. for example, it could learn the difference between a dogs bark, and tree bark, based on its context or the words and concepts that surround it. if the word 'tree' is in the same paragraph as the word 'bark' the llm learns that it means plant covering not dog sound. by learning words and their relationship, the llm can guess what might come next in a sentence or paragraph. the llm uses this to predict and generate content. chatgpt is the most famous and viral of the llms, and it is impressive what chatgpt can do. for example, you can ask chatgpt to tell you the 3 main ideas of the declaration of independence and it does a pretty solid job. chatgpt has this ability because its training dataset included the declaration of independence. chatgpt is based on openai's gpt3 llm. there are lots of large language models. i will write about them in a future episode, but for today we are going to focus on gpt3 because it is the most widely used, with the best api currently. "hey chatgpt, let's talk about the book i wrote." but what if you want chatgpt to tell you the 3 main ideas of something that is not in its training dataset? for example, you want 3 main ideas from your most recent newsletter edition? currently, chatgpt can't do this, because it doesn't know about your newsletter. since your newsletter wasn't in the training dataset, it doesn't exist. new ai applications that can pull data from the internet might be able to do this easier in the future. bing (still in closed beta) for example can 'google' concepts and use them. in a fun example on twitter, ethan mollick asked bing to re-write a story using kurt vonnegut's rules of writing which it did after looking them up. bing is not widely available. but luckily for us, there are four techniques we can use today, to get text generator models to use our own text and information. the three methods are: give the ai the data in the prompt fine-tune a gpt3 model use a paid service use an embedding database to feed the needed data into the prompt let's dive into all four ways to use your data with gpt3. 1. give the ai the data in the prompt the easiest way to have the ai answer interact with your data is to give it the data needed in the prompt. you can just hand gpt3 a chunk of text and then ask it to interact with it. this works relatively well. the issue with this method is there is a limit to the amount of text you can give to gpt3. the limit is there because running ai models is computationally expensive. if you handed gpt3 1,000 pages of text in the prompt, gpt3 would need to go through each word to understand what it is, what it means, and its relationship to other words. openai has set the prompt input limit at 4,000 tokens or approximately ~3,000 words. what is a token? from this site by openai: the gpt family of models process text using tokens, which are common sequences of characters found in text. the models understand the statistical relationships between these tokens, and excel at producing the next token in a sequence of tokens. you can use the tool below to understand how a piece of text would be tokenized by the api, and the total count of tokens in that piece of text. if you try to submit something that is too long you will get this error: a helpful rule of thumb is that one token generally corresponds to ~4 characters of text for common english text. this translates to one token for roughly of a word, so 100 tokens 75 words. if you are not sure how much you can submit, paste it into the little tool on the openai website and it will tell you how many tokens your text is. but what if you want to have the ai use more than 3,000 words? we need to step up our game. we need to fine-tune gpt3. 2. fine-tune gpt3 using your own text fine-tuning is where you take an existing model, and then add in your own data on top. we take openai's base model gpt3, and train a new model on a curated dataset that we supply. this is great because we don't have to feed billions of words and buy hundreds of gpus to train our own model from scratch. we just teach gpt3 about our text. even better, openai has an official api that lets you do this. all you need is a to run one command pointing at your text, and it will fine-tune you a gpt3 model which you can then use in the playground or via the api. unfortunately, it is not as easy (yet) as handing gpt3 all your text. you have to give it text in a structured format, essentially telling it how it should try to generate text, based on your data and inputs. you need to create bunch of examples of what the prompt would be, and then what the answer would be. it would look something like this. {"prompt": "<prompt text>", "completion": "<ideal generated text>"} {"prompt": "<prompt text>", "completion": "<ideal generated text>"} {"prompt": "<prompt text>", "completion": "<ideal generated text>"} after you have all these [prompt - generated text] examples, you package them up in a folder and submit them to the openai api. this requires some knowledge of programming (chatgpt can help you figure this out as well) but this article walks you through it. a neat trick, is you can also give some of your text to chatgpt and ask it to create the prompt completion for you. for example i handed chatgpt the entire article about creating consistent characters in stable diffusion from last week, and asked it to create question and answered from it. it did a pretty good job. i would need to fix, define, and correct a lot of the output, but it is a good starting point. once your model is done being fine tuned, you can test it out in the openai playground by selecting the model drop down, and picking the model you created and named. how much does it cost to fine-tune gpt3 using your own text? because processing all of your text costs money, they charge you for this, but they give you a discount. fine-tuning a model is charged at 50% of the cost of running the model. the most powerful and expensive gpt3 model, davinci, costs $0.0200 or 2 cents per / 1000 tokens. the entire harry potter series has 1,084,170 words. so fine-tuning davinci on just the words in the entire series, one time would cost about 1,084,170 words *.75 = 813,127.5 tokens / 1000 = 813.1 thousand token bundles * 0.02 cents = $16.26 update march 2023 - openai cut the price by 10x. however, the default number your tokens are used to train (called an epoch) is 4. so multiple your number of training tokens by 4 to get a more accurate price. to get good results, you would not be able to just send the text. you would need to create prompts, and then the ideal generated text pairs. so this would inflate the number of if all of this seems difficult, you are correct. that is why a bunch of companies have sprouted up that automate this. this leads us to our next method of training gpt on your own text. 3. use a paid service there are a number of services that let you give them text content, which they will then use to generate a gpt-powered chatbot for you. i haven't used any of these services but they all seem like they would work. https://www.filechat.io/ - upload your pdf and start asking questions to your personalized chatbot. https://www.chatbase.co/ - upload a pdf and ask a gpt-based chatbot to answer questions on it. https://www.docuchat.io/ - you upload documents. they feed your content to your chatbot. https://www.humata.ai/ - created an ai research assistant where you can ask questions about any file (i.e. technical paper, report, etc) in english and automatically get the answer. humata is like chatgpt for your files. https://www.customgpt.ai/ - ingests your website and creates a chatbot from the content. since they are not open source we don't know exactly what each service is doing, but odds are, they are using the last method, which is 'use an embedding database to feed the needed data into the prompt'. this is the most difficult method of training a chatbot on your own data but scales the best. let's dig into it. 4. use an embedding database to feed the needed data into the prompt if you don't know what embeddings are, please read this section of the article and then come back. fine-tuning gpt can be super effective if you have a defined use case. but if you are not sure what users will be asking for, it can be effective to put all your content into an embedding database and then pull out related data and put that into the prompt. for example, let's say you wrote a book about places to eat in new york. you could take that content and put it into an embedding database. just like latitude and longitude can help you tell how close two cities are on a map, embeddings do the same kind of thing for text chunks. if you want to know if two pieces of text are similar, you just calculate the embeddings for them and compare them. text chunks with embeddings that are "closer" together are similar. this would store chunks of your book in a map of space, putting chunks that are more related for example phrases about pizza and phrases about italian food, closer together and phrases that are less related, for example, phrases about pizza and phrases about soup, further apart. next, you accept the user input and embed it as well. this is super useful because then you know how similar the phrase is to your content. if someone typed in a prompt that mentions spaghetti, they might not have mentioned 'italian food' specifically. but since you have your content and the user phrase embedded, you can see how similar they are. 'italian food' and 'spaghetti' will probably be close so you can take the sections of your book that talk about italian food, put them into the prompt, then return the output to the user. here is an example of how that could work. the user asks 'what is the best spaghetti in new york?' you take the phrase what is the best spaghetti in new york? and embed it with your content. a passage you wrote about fiaschetteria pistoia: petite tuscan is one of the best italian restaurant fiaschetteria pistoia makes up for its size with charm the servers are brusque yet friendly, and everything they make is a celebration of the genre. related very closely to the user's question. you know this because they are placed close together in the embedding database. this is important because fiaschetteria pistoia has great spaghetti but your text didn't mention it directly. but because we know how close they those two chunks of text are, we can use that info. so you take the user prompt and your content about fiaschetteria pistoia which has great spaghetti but the text and put them into a prompt that you would then send to gpt. this will help gpt know your content and it can be very flexible. dan shipper has a great article where he explains exactly how he did this with a substack newsletter here. while more complicated you can use embeddings to stuff prompts and this can drastically improve the results you are getting. you can of course use embeddings along with a fine-tuned gpt3 model for hopefully even more accuracy and value. update feb 2023 - this is why open source is cool. someone made a library that will do this basically for you. the tweet is inaccurate, it is embedding then feeding relevant info into the prompt, but it is still easier to do now. update march 2023 - it gets even easier. pdf to ask my book site in 60 seconds. https://www.steamship.com/build/ask-my-book-site scenarios or use cases for training gpt3 on your own data we covered 4 different methods to train gpt3 on your own text. here are some interesting use cases. personalized email generator prepare a dataset from the emails you have sent, and then fine-tune a davinci model on this dataset. you now will have a personalized email generator to follow your style and write emails for you. a chatbot that talks in the style of someone famous chat with a famous author, like isaac asimov or carl sagan. prepare a dataset of their books or words and then fine-tune gpt3. blog posts write blog posts in your style, with your information. chat with an author or a book sahil wrote a book and made a site where you could ask that book questions. customer service train gpt3 on your help docs and style so customers can get quick answers. what did i miss? are any other methods or use cases you find compelling? let me know in the comments. see you next week! -josh thanks for reading mythical ai! subscribe for free to receive new posts and support my work. philosopher here! can i train with every known work of two philosophers and then simulate a conversation between the two, including on topics that they had significant but very subtle philosophical disagreement on? andvwhete bothbusefctechbical terms in slightly different ways?how does one train humor? hi. i think many people have personal journals and would like to create ai versions of themselves. it can be therapeutic to talk to a past version of yourself built on diary entries from 15 years ago. could fine tuning allow for this? an old diary doesn't seem to lend itself to "prompt" "answer" format.