ChatGPT Prompt Engineering for Developers ChatGPT 06: Transforming 开发人员提示工程 06: 转化

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
large language models are very good at transforming its input to a different format such as inputting a piece of text in one language and transforming it or translating it to a different language or helping with spelling and grammar Corrections so taking us in for the piece of tech that may not be fully grammatical and helping you to fix that up a bit or even transforming formats such as inputting HTML and operating Json so there's a bunch of applications that I used to write somewhat painfully with a bunch of regular Expressions that would definitely be much more simply implemented now with a large language model and a few prompts yeah I use chat gbt to proofread pretty much everything I write these days so I'm excited to show you some more examples in the notebook now so first we'll import openai and also use the same get completion helper function that we've been using throughout the videos and the first thing we'll do is a translation task so large language models are trained on a lot of text from kind of many sources a lot of which is the internet and this is kind of of course in many different languages so this kind of imbues the model with the ability to do translation and these models know kind of hundreds of languages to varying degrees of proficiency and so we'll go through some examples of how to use this capability so let's start off with something simple so in this first Example The Prompt is translate the following English text to Spanish hi I would like to order a blender and the response is hola me gustaria or dinner and I'm very sorry to all of you Spanish speakers I never learned Spanish unfortunately as you can definitely tell okay let's try another example so in this Example The Prompt is tell me what language this is and then this is in French and so let's run this and the model has identified that this is French the model can also do multiple translations at once so in this example let's say translate the following text to French and Spanish and you know what let's add another and English pirate and the text says I want to order a basketball so here we have French Spanish and English pirate so in some languages the translation can change depending on the speaker's relationship to the listener and you can also explain this to the language model and so it will be able to kind of translate accordingly so in this example we say translate the following text to Spanish in both the formal and informal forms would you like to order a pillow and also notice here we're using a different delimiter than these baptics it doesn't really matter as long as it's kind of a clear separation so here we have the formal and informal so formal is when you're speaking to someone who's kind of maybe senior to you or you're in a professional situation that's when you use a formal tone and then informal is when you're speaking to maybe a group of friends I don't actually speak Spanish but my dad does and he says that this is correct so for the next example we're going to pretend that we're in charge of a multinational e-commerce company and so the user messages are going to be in all different languages and so users are going to be telling us about their I.T issues in a wide variety of languages so we need a universal translator so first we'll just paste in a list of user messages in a variety of different languages and now we will Loop through each of these user messages so for issue in user messages and then I'm going to copy over the slightly longer code block and so the first thing we'll do is ask the model to tell us what language the issue is in so here's the prompt then we'll print out the original messages language and the issue and then we'll ask the model to translate it into English and Korean from this so the original message in French so we have a variety of languages and then the model translates them into English and then Korean and you can kind of see here so the model says this is French so that's because the response from this prompt is going to be this is French you could try editing this prompt to say something like tell me what language this is respond with only one with only one word or don't use a sentence that kind of thing if you wanted this to just be kind of one word or you could kind of ask for it in a Json format or something like that which would probably encourage it to not use a whole sentence and so amazing you've just built a universal translator and also feel free to pause the video and add kind of any other languages you want to try here maybe languages you speak yourself and see how the model does so the next thing we're going to dive into is tone transformation writing can vary based on kind of an intended audience you know the way that I would write an email to a colleague or a professor is obviously going to be quite different to the way I text my younger brother and so chat gbt can actually also help produce different tones so let's look at some examples so in this first example The Prompt is translate the following from slang to a business letter dude this is Joe check out the spec on the standing lamp so let's execute this and as you can see we have a much more formal business letter with a proposal for a standing lamp specification the next thing that we're going to do is to convert between different formats chat gbt is very good at translating between different formats such as Json to HTML um you know XML all kinds of things markdown and so in the prompt we'll describe both the input and the output formats so here is an example so we have this Json that contains a list of restaurant employees with their names and email and then in the prompt we're going to ask the model to translate this from Json to HTML so the prompt is translate the following python dictionary from Json to an HTML table with column headers and titles and then we'll get the response from the model and print it so here we have some HTML displaying all of the employee names and emails and so now let's see if we can actually view this HTML so we're going to use this display function from this python Library display HTML response and here you can see that this is a properly formatted HTML table the next transformation task we're going to do is spell check and grammar checking and this is a really kind of popular use for chat gbt I highly recommend doing this I do this all the time and it's especially useful when you're working in a non-native language and so here are some examples of some kind of common grammar and spelling problems and how the language model can help address these so I'm going to paste in a list of sentences that have some kind of grammatical or spelling errors and then we're going to Loop through each of these sentences and ask the model to proofread these proofread and correct and then we'll use some delimiters you foreign and then we will get the response and print it as usual and so the model is able to correct all of these grammatical errors we could use some of the techniques that we've discussed before so we could to improve the prompt we could say proofreading correct the following text and rewrite oh and rewrite the whole and rewrite it corrected foreign version if you don't find any errors just say no errors found let's try this so this way we were able to oh they're still using quotes here but you can imagine you'd be able to find a way with a little bit of iterative prompt development to kind of find a problem that works more reliably every single time and so now we'll do another example it's always useful to check your text before you post it in a public forum and so we'll go through an example of checking a review and so here is a review about a stuffed panda and so we're going to ask the model to proofread and correct the review great so we have this corrected version and one cool thing we can do is find the kind of differences between our original review and the model's output so we're going to use this um red lines python package to do this and to get we're going to get the diff between the original text of our review and the model output and then display this and so here you can see the diff between the original review and the model output and the kind of things that have been corrected so the prompt that we used was proofread and correct this review but you can also make kind of more dramatic changes kind of changes to tone and that kind of thing so let's try one more thing so in this prompt we're going to ask the model to proofread and correct this same review but also make it more compelling and ensure that it follows APA style and targets an advanced reader and we're also going to ask for the output in markdown format and so we're using the same text from the original review up here so let's execute this and here we have a expanded APA style review of the soft panda so this is it for the transforming video next up we have expanding where we'll take a shorter prompt and kind of generate a longer more free-form response from a language model
Info
Channel: 盛少
Views: 95
Rating: undefined out of 5
Keywords: ChatGPT, AI, artificial intelligence, natural language processing, NLP, GPT, OpenAI, machine learning, ML, deep learning, prompt engineering, chatbot development, AI chatbot, AI-powered conversations, AI language model, AI tutorial, GPT tutorial, AI applications, AI development, AI techniques
Id: YVln8f9u268
Channel Id: undefined
Length: 12min 41sec (761 seconds)
Published: Thu May 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.