Using the OpenAI API, I tested with a couple of model versions. While not the same in all versions, there is garbage characters returned in the inference:
def classify_sentiment(text):
model_engine = "text-davinci-002"
cheaper_engine = "text-ada-001"
prompt = f"label:Sentiment Analysis (Positive, Negative, Neutral) | {text}"
completions = openai.Completion.create(
engine=model_engine, # cheaper_engine | model_engine
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
print (completions.choices)
sentiment = message.strip().split(" ")[-1]
sentiment_debug = message
total_tokens = completions["usage"]["total_tokens"]
print(f"The total number of tokens in the request is: {total_tokens}")
print (f"this is the debug: {sentiment_debug}")
-
Here is my function with the utterance:
classify_sentiment("I am unreasonably excited about the state of my phone today given I have only 1 bar")
-
Here is what is returned:
[<OpenAIObject at 0x15bc8d800> JSON: { "finish_reason": "stop", "index": 0, "logprobs": null, "text": " of battery life left\n\nPositive" }] The total number of tokens in the request is: 41 this is the debug: of battery life left Positive
'left\n\nPositive'
Why are there garbage characters in the returned json values that have nothing to do with the utterance I used to pass into the function? Example:
of battery life left Positive
and:
left\n\nPositive
Of particular interest is the function return value, because it is unpredictable and I wonder why I should have to parse the returned value. Am I missing something (such as a function property) where I can set the option to ONLY return positive, negative or neutral? Thank you in advance.
.\n\nNegative