Wrong Word

parent:
linguistics

Related:


Overview

Sometimes you want to check if the output makes sense. This code does that.

Few Shot

This few-shot method does OK.

Code

import openai, json, pandas as pd
openai.api_key = "YOUR KEY"

#arguments to send the API
kwargs = {"engine":"davinci", "temperature":0, "max_tokens":30, "stop":"\n\n", }

import datetime
def query(prompt, myKwargs = kwargs):
  """
  wrapper for the API to save the prompt and the result
  """

  r = openai.Completion.create(prompt=prompt, **myKwargs)["choices"][0]["text"].strip()
  with open("{}.json".format(datetime.datetime.now().strftime("%Y%m%d%s")), "w") as fh:
    json.dump({"prompt":prompt, "response":r}, fh, indent=4)
  return r

prompt = """If the context doesn't make sense, list the major errors.

context: 'I have completed my masters degree.'
Error: None

context: 'I am rising up the stairs.'
Error: 'rising' does not make sense here. Do you mean walking?

context: 'The quarg is on me.'
Error: 'quarg' does not make sense. Is that a typo?

context: 'The man is not happy.'
Error: None

context: '{}'
Error:"""

Examples

query(prompt.format("The boy is ready for learn."))
>> "'ready' does not make sense. Is that a typo?"

query(prompt.format("The man is not happy."))
>> "None"

query(prompt.format("The boy is related to the girl."))
>> "None"

query(prompt.format("I have completed my masters degrade."))
>> "'degrade' does not make sense. Do you mean degree?"
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License