LoginSignup
1
1

More than 1 year has passed since last update.

GPT-3を使って英語を添削してもらう

Last updated at Posted at 2022-12-25

概要

  • OpenAIのモデル「Text davinci」に英文添削をしてもらう
  • 意外と使い物になる英文ができた。

動機

  • 英語で何かを書かなくてはならないときによく詰んでしまう。
  • Grammarlyなどのサービスがあるが、無料版では文法間違いのみの指摘。
  • ちょっとした英文のブラッシュアップをしたい。

🧠 Awesome ChatGPT Prompts

巷を沸かせているOpenAiのChatGPTですが、世界のすごい人が「呪文集」をまとめてくれています。
🧠 Awesome ChatGPT Prompts
その中に"Act as an English Translator and Improver"という面白いものがありました。
これは、ChatGPTが英語教師に成り代わって文書推敲してくれるという願ったり叶ったりの呪文です。

Act as an English Translator and Improver
I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My first sentence is "istanbulu cok seviyom burada olmak cok guzel"

My first sentence is〜以下に任意の文章を流し込めば、文書を吐いてくれるようです。
image.png

これは期待できそう...?

OpenAIのpythonAPI

https://beta.openai.com/docs/libraries/python-bindings
色々な先人が解説しているのでここではざっと流れだけ触れます。

  • OpenAIのアカウントを作る
  • ApiKeyを発行する
  • pip install openaiを叩いてライブラリをダウンロード
  • python上でimport openaiしてゴニョゴニョ

実装例

english_teacher.py
import os
import openai
OPEN_AI_KEY = "あなたのApikey"
openai.api_key = OPEN_AI_KEY
MAX_WORD = 500
revised_ans = ""

word = "I phoned her but she wasn’t there here." #ここに添削してほしい文書を入力
magic_word = f"I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My first sentence is '{word}'"

count_word = len(magic_word.split())
if count_word < MAX_WORD:
    response = openai.Completion.create(model="text-davinci-003", prompt=magic_word, temperature=0, max_tokens=1000)
    if response["choices"]:
        res = response["choices"][0]
        if res["finish_reason"] == "stop":
            revised_ans = res["text"]
else:
    print("Exceeded # of words.")

print(revised_ans)

どうやら注意点としては、
ChatGPTはAPIでは直接叩けず、学習完成版のText Davinci 003モデルとなる、ということでしょうか。
両者の違いについてはこちらにざっくり書かれています。

出力例

$ python english_teacher.py


I phoned her, yet she was not present.

んー、なんか洗練されている気がしますね(?)

考察

  • 入力は標準入力や、txtファイル読み込みとかにしても面白いかもしれません。
  • Promptsもいろいろな例が公開されているので、magic_word部分を変えても面白いと思います。(剽窃チェッカーやサッカー解説者モードとかもありますw)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1