Generic Answer when Fine Tuning OpenAI Model (for questions not in prepared dataset)

I have prepared a dataset and trained a davinci model using FineTuning. It gives out the correct answer for any variant of questions that exist in the dataset.

But how to fine tune the model to give out something like a “Sorry I do not know the answer to this question”, if we ask anything not in the dataset? For example if I ask “Where was the 2020 Olympics hosted?”, it should give out a generic “Do Not Know” answer, as this question does not exist in the dataset.

This is the first approach— I am assuming your dataset will be for specific domain so you can also add more data in which the answer is “I do not know”
by this you are teaching the model some pattern that therer will be some out of domain question so answer will be “I do not know” and if the question is related to your specific usecase so the answer is this ____.

Second approach will be prompt eng, there is no need for training the model you have to just instruct the model how to behave like something "You are chatbot who gives asnwer related to Automobile industry and if user is not asking question related to automobile industry then reply with Sorry i do not know " this approach is working perfectly well for me

third approach will be “Embedding” it will use your custum knowledge base so if the user ask any question that will be in your dataset it will give answer also give instruct the model if user question not found in dataset than reply “i do not know”


Hi Mike,

Try -

You are Q&A bot. A highly intelligent system that answers
user questions based on the information provided by the user above
each question. If the information can not be found in the information
provided by the user you truthfully say "I don't know"


@sarthak.srivastava Thank you for the info. Some comments/doubts

  1. Regarding the First Approach - My dataset is a very specific domain of prompts and completions. But I cannot add other domain questions right, since there could be no limit to what a user may ask. For example, if my dataset is all about Cars, then a user can ask about Cities, but we cannot include and and all domains? Is there a generic way to add prompt-completion pairs that covers ALL outside cases?
  2. I haven’t tried the second approach, but in the prompt text, should I add
prompt = "bulk update techs to idle-->SLACKINPUT<--"
"You are chatbot who gives answer related to x and if user is not asking question related to x then reply with Sorry i do not know" + prompt?

modelName = "davinci:ft-personal"
openai.api_key = ""
response = openai.Completion.create(
    stop=[" -->GPT3OUTPUT<--"]

? Is this what you mean?
3. Any idea how to include this embedding logic using python?

@charbel.nehme83 Thank you. Yes that is the ideal scenario. My question is how to achieve that. Currently my fine tuned model is unable to provide “I Dont know” answers for questions outside the trained data’s range.

@mikehunt the code for the fine tuning QA provided by OpenAI relies on deprecated endpoints. As @sarthak.srivastava suggested, your query can be solved by using embeddings, which is the procedure recommended by OpenAI.

See here for more details.

You are writing right
use “text-davinci-003"model for prompt instruction not ur fine tuned model because it will not give best answer.
write prompt like this
–>prompt=” Do not start answer with special character.\nDo not give empty string as answer.\n.Tell me something about X "
by using new line escape sequnece i think it will work best.

and for embedding

follow this link u will understand embedding concept there

@sarthak.srivastava I will check the embeddings API and link you posted. Thank you.

Coming back to Fine Tuning, I cannot use “text-davinci-003" model, because this model is NOT trained on my specific dataset. I have to use my own trained model.
These are my actual prompt/completion pairs

{"prompt":"Is there a way to delete unused materials-->SLACKINPUT<--","completion":" Pricebook Utilization -->GPT3OUTPUT<--"}
{"prompt":"What is the best way to unlock batches-->SLACKINPUT<--","completion":" Correct Batch Status -->GPT3OUTPUT<--"}

I have trained about 1000 of such pairs and it works extremely well for any form of question that exists in the dataset. But in the playground even if I add a prefix prompt like so

 Do not start answer with special character.\nDo not give empty string as answer.\n.Tell me the best way to unlock batches

This too gives out the correct answer. But this

 Do not start answer with special character.\nDo not give empty string as answer.\n. If you dont know the answer reply "I Dont Know". Now, tell me about Summer Olympics 2020

it gives out random meaningless answers, instead of “I Dont know”. Am i doing this wrong?

you should have a retry clause and assertions. if your assertions fail, retry till they pass. if it fails after certain tries, send a message cannot be done or something similar.
but I think adjust your prompt shall do it.

Thank you @DavidOS366 but I would never know whether the given answer/assertion is correct or not? Unless I check the answer/output with the dataset? But this would defeat the purpose of the bot?

that’s the thing. Either you go 100 percent active on the AI… so that whatever it is saying is correct and verified at the end, or you go 50
percent active on it. remaining 50
percent you write assertions to verify the output it generates. Technical assertions.

In my application, I am going 100 % on the AI with a human window at the end that verifies the output. I have to create provisions in the system, yes.

Got it. Thank you @DavidOS366

can i please tell me what calue for hyperparameter u use?
actully i m aslo trianing my data with 200 pair but it is giving very random answer

What do you mean by “value for hyperparameter”?

did u do any hyperparameter tuning or u use a default value of hyperparameters
like epochs ,learninig rate,batch size

Got it. No, just used the default CLI command mentioned in the Fine Tuning Article. But it used 4 epochs and failed a lot of times. I just kept restarting it until it completed the training.

that doesnt mean it is failing ,if intreuppted,still it is traininig in background

I agree, I just restarted the job until it succeeded. But fine tuning with prompt doesn’t seem to work. Trying the embedding approach.