I’m trying to include some words in the output, but in all cases, it includes only some of them.
I tried the following prompt:
Include the following keywords in the content: “term 1”, “term 2”, “term 3”
I also tried the following prompt too:
Include the following terms in the content and try to add 5 keywords per heading
What is the correct prompt to include all words I want in the output?
There is no “correct prompt” That will let you accomplish your tasks but here are a few things that might be helpful:
- Add it as an instructions to the generation to - Always include these key words.
- Add samples to GPT.
- Which model are you using ? In GPT 4, you can add this instruction in the system message which will make it more reliable.
I’m using ChatGPT and Turbo API. Both of them don’t obey that.
Also, I can’t use GPT-4 system message because I’m on the waiting list for the API
Can you please elaborate more on how to Add it as an instructions to the generation
Welcome to the OpenAI community @mokhtarali2001
If there are specific words that you want appearing in the completion, use
Simply obtain the tokens for the words an map them to a positive bias value
Looks like we have a professional here
Would you please give an example using Python or so on how to get the tokens for the words? and how to map them?
All I know is that this tool https://platform.openai.com/tokenizer?view=bpe can get the tokens.
How to get tokens programmatically?
Also, the tokens are for single words, in my case, sometimes it’s a sentence (4~5 words) needs to be included.
It is cool to learn that, thanks. But is it possible to use logit conditionally and instruct AI: if you think this than logit that token to 100 otherwise -100?
I instruct it and it doesn’t include all words.
Is there another prompt can do that better than the one I used?
I searched a little and found that tiktoken gets token ids for words I tested it and it works fine.
In my case, I want to include sentences in the output, not single words.
So, how to get tokens for sentences and force the API to include sentences in the output?
In my experience, it isn’t possible to set logit_bias after sending the API request. However, prompt can be designed to achieve that.
Interesting question. I tried experimenting and found that only individual tokens can be sent with bias, hence we can’t send an entire token sequence and set its bias to 100.
If we were to send the individual tokens with bias 100, the order of tokens is random.
The only way to make it work it is to send the logit bias as an orderedDict() ordered dictionary, where keys are int tokens and value are bias.
Simply add worked examples after your prompt - and before the task.
For GPT-4 you will only need 1 or 2 examples.
For GPT-3.5 you will need 3-4 examples.
You mean give examples of content in the prompt?
Best to add the prompt at the beginning, followed by examples, and then your task.
How an expert (insert a description of the task here)
(insert worked example here, input & output)
(insert worked example here, input & output)
Input: (your input here).
note: This strategy ensures you get exactly what you want.
You may need more than 2 examples if using GPT-3.5
Why I would give examples? If I wrote it I would put it directly in my content.
I think you’re talking about something else.
I just want chatgpt to include some words in the output.
Yes, so give a couple of examples of exactly that being done, perfectly as you want it.
It learns best by example.
(technique is known as few-shot prompting)
Maybe its having a hard time cramming all/multiple keywords at once. Especially if the max_toxens is low.
Maybe try generate one sentence at a time, with individual API calls, then one final call where you pass in all previous generated sentences as context, and request a paragraph as a summary, like:
I have tried to achieve this using different prompts but it doesn’t work consistently. For example I instruct it that if it thinks the result is safisfactory say A and otherwise say B and strictly apply this rule, I found out that it sometimes say “Since the result is not satisfactory I will not say A, until then B” since I wrote a code to detect A in its output, my code thinks it is satisfactory and fails. I know that you can try to improve this by modifying the code but the unpredictability in its output makes it very hard to write a consisting code.
The definition of “satisfactory” is open to interpretation. This leads to ambiguity. Trying to make your prompt as explicitly detailed as possible should improve the results.
Thanks, but the problem is not satisfaction being a relative concept.I strictly tell it not to mention a word until it is satisfied with the result. It correctly finds the result not satisfactory and it thinks that it doesn’t mention that word by saying “I wont mention the word until this is satisfactory”. It says the word by saying it wont mention that word I suspect that it knows the program will end when he says that word since there is a condition for that in my code and he is trying to break free by saying that word