๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป IT·๊ธฐ์ˆ ·ํ†ต๊ณ„

ChatGPT ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๊ฐ€์ด๋“œ - ไธ‹

by nowgeun 2023. 8. 2.
728x90

1ํŽธ์—์„œ๋Š” ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง์— ๋Œ€ํ•œ ์›์น™ ๋ฐ ์‚ฌ์šฉ ์‹œ ์ฃผ์˜ํ•ด์•ผ ํ•  ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ๋‹ค๋ค˜์Šต๋‹ˆ๋‹ค. 

2023.07.31 - [๐Ÿ’ป ์ฝ”๋”ฉ·๊ฐœ๋ฐœ·๋ถ„์„] - ChatGPT ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๊ฐ€์ด๋“œ - ไธŠ

 

ChatGPT ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๊ฐ€์ด๋“œ - ไธŠ

์ตœ๊ทผ ๋ช‡ ๊ฐœ์›” ๋น„์ „๋ฌธ๊ฐ€์ธ ์–ด์ค‘์ด๋– ์ค‘์ด๋“ค์ด ์ •ํ™•ํ•˜์ง€ ์•Š์€ ์ •๋ณด๋กœ ChatGPT๋ผ๋Š” ํ‚ค์›Œ๋“œ์— ํŽธ์Šนํ•˜์—ฌ ์ฑ…์ด๋‚˜ ์œ ํŠœ๋ธŒ ๊ฐ•์˜๋ฅผ ํŒ”์•„๋จน๋Š” ๊ฒƒ์„ ๋ณด๋ฉฐ ๋งค์šฐ ์•ˆํƒ€๊นŒ์› ๋Š”๋ฐ, AI ๋ถ„์•ผ์˜ ์„ธ๊ณ„์ ์ธ ์ „๋ฌธ๊ฐ€์ด์ž C

jakely.tistory.com

>> ์ˆ˜๊ฐ• ๋งํฌ <<

 

 

๋‚˜๋จธ์ง€ ๋ถ€๋ถ„์—์„œ๋Š” ์š”์•ฝ, ์ถ”๋ก , ๋ณ€ํ™˜, ํ™•์žฅ, ์ฑ—๋ด‡ ๊ฐœ๋ฐœ ๋“ฑ ์–ด๋–ป๊ฒŒ ChatGPT๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ๋‹ค๋ค˜์Šต๋‹ˆ๋‹ค. 


Python Notebook ๋‹ค์šด๋กœ๋“œ

ChatGPT-Prompt-Eng.zip
0.04MB


ํ•ต์‹ฌ ๋‚ด์šฉ ์š”์•ฝ์ •๋ฆฌ (Key Takeaways)

 

์š”์•ฝ (Summarizing)

  • ๋‹จ์–ด, ๋ฌธ์žฅ, ๊ธ€์ž์ˆ˜๋ฅผ ์ œํ•œํ•˜์—ฌ ์›ํ•˜๋Š” ๊ธธ์ด์˜ ๊ฒฐ๊ณผ๊ฐ’์„ ์–ป๋Š”๋‹ค.
  • ํŠน์ • ๋ถ€๋ถ„์— ์ง‘์ค‘ํ•˜๋„๋ก ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.
  • "์š”์•ฝ (Summarize)" ๋Œ€์‹ ์— "์ถ”์ถœ (Extract)"์ด๋ผ๋Š” ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•ด ๋ณธ๋‹ค

 

์ถ”๋ก  (Inferring)

  • ๊ฐ์„ฑ ๋ถ„์„ (Sentiment Analysis), ์—”ํ‹ฐํ‹ฐ์ถ”์ถœ (NER), ํ† ํ”ฝ ๋“ฑ์˜ ์ž์—ฐ์–ด์ฒ˜๋ฆฌ ์ˆ˜ํ–‰
  • ํ•œ ๋ฒˆ์— ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ ๋ผ๋ฒจ ๋˜ํ•œ ์ถ”์ถœ ๊ฐ€๋Šฅ
  • ํŠน์ • ํ† ํ”ฝ์ด ์ถœํ˜„ํ–ˆ์„ ๋•Œ ์•Œ๋ฆผ์„ ์ค„ ์ˆ˜๋„ ์žˆ์Œ

 

๋ณ€ํ™˜ (Transforming)

  • ๋‹ค์–‘ํ•œ ์–ธ์–ด๋กœ ๋ฒˆ์—ญ ๊ฐ€๋Šฅ
  • ์–ธ์–ด์˜ ํ†ค, ํ˜•์‹, ๋ฌธ๋ฒ• ์ฒดํฌ ๋“ฑ์ด ๊ฐ€๋Šฅํ•จ

 

ํ™•์žฅ (Expanding)

  • ChatGPT API์˜ Temperature ํŒŒ๋ผ๋ฏธํ„ฐ ์กฐ์ •์œผ๋กœ ์ฐฝ์˜์ ์ธ ๋‹ต๋ณ€์„ ์œ ๋„ํ•  ์ˆ˜ ์žˆ์Œ (์ผ๊ด€์„ฑ์€ ๋–จ์–ด์ง)
  • ์œ„์˜ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ๊ณ ๊ฐ์—๊ฒŒ ์ž๋™์œผ๋กœ ๋‹ต๋ณ€ํ•ด ์ฃผ๋Š” ์ด๋ฉ”์ผ์„ ์ž‘์„ฑํ•˜๋Š” AI๋ด‡ ์ƒ์„ฑ
  • "AI๊ฐ€ ์ž‘์„ฑํ–ˆ๋‹ค"๋Š” ๊ณ ์ง€๋ฅผ ํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ๊ณ 

์ผ๊ด€์„ฑ์„ ์›ํ•œ๋‹ค๋ฉด Temperature์„ 0์œผ๋กœ , ์ฐฝ์˜์ ์ธ ๋‹ต๋ณ€์„ ์›ํ•˜๋ฉด 1์— ๊ฐ€๊น๊ฒŒ ์„ค์ •

 

 

์ฑ—๋ด‡ (Chatbot)

  • ์ฑ—๋ด‡ ํ˜•ํƒœ๋กœ ์‚ฌ์šฉ์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋Œ€ํ™” ๋‚ด์šฉ์„ ์ €์žฅํ•œ ํ˜•ํƒœ์˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•จ
  • ex) messages =  [  
    {'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},    
    {'role':'user', 'content':'tell me a joke'},   
    {'role':'assistant', 'content':'Why did the chicken cross the road'},   
    {'role':'user', 'content':'I don\'t know'}  ]

 


๊ฐ•์˜ ๋…ธํŠธ (ํ”„๋กฌํ”„ํŠธ ์˜ˆ์‹œ)

๊ฐ•์˜ ์ค‘์— ๋‹ค๋ค„์ง„ ๋Œ€ํ‘œ์ ์ธ ํ”„๋กฌํ”„ํŠธ ์–‘์‹์„ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค. 

 

4. Summarizing 

prod_review = """
Got this panda plush toy for my daughter's birthday, \
who loves it and takes it everywhere. It's soft and \ 
super cute, and its face has a friendly look. It's \ 
a bit small for what I paid 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 her.
"""

# ๊ธ€์ž์ˆ˜๋ฅผ 30์ž๋กœ ์ง€์ •
prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site. 

Summarize the review below, delimited by triple 
backticks, in at most 30 words. 

Review: ```{prod_review}```
"""


# ๊ฐ€๊ฒฉ๊ณผ ๊ฐ’์–ด์น˜์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ค‘์ ์ ์œผ๋กœ ์š”์•ฝ
prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
pricing deparmtment, responsible for determining the \
price of the product.  

Summarize the review below, delimited by triple 
backticks, in at most 30 words, and focusing on any aspects \
that are relevant to the price and perceived value. 

Review: ```{prod_review}```
"""

# "์š”์•ฝ" ๋Œ€์‹  "์ถ”์ถœ"์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ๋Œ€์‹  ์‚ฌ์šฉ
prompt = f"""
Your task is to extract relevant information from \ 
a product review from an ecommerce site to give \
feedback to the Shipping department. 

From the review below, delimited by triple quotes \
extract the information relevant to shipping and \ 
delivery. Limit to 30 words. 

Review: ```{prod_review}```
"""

 

 

5. Inferring

lamp_review = """
Needed a nice lamp for my bedroom, and this one had \
additional storage and not too high of a price point. \
Got it fast.  The string to our lamp broke during the \
transit and the company happily sent over a new one. \
Came within a few days as well. It was easy to put \
together.  I had a missing part, so I contacted their \
support and they very quickly got me the missing piece! \
Lumina seems to me to be a great company that cares \
about their customers and products!!
"""

# ๊ธ์ •-๋ถ€์ • ์—ฌ๋ถ€ ์ฒดํฌ
prompt = f"""
What is the sentiment of the following product review, 
which is delimited with triple backticks?

Give your answer as a single word, either "positive" \
or "negative".

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)


# ๋ฆฌ๋ทฐ์—์„œ ์ œํ’ˆ, ํšŒ์‚ฌ๋ช… ์ถ”์ถœ (NER)
prompt = f"""
Identify the following items from the review text: 
- Item purchased by reviewer
- Company that made the item

The review 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.
  
Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)



# ํ† ํ”ฝ ์ถ”์ถœํ•˜๊ธฐ 
story = """
In a recent survey conducted by the government, 
public sector employees were asked to rate their level 
of satisfaction with the department they work at. 
The results revealed that NASA was the most popular 
department with a satisfaction rating of 95%.

One NASA employee, John Smith, commented on the findings, 
stating, "I'm not surprised that NASA came out on top. 
It's a great place to work with amazing people and 
incredible opportunities. I'm proud to be a part of 
such an innovative organization."

The results were also welcomed by NASA's management team, 
with Director Tom Johnson stating, "We are thrilled to 
hear that our employees are satisfied with their work at NASA. 
We have a talented and dedicated team who work tirelessly 
to achieve our goals, and it's fantastic to see that their 
hard work is paying off."

The survey also revealed that the 
Social Security Administration had the lowest satisfaction 
rating, with only 45% of employees indicating they were 
satisfied with their job. The government has pledged to 
address the concerns raised by employees in the survey and 
work towards improving job satisfaction across all departments.
"""

prompt = f"""
Determine five topics that are being discussed in the \
following text, which is delimited by triple backticks.

Make each item one or two words long. 

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

Text sample: '''{story}'''
"""
response = get_completion(prompt)
print(response)

 

6. Transforming

# ๊ธฐ๋ณธ ๋ฒˆ์—ญ (๋‹ค๊ตญ์–ด ์ง€์›)
prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)


# ํ†ค ๋ณ€ํ™˜ 
prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = get_completion(prompt)
print(response)


# ์ถœ๋ ฅ ํฌ๋งท ๋ณ€ํ™˜ (HTML๋กœ ๋ณ€ํ™˜)
data_json = { "resturant employees" :[ 
    {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},
    {"name":"Bob", "email":"bob32@gmail.com"},
    {"name":"Jai", "email":"jai87@gmail.com"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""


# ๋งž์ถค๋ฒ• ๋ฐ ๋ฌธ๋ฒ• ์ฒดํฌ
text = [ 
  "The girl with the black and white puppies have a ball.",  # The girl has a ball.
  "Yolanda has her notebook.", # ok
  "Its going to be a long day. Does the car need it’s oil changed?",  # Homonyms
  "Their goes my freedom. There going to bring they’re suitcases.",  # Homonyms
  "Your going to need you’re notebook.",  # Homonyms
  "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
  "This phrase is to cherck chatGPT for speling abilitty"  # spelling
]
for t in text:
    prompt = f"""Proofread and correct the following text
    and rewrite the corrected version. If you don't find
    and errors, just say "No errors found". Don't use 
    any punctuation around the text:
    ```{t}```"""
    response = get_completion(prompt)
    print(response)

 

 

7. Expanding 

# ๊ณ ๊ฐ์˜ ๋ฆฌ๋ทฐ์— ์ž๋™์œผ๋กœ ๋‹ต์žฅ์„ ํ•˜๋Š” AI ๋‹ต๋ณ€ ์ƒ์„ฑํ•˜๊ธฐ

sentiment = "negative"

# review for a blender
review = f"""
So, they still had the 17 piece system on seasonal \
sale for around $49 in the month of November, about \
half off, but for some reason (call it price gouging) \
around the second week of December the prices all went \
up to about anywhere from between $70-$89 for the same \
system. And the 11 piece system went up around $10 or \
so in price also from the earlier sale price of $29. \
So it looks okay, but if you look at the base, the part \
where the blade locks into place doesn’t look as good \
as in previous editions from a few years ago, but I \
plan to be very gentle with it (example, I crush \
very hard items like beans, ice, rice, etc. in the \ 
blender first then pulverize them in the serving size \
I want in the blender then switch to the whipping \
blade for a finer flour, and use the cross cutting blade \
first when making smoothies, then use the flat blade \
if I need them finer/less pulpy). Special tip when making \
smoothies, finely cut and freeze the fruits and \
vegetables (if using spinach-lightly stew soften the \ 
spinach then freeze until ready for use-and if making \
sorbet, use a small to medium sized food processor) \ 
that you plan to use that way you can avoid adding so \
much ice if at all-when making your smoothie. \
After about a year, the motor was making a funny noise. \
I called customer service but the warranty expired \
already, so I had to buy another one. FYI: The overall \
quality has gone done in these types of products, so \
they are kind of counting on brand recognition and \
consumer loyalty to maintain sales. Got it in about \
two days.
"""

prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt)
print(response)

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€