0

I am using the Python Open AI API to give definitions for words automatically and return the text result, but it is giving too much text.

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="give a definition for "+str(definition),
  temperature=0.7,
  max_tokens=50,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)
print( str(response['choices'][0]['text']))

However, it would return something like this:

1. Definition: A statement that explains the meaning of a word or phrase.

2. High-definition Television: A type of television system that provides a much higher resolution than a standard-definition television.

3. Standard

It is giving me too much text; how can I narrow it down to just give the first result?

George
  • 31
  • 5

1 Answers1

0

You can use "few shot learning" to train your model by using a longer prompt which gives examples of what you want. Here is an example of a quick rough-and-dirty prompt that will get definitions.

This one returns results maybe a bit longer than you want, because I used examples that enumerate all definitions. So it's giving longer lists--you can tweak this basic approach to get what you want. I threw it together pretty quick.

Sample prompt implementing few shot learning:

I am going to ask you for a definition of a word.

Here is an example of a definition for the word "tree":

noun
1. a woody perennial plant; 2.a wooden structure or part of a structure.

verb
1. force (a hunted animal) to take refuge in a tree.

Here is an example of a definition for the word "plasma":

noun 
1.the colourless fluid part of blood, lymph, or milk; 2. an ionized gas consisting of positive ions and free electrons 3. a bright green, translucent variety of quartz 4. another term for cytoplasm or protoplasm.


Here is an example of a definition for the word "there":

adverb
1. in, at, or to that place or position. 2. used in attracting someones attention or calling attention to someone or something.

exclamation
1. used to focus attention on something. 2. used to comfort someone.

[more examples here]

Here is a definition for the word "[the word you want defined]":