3

I use LLMs for QA tasks. The following prompt sent to Llama-2-13b-chat-hf:

Give a precise answer to the question based on the context. Don't be verbose.
CONTEXT: .....
QUESTION: what is the commission rate?
ANSWER:

It gives me the answer like:

The commission rate is 20%

How to prompt so that it can give the answer without a full sentence like:

20%
1
  • In order to get it to output the exact value you have to tell it to output the exact value type. When I told it to output only the number it gave only the number. If you want other cases you'll have to change the prompt to match the value type. Commented Sep 15, 2023 at 22:01

1 Answer 1

4

Add a restriction like the following to your prompt:

Do not reply using a complete sentence, and only give the answer in the following format: xx%.

Example:

75 is what percentage of 150? Do not reply using a complete sentence, and only give the answer in the following format: xx%.

Both ChatGPT and Bard give this as their response to the prompt above:

50%

Without the restriction in the prompt, both ChatGPT and Bard will give responses that consist of one or more sentences.

1
  • 1
    This is helpful. The key in my QA case was adding the instruction after the input (question, in this case) instead of giving the instruction first and then asking a question.
    – Pedram
    Commented Mar 31 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.