Exploring the Power of Generative AI - An Introduction to Large Language Models, ChatGPT, and Prompt Engineering
Photo by <a >Andy Kelly</a> on <a

Exploring the Power of Generative AI - An Introduction to Large Language Models, ChatGPT, and Prompt Engineering

Introduction

In recent years, artificial intelligence (AI) has made tremendous advancements, revolutionising various industries and reshaping our interaction with technology. One notable area of AI research is generative AI, which involves creating machines that can generate content, such as text, images, and even music, with astonishing creativity. In this blog, we'll delve into the fascinating world of generative AI, focusing on large language models, such as ChatGPT, and the concept of prompt engineering

Large Language Models (LLM)

Large language models lie at the heart of generative AI, transforming the field of natural language processing. These models, trained on vast amounts of text data, can generate coherent and contextually relevant sentences, paragraphs, and even entire articles. They learn patterns, semantics, and grammatical rules from the data, allowing them to generate human-like text

ChatGPT and Interactive Conversations

One prominent example of a large language model is ChatGPT, developed by OpenAI. ChatGPT is a sophisticated AI model designed to engage in interactive conversations with users. Powered by the GPT-3.5 architecture, it can understand prompts, generate coherent responses, and adapt its behaviour based on the given context. ChatGPT has been trained on a wide range of internet text, allowing it to provide insightful and relevant information across various topics.

Harnessing the Power of Prompt Engineering

Prompt engineering is a technique that involves carefully crafting instructions or queries to obtain desired outputs from generative models like ChatGPT. It plays a crucial role in guiding the model's responses and fine-tuning its behavior. By understanding the model's strengths, limitations, and potential biases, prompt engineering enables users to achieve more accurate and controlled results.

In the following section, we will see how to use prompts using openAI API for achieving various functionalities.

Initialise openAI library & the helper function

import openai
openai.api_key="YOUR_API_KEY"

def complete(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,messages=messages,
temperature=0, # this is the degree of randomness of the model's output
    )
return response.choices[0].message["content"]        

Example-1 : Summarise a paragraph

Product reviews or a big article that can be summarised for quick understanding

text = ""
In recent years, artificial intelligence (AI) has made tremendous advancements, \
revolutionising various industries and reshaping our interaction with technology. \
One notable area of AI research is generative AI, which involves creating machines \
that can generate content, such as text, images, and even music, with astonishing \
creativity. In this blog, we'll delve into the fascinating world of generative AI, \
focusing on large language models, such as ChatGPT, and the concept of prompt engineering"""

prompt = f"""
Summarize the text delimited by triple backticks \ 
into a single sentence.
```{text}```
"""

response = complete(prompt)
print(response)        

Result

The article discusses the advancements in artificial intelligence, 
particularly in generative AI, which involves creating machines 
that can generate content with creativity, and focuses on 
large language models like ChatGPT and prompt engineering.        

Example-2 : Extract emphasising on a particular aspect

In this example product review text, we want to extract what the user is saying about price

text = ""
It's a must have product. Our clothes now looks much organised. \
Besides we are able to keep our other stuff as well comfortably\
its bit pricey. Also it arrived 2-3 days late. \
"""
prompt = f"""
extract the product review delimited by triple backticks \
focusing on aspects that are relevant to the pricing
```{text}```
"""
response = complete(prompt)
print(response)"        

Result

its bit pricey.        

Example-3 : Extract emphasizing on a particular aspect

In this example product review text, we want to extract what the user is saying about shipping

text = ""
It's a must have product. Our clothes now looks much organised. \
Besides we are able to keep our other stuff as well comfortably\
its bit pricey. Also it arrived 2-3 days late. \
"""
prompt = f"""
extract the product review delimited by triple backticks \
focusing on aspects that are relevant to shipping
```{text}```
"""
response = complete(prompt)
print(response)"        

Result

Also it arrived 2-3 days late.        

Example-4 : Inferring - Sentiment analysis

In this example product review text, we want to extract the sentiment shown by the reviewer. In traditional machine learning, typically this is done using a supervised learning where first the model is trained with a set of training data and later the model is run to predict. However in LLM, this can be done quickly. That is one of the reason the LLMs are becoming so popular

text = ""
This looks good only in promotional video.
But in reality you have to balance the trousers like a pro .. \
even if one trouser is even slightly imbalanced this \
thing will tilt and all trousers will fall. Completely insensible
"""
prompt = f"""
What is the sentiment of the following product review, which is delimited with triple backticks?\
Give your answer in a json format with single word as result and value one of the following : Positive or Negative or Neutral in Json
```{text}```
"""
response = get_completion(prompt)
print(response)"        

Result

{? 
  "sentiment": "Negative"
}        

Example-4 : Inferring - Extract a set of emotions

In this example product review, we want to extract a set of emotions shown by the reviewer

text = ""
This looks good only in promotional video.
But in reality you have to balance the trousers like a pro .. \
even if one trouser is even slightly imbalanced this \
thing will tilt and all trousers will fall. Completely insensible
"""
prompt = f"""
Identify a list of emotions that the writer of the \
following review is expressing which is delimited with triple backticks?\.?
Include no more than five items in the list. Format your answer as a list of \
lower-case words separated by commas.
```{text}```
"""
response = complete(prompt)
print(response)"        

Result

disappointment, frustration, annoyance        

Example-5 : Inferring - Extract the item details

In this example product review, we want to extract the item purchased along with the brand of the product

text = ""
It's Good Hangers from Rylan... Using less space one can hang multiple cloth...... \
Superb Space management f......the material is very good and long lasting \
can use it for many years. Low weight of hangers can easily hang it anywhere...
"""
prompt = f"""
Identify the item purchased by the writer of the \
following review which is delimited with triple backticks?\.?


Format your response as a JSON object with \
"Item" and "Brand" as the keys.?
If the information isn't present, use "unknown" \
as the value.
Make your response as short as possible.```{text}```
"""
response = complete(prompt)
print(response)"        

Result

{? 
   "Item": "Hangers",
?  "Brand": "Rylan"
}        

Example-6 : Inferring - Extract a list of topics

In this example news article, we want to extract the list of topics being discussed

text = ""
Legendary Indian cricketer Sachin Tendulkar on Saturday (June 3) opened up on \
the career of his son Arjun Tendulkar, saying that he has asked Arjun Tendulkar to \
remain focused on his game. The former India opener also urged the parents to give the required freedom to their children.\
Arjun Tendulkar made his IPL debut this year and played as an all-rounder fast bowler for Rohit Sharma-led Mumbai Indians (MI).
"""
prompt = f"""
Determine 3 topics that are being discussed in the \
following text, which is delimited by triple backticks.\


Make each item one word long. \


Format your response as a list of items separated by commas.


```{text}```
"""
response = complete(prompt)
print(response)"        

Result

Sachin Tendulkar, Arjun Tendulkar, IPL debut.        

Example-7 : Translation - Translate to different languages

These LLMs have very good understanding about different languages and they do a good job of translating

prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a pizza```
"""
response = get_completion(prompt)
print(response)        

Result

Hola, me gustaría ordenar una pizza.        

Example-8 : Translation - Translate the tone

prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = complete(prompt)
print(response)        

Result

Dear Sir/Madam,

I am writing to bring to your attention a standing lamp that I believe may be of interest to you. Please find attached the specifications for your review.

Thank you for your time and consideration.

Sincerely,

Joe        

Example-9 : Spell check / Grammar check / Proofreading

text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
though. I think there might be other options that are bigger for \
the same price.  It arrived a day earlier than expected, so I got \
to play with it myself before I gave it to my daughter.
"""
prompt = f"proofread and correct this review: ```{text}```"
response = complete(prompt)
print(response)        

Result

I got this for my daughter's birthday because she keeps taking mine from my room. Yes, adults also like pandas too. She takes it everywhere with her, and it's super soft and cute. However, one of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. Additionally, it's a bit small for what I paid for it. I think there might be other options that are bigger for the same price. On the positive side, it arrived a day earlier than expected, so I got to play with it myself before I gave it to my daughter.        

Conclusion

Generative AI, large language models, such as ChatGPT, and prompt engineering are revolutionizing the way we interact with AI systems. With their ability to generate human-like text and engage in interactive conversations, these advancements have the potential to reshape industries, enhance creativity, and provide valuable assistance in various domains. However, it is vital to exercise responsible AI use and continue refining these models to address potential biases and ethical concerns. As the field progresses, we can anticipate exciting developments that will further elevate the capabilities of generative AI.

Reference

Thank you Andrew Ng , Isa Fulford for the great tutorials in https://www.deeplearning.ai/short-courses/


















Woodley B. Preucil, CFA

Senior Managing Director

1 年

Siddharth Patnaik Very interesting. Thank you for sharing

要查看或添加评论,请登录

社区洞察

其他会员也浏览了