Restriction of response to predefined keywords

I’d like to ask the API to restrict its responses to a predefined set of keywords. For instance, if asked to describe the setting of an outdoor scene where children are playing, it might response “exterior park” instead of “outdoor playground” because ‘exterior’ and ‘park’ are among the preset keywords, but ‘outdoor’ and ‘playground’ are not. Is there a way to do this?

You could try something like:

“With only the keywords: ‘exterior’, ‘park’, ‘children’, and ‘play’, can you describe an outdoor scene where children are playing? Remember to only use the provided keywords.”

You could then replace the text in the example with variables to allow for different input.

def create_prompt(keywords, question):
    keyword_str = "', '".join(keywords)
    
    prompt = f"With only the keywords: '{keyword_str}', {question} Remember to only use the provided keywords."
    
    return prompt

keywords = ['exterior', 'park', 'children', 'play']
question = "can you describe a setting of an outdoor scene where children are playing?"

prompt = create_prompt(keywords, question)
print(prompt)

The problem is, I have thousands of keywords. So it isn’t practical (or even possible) to include the list with every query.

I’m now fine-tuning a model, uploading thousands of questions and answers. No idea yet whether it’ll have the desired result though.

Example:

USER: Describe a place in a comma-delimited list of up to 2 keywords.
ASSISTANT: exterior, park

I wish you luck, you can certainly train the model to use words in the examples you provide, but I’m not sure if it will prevent others from being used.

What you are asking for is essentially a subset of the models existing vocabulary and LLM’s are simply not setup for that. LLM’s can categorise and they can follow a limited set of rules and work from a limited set of examples and lists, but trying to define thousands of allowed words would essentially require a full model retrain, or some form of mapping function.