【プロンプト】ChatGPT プロンプトエンジニアリング開発ガイド (5)


このチュートリアルでは、言語翻訳、スペルと文法チェック、ピッチ調整、書式設定などのテキスト変換タスクに大規模な言語モデルを使用する方法を検討します。
注: 環境設定は前の記事と同じであるため、ここでは説明しません。

翻訳

ChatGPT は、複数の言語のソース コードを使用してトレーニングされます。これにより、モデルを変換できるようになります。この機能の使用方法の例をいくつか示します。

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

結果:

Hola, me gustaría ordenar una licuadora.

他の 3 つのケース:

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

結果:

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)

結果:

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)

結果:

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

ユニバーサル翻訳者

あなたが大規模な多国籍電子商取引会社の責任者であると想像してください。ユーザーは、すべての母国語で IT に関する質問を送信します。従業員は世界中から集まっており、母国語のみを話します。万能翻訳者が必要です!

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")

の結果

ピッチシフト

書き方は対象読者によって異なります。ChatGPT はさまざまなトーンを生成できます。

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)

の結果

フォーマット変換

ChatGPT は異なる形式の間で変換できます。ヒントでは入力形式と出力形式を説明する必要があります。

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>

HTMLを表示:

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

出力結果

スペルチェック/文法チェック

以下は、一般的な文法とスペルの質問と LLM の応答の例です。

LLM にテキストを校正してほしいという信号を送るには、モデルに「校正」または「校正と修正」を指示します。

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)

の結果

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)

実行結果:
の結果
修正モード:

from redlines import Redlines

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

の結果
追加: Redlines2 つの文字列/テキストの違いを示すマークダウン テキストを生成します。これらの変更には取り消し線と下線が引かれており、Microsoft Word の変更履歴に似ています。変化を示すこの方法は、弁護士にとっては馴染みがあり、長期シリーズのキャラクターにとってはより緊密です。
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))

結果:
の結果

コンテンツソース

  1. DeepLearning.AI: 《開発者向け ChatGPT プロンプト エンジニアリング》

おすすめ

転載: blog.csdn.net/ARPOSPF/article/details/130663831