728x90
1ํธ์์๋ ํ๋กฌํํธ ์์ง๋์ด๋ง์ ๋ํ ์์น ๋ฐ ์ฌ์ฉ ์ ์ฃผ์ํด์ผ ํ ๋ถ๋ถ์ ๋ํด์ ๋ค๋ค์ต๋๋ค.
2023.07.31 - [๐ป ์ฝ๋ฉ·๊ฐ๋ฐ·๋ถ์] - ChatGPT ํ๋กฌํํธ ์์ง๋์ด๋ง ๊ฐ์ด๋ - ไธ
๋๋จธ์ง ๋ถ๋ถ์์๋ ์์ฝ, ์ถ๋ก , ๋ณํ, ํ์ฅ, ์ฑ๋ด ๊ฐ๋ฐ ๋ฑ ์ด๋ป๊ฒ ChatGPT๋ฅผ ํ์ฉํ ์ ์๋์ง์ ๋ํ ๋ด์ฉ์ ๋ค๋ค์ต๋๋ค.
Python Notebook ๋ค์ด๋ก๋
ํต์ฌ ๋ด์ฉ ์์ฝ์ ๋ฆฌ (Key Takeaways)
์์ฝ (Summarizing)
- ๋จ์ด, ๋ฌธ์ฅ, ๊ธ์์๋ฅผ ์ ํํ์ฌ ์ํ๋ ๊ธธ์ด์ ๊ฒฐ๊ณผ๊ฐ์ ์ป๋๋ค.
- ํน์ ๋ถ๋ถ์ ์ง์คํ๋๋ก ํ๋กฌํํธ๋ฅผ ์์ฑํ๋ค.
- "์์ฝ (Summarize)" ๋์ ์ "์ถ์ถ (Extract)"์ด๋ผ๋ ์ฉ์ด๋ฅผ ์ฌ์ฉํด ๋ณธ๋ค
์ถ๋ก (Inferring)
- ๊ฐ์ฑ ๋ถ์ (Sentiment Analysis), ์ํฐํฐ์ถ์ถ (NER), ํ ํฝ ๋ฑ์ ์์ฐ์ด์ฒ๋ฆฌ ์ํ
- ํ ๋ฒ์ ๋ค์ํ ์ข ๋ฅ์ ๋ผ๋ฒจ ๋ํ ์ถ์ถ ๊ฐ๋ฅ
- ํน์ ํ ํฝ์ด ์ถํํ์ ๋ ์๋ฆผ์ ์ค ์๋ ์์
๋ณํ (Transforming)
- ๋ค์ํ ์ธ์ด๋ก ๋ฒ์ญ ๊ฐ๋ฅ
- ์ธ์ด์ ํค, ํ์, ๋ฌธ๋ฒ ์ฒดํฌ ๋ฑ์ด ๊ฐ๋ฅํจ
ํ์ฅ (Expanding)
- ChatGPT API์ Temperature ํ๋ผ๋ฏธํฐ ์กฐ์ ์ผ๋ก ์ฐฝ์์ ์ธ ๋ต๋ณ์ ์ ๋ํ ์ ์์ (์ผ๊ด์ฑ์ ๋จ์ด์ง)
- ์์ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณ ๊ฐ์๊ฒ ์๋์ผ๋ก ๋ต๋ณํด ์ฃผ๋ ์ด๋ฉ์ผ์ ์์ฑํ๋ AI๋ด ์์ฑ
- "AI๊ฐ ์์ฑํ๋ค"๋ ๊ณ ์ง๋ฅผ ํ๋ ๊ฒ์ ๊ถ๊ณ
์ฑ๋ด (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)
๋ฐ์ํ
'๐ป ITยท๊ธฐ์ ยทํต๊ณ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ChatGPT๋ก ์ ํ๋ธ ํ๋กํ ์ฌ์ง ๋ง๋ค๊ธฐ (feat. DALL-E-3) (2) | 2024.01.30 |
---|---|
๊ตฌ๊ธ์ ๋ฐ๊ฒฉ? Gemini ์ถ์์ ๋ํ ์๊ฐ (2) | 2023.12.11 |
ChatGPT ํ๋กฌํํธ ์์ง๋์ด๋ง ๊ฐ์ด๋ - ไธ (0) | 2023.07.31 |
API๊ฐ ๋ญ์ฃ ? (2) | 2023.06.08 |
๋์ P-Value๋?! (3) | 2023.06.05 |
๋๊ธ