【Prompting】ChatGPT Prompt Engineering Development Guide (5)

ChatGPT Prompt Engineering Development Guide: Transforming


In this tutorial, we'll explore how large-scale language models can be used for text transformation tasks such as language translation, spelling and grammar checking, pitch adjustment, and formatting.
Note: The environment settings are the same as those in the previous article and will not be mentioned here.

translate

ChatGPT is trained using source code in multiple languages. This enables the model to be translated. Here are some examples of how to use this feature.

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

Results of the:

Hola, me gustaría ordenar una licuadora.

Three other cases:

prompt = f"""
Tell me which language this is:
```Combien coûte le lampadaire?```
"""
response = get_completion(prompt)
print(response)

Results of the:

This is French.
prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
response = get_completion(prompt)
print(response)

Results of the:

French pirate: ```Je veux commander un ballon de basket```
Spanish pirate: ```Quiero pedir una pelota de baloncesto```
English pirate: ```I want to order a basketball```
prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms:
'Would you like to order a pillow?'
"""
response = get_completion(prompt)
print(response)

Results of the:

Formal: ¿Le gustaría ordenar una almohada?
Informal: ¿Te gustaría ordenar una almohada?

universal translator

Imagine that you are in charge of a large multinational e-commerce company. Users send you IT questions in all their native languages. Your employees come from all over the world and only speak their native language. You need a universal translator!

user_messages = [
  "La performance du système est plus lente que d'habitude.",  # System performance is slower than normal
  "Mi monitor tiene píxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mój klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "我的屏幕在闪烁"                                               # My screen is flashing
]
for issue in user_messages:
    prompt = f"Tell me what language this is: ```{
      
      issue}```"
    lang = get_completion(prompt)
    print(f"Original message ({
      
      lang}): {
      
      issue}")

    prompt = f"""
    Translate the following  text to English \
    and Korean: ```{
      
      issue}```
    """
    response = get_completion(prompt)
    print(response, "\n")

Results of the

pitch shift

Writing can vary depending on the intended audience. ChatGPT can produce different tones.

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)

Results of the

format conversion

ChatGPT can convert between different formats. The hint should describe the input and output format.

data_json = {
    
     "resturant employees" :[
    {
    
    "name":"Shyam", "email":"[email protected]"},
    {
    
    "name":"Bob", "email":"[email protected]"},
    {
    
    "name":"Jai", "email":"[email protected]"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {
      
      data_json}
"""
response = get_completion(prompt)
print(response)
<table>
  <caption>Restaurant Employees</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Shyam</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>Jai</td>
      <td>[email protected]</td>
    </tr>
  </tbody>
</table>

Display HTML:

from IPython.display import display, Markdown, Latex, HTML, JSON
display(HTML(response))

output result

spell check/grammar check

Below are some examples of common grammar and spelling questions and LLM responses.

To signal to the LLM that you want it to proofread your text, you instruct the model to "proofread" or "proofread and correct".

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)

Results of the

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 = get_completion(prompt)
print(response)

Execution result:
Results of the
Correction mode:

from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))

Results of the
Added: RedlinesGenerate a Markdown text showing the difference between two strings/texts. These changes are strikethrough and underlined and look similar to Microsoft Word's Track Changes. This method of showing change is more familiar to lawyers and tighter to long-series characters.
pip install redlines

prompt = f"""
proofread and correct this review. Make it more compelling.
Ensure it follows APA style guide and targets an advanced reader.
Output in markdown format.
Text: ```{
      
      text}```
"""
response = get_completion(prompt)
display(Markdown(response))

Results of the:
Results of the

content source

  1. DeepLearning.AI: 《ChatGPT Prompt Engineering for Developers》

Guess you like

Origin blog.csdn.net/ARPOSPF/article/details/130663831