Skip to content

Commit

Permalink
Fix prompts
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Gitman <[email protected]>
  • Loading branch information
Kipok committed Jun 27, 2024
1 parent 3eb9fab commit 6ea02d3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 66 deletions.
8 changes: 3 additions & 5 deletions nemo_skills/inference/prompt/llama3/base.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}My solution:\n{generation}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nMy solution:\n{generation}\n\n\n\n\n\n"

system: ""
user: |-
Here are some examples of questions and solutions followed by a new question that you need to solve.
Make sure to put the answer (and only answer) inside \boxed{{}}.
{examples}Question:
{question}
{question}{context}
{context}
prompt_template: "<|begin_of_text|>{user}My solution:\n{generation}"
prompt_template: "<|begin_of_text|>{user}\n\nMy solution:\n{generation}"

stop_phrases: ["\n\n\n\n\n\n"]
13 changes: 6 additions & 7 deletions nemo_skills/inference/prompt/llama3/instruct.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}My solution:\n{generation}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nMy solution:\n{generation}\n\n\n\n\n\n"

system: |-
You are Meta AI, a sophisticated and energetic AI Assistant. You excel at solving mathematical problems.
system: ""

user: |-
Here are some examples of questions and solutions followed by a new question that you need to solve.
Make sure to put the answer (and only answer) inside \boxed{{}}.
{examples}Question:
{question}
{context}
{question}{context}
prompt_template: |-
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
{system}<|eot_id|><|start_header_id|>user<|end_header_id|>
{user}<|eot_id|><|start_header_id|>assistant<|end_header_id|>{generation}
{user}
<|eot_id|><|start_header_id|>assistant<|end_header_id|>{generation}
stop_phrases: ["<|eot_id|>"]
4 changes: 0 additions & 4 deletions nemo_skills/inference/prompt/llama3/sft.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
few_shot_examples:
template: ""
num_few_shots: 0

system: ""

user: "{question}{context}"
Expand Down
6 changes: 2 additions & 4 deletions nemo_skills/inference/prompt/nemotron/fewshot.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
few_shot_examples:
template: "Example question:\n{question}\n\n{context}Example solution:\n{generation}\n\n\n\n\n\n"
template: "Example question:\n{question}{context}\n\nExample solution:\n{generation}\n\n\n\n\n\n"

system: ""

Expand All @@ -8,9 +8,7 @@ user: |-
Make sure to put the answer (and only answer) inside \boxed{{}}.
{examples}Question:
{question}
{context}
{question}{context}
Don't forget that your final answer should be inside \boxed{{}}!
Expand Down
5 changes: 0 additions & 5 deletions nemo_skills/inference/prompt/nemotron/zeroshot.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
few_shot_examples:
template: ""
num_few_shots: 0

system: ""

user: |-
You are an expert in math. Given the math question below, I want you to reason through the steps and then give a final answer.
Your final answer should be inside \boxed{{}}.
{examples}Question:
{question}{context}
prompt_template: |-
Expand Down
8 changes: 3 additions & 5 deletions nemo_skills/inference/prompt/openmathinstruct/base.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}My solution:\n{generation}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nMy solution:\n{generation}\n\n\n\n\n\n"
system: ""
user: |-
Here are some examples of questions and solutions followed by a new question that you need to solve.
Make sure to put the answer (and only answer) inside \boxed{{}}.
{examples}Question:
{question}
{question}{context}
{context}
prompt_template: "{system}{user}My solution:\n{generation}"
prompt_template: "{system}{user}\n\nMy solution:\n{generation}"
stop_phrases: ["\n\n\n\n\n\n"]
8 changes: 3 additions & 5 deletions nemo_skills/inference/prompt/openmathinstruct/reference.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}My solution:\n{reference_solution}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nMy solution:\n{reference_solution}\n\n\n\n\n\n"
system: ""
user: |-
Here are some examples of questions and solutions followed by a new question that you need to solve.
Make sure to put the answer (and only answer) inside \boxed{{}}.
{examples}Question:
{question}
{question}{context}
{context}
prompt_template: "{system}{user}My solution:\n{generation}"
prompt_template: "{system}{user}\n\nMy solution:\n{generation}"
stop_phrases: ["\n\n\n\n\n\n"]
6 changes: 1 addition & 5 deletions nemo_skills/inference/prompt/openmathinstruct/sft.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
few_shot_examples:
template: ""
num_few_shots: 0

system: >- # no line breaks!
You're an expert Python programmer and mathematician.
Help the user to solve this problem using code when necessary.
Make sure to put the answer (and only answer) inside \boxed{}.
user: "{question}\n\n{context}"
user: "{question}{context}\n\n"

prompt_template: "System:\n{system}\n\nUser:\n{user}Assistant:\n{generation}"
stop_phrases: []
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}My masked solution:\n{generation}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nMy masked solution:\n{generation}\n\n\n\n\n\n"
system: ""
user: "\
Here are some examples of questions, solutions, \
Expand All @@ -8,6 +8,6 @@ user: "\
mentioned in the solution that are not mentioned in the question. \
Mask the intermediate values calculated in the solution via capitalized variables, such as M, N, M_01.\n\n\
{examples}\
Question:\n{question}\n\n{context}"
Question:\n{question}{context}\n\n"
prompt_template: "{system}{user}My masked solution:\n{generation}"
stop_phrases: ["\n\n\n\n\n\n"]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}Write another question similar to this one:\n{augmented_question}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nWrite another question similar to this one:\n{augmented_question}\n\n\n\n\n\n"

system: ""

user: |-
You are an AI assistant that excels at creating similar questions. Follow the given examples.
{examples}Question:
{question}
{context}
{question}{context}
prompt_template: |-
{system}{user}Write another question similar to this one:
{system}{user}
Write another question similar to this one:
{generation}
stop_phrases: ["\n\n\n\n\n\n"]
10 changes: 5 additions & 5 deletions nemo_skills/inference/prompt/question_generation/rephrasing.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
few_shot_examples:
template: "Question:\n{question}\n\n{context}Rephrase the above question:\n{rephrased_question}\n\n\n\n\n\n"
template: "Question:\n{question}{context}\n\nRephrase the above question:\n{rephrased_question}\n\n\n\n\n\n"

system: ""

user: |-
You are an AI assistant that excels at rephrasing questions. Follow the given examples.
{examples}Question:
{question}
{context}
{question}{context}
prompt_template: |-
{system}{user}Rephrase the above question:
{system}{user}
Rephrase the above question:
{generation}
stop_phrases: ["\n\n\n\n\n\n"]
10 changes: 5 additions & 5 deletions nemo_skills/inference/prompt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def retrieve(self, query: str, top_k: int = 1):

@nested_dataclass
class FewShotExamplesConfig:
template: str = MISSING
template: str = ""
num_few_shots: int = 0

examples_type: Optional[str] = None
Expand Down Expand Up @@ -241,11 +241,11 @@ def get_prompt_config(prompt_type: str) -> PromptConfig:
# and so most often will require changes to the code anyway
context_templates = {
"empty": "",
"reference_solution": "\n\nReference solution (do not copy it):\n{reference_solution}\n\n",
"masked_solution": "\n\nReference solution:\n{masked_reference_solution}\n\n",
"table": "\n\nUse the following table to answer the question:\n{table}\n\n",
"reference_solution": "\n\nReference solution (do not copy it):\n{reference_solution}",
"masked_solution": "\n\nReference solution:\n{masked_reference_solution}",
"table": "\n\nUse the following table to answer the question:\n{table}",
"table_solution": (
"\n\nUse the following table to answer the question:\n{table}\n"
"Reference solution (do not copy it):\n{reference_solution}\n\n"
"Reference solution (do not copy it):\n{reference_solution}"
),
}
15 changes: 6 additions & 9 deletions tests/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def test_llama3_instruct_prompt():

expected_prompt = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are Meta AI, a sophisticated and energetic AI Assistant. You excel at solving mathematical problems.
You will look at the examples provided by the user and try to follow the solution format as much as possible.<|eot_id|><|start_header_id|>user<|end_header_id|>
<|eot_id|><|start_header_id|>user<|end_header_id|>
Here are some examples of questions and solutions followed by a new question that you need to solve.
Make sure to put the answer (and only answer) inside \\boxed{}.
Expand Down Expand Up @@ -243,8 +241,11 @@ def test_nemotron_zeroshot_prompt():
expected_prompt = """<extra_id_0>System
<extra_id_1>User
2 + 2 = ?
<extra_id_1>Assistant
You are an expert in math. Given the math question below, I want you to reason through the steps and then give a final answer.
Your final answer should be inside \\boxed{}.
2 + 2 = ?<extra_id_1>Assistant
"""
assert prompt.build_string({'question': '2 + 2 = ?'}) == expected_prompt

Expand Down Expand Up @@ -287,8 +288,6 @@ def test_nemotron_fewshot_prompt():
Question:
2 + 2 = ?
Don't forget that your final answer should be inside \\boxed{}!
<extra_id_1>Assistant
"""
Expand Down Expand Up @@ -343,8 +342,6 @@ def test_nemotron_fewshot_prompt_reference():
Reference solution (do not copy it):
What should I do??
Don't forget that your final answer should be inside \\boxed{}!
<extra_id_1>Assistant
"""
Expand Down

0 comments on commit 6ea02d3

Please sign in to comment.