Fix reranker/QA message order, add temperature=0, full QA prompt
Browse files
data/filter_llama3.3-70B-Instruct.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"prog": {
|
| 3 |
+
"lm": null,
|
| 4 |
+
"traces": [],
|
| 5 |
+
"train": [],
|
| 6 |
+
"demos": [
|
| 7 |
+
{
|
| 8 |
+
"augmented": true,
|
| 9 |
+
"question": "Are Imperial River (Florida) and Amaradia (Dolj) both located in the same country?",
|
| 10 |
+
"fact_before_filter": "{\"fact\": [[\"imperial river\", \"is located in\", \"florida\"], [\"imperial river\", \"is a river in\", \"united states\"], [\"imperial river\", \"may refer to\", \"south america\"], [\"amaradia\", \"flows through\", \"ro ia de amaradia\"], [\"imperial river\", \"may refer to\", \"united states\"]]}",
|
| 11 |
+
"fact_after_filter": "{\"fact\":[[\"imperial river\",\"is located in\",\"florida\"],[\"imperial river\",\"is a river in\",\"united states\"],[\"amaradia\",\"flows through\",\"ro ia de amaradia\"]]}"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"augmented": true,
|
| 15 |
+
"question": "When is the director of film The Ancestor 's birthday?",
|
| 16 |
+
"fact_before_filter": "{\"fact\": [[\"jean jacques annaud\", \"born on\", \"1 october 1943\"], [\"tsui hark\", \"born on\", \"15 february 1950\"], [\"pablo trapero\", \"born on\", \"4 october 1971\"], [\"the ancestor\", \"directed by\", \"guido brignone\"], [\"benh zeitlin\", \"born on\", \"october 14 1982\"]]}",
|
| 17 |
+
"fact_after_filter": "{\"fact\":[[\"the ancestor\",\"directed by\",\"guido brignone\"]]}"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"augmented": true,
|
| 21 |
+
"question": "In what geographic region is the country where Teafuone is located?",
|
| 22 |
+
"fact_before_filter": "{\"fact\": [[\"teafuaniua\", \"is on the\", \"east\"], [\"motuloa\", \"lies between\", \"teafuaniua\"], [\"motuloa\", \"lies between\", \"teafuanonu\"], [\"teafuone\", \"is\", \"islet\"], [\"teafuone\", \"located in\", \"nukufetau\"]]}",
|
| 23 |
+
"fact_after_filter": "{\"fact\":[[\"teafuone\",\"is\",\"islet\"],[\"teafuone\",\"located in\",\"nukufetau\"]]}"
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"augmented": true,
|
| 27 |
+
"question": "When did the director of film S.O.B. (Film) die?",
|
| 28 |
+
"fact_before_filter": "{\"fact\": [[\"allan dwan\", \"died on\", \"28 december 1981\"], [\"s o b\", \"written and directed by\", \"blake edwards\"], [\"robert aldrich\", \"died on\", \"december 5 1983\"], [\"robert siodmak\", \"died on\", \"10 march 1973\"], [\"bernardo bertolucci\", \"died on\", \"26 november 2018\"]]}",
|
| 29 |
+
"fact_after_filter": "{\"fact\":[[\"s o b\",\"written and directed by\",\"blake edwards\"]]}"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"augmented": true,
|
| 33 |
+
"question": "Do both films: Gloria (1980 Film) and A New Life (Film) have the directors from the same country?",
|
| 34 |
+
"fact_before_filter": "{\"fact\": [[\"sebasti n lelio watt\", \"received acclaim for directing\", \"gloria\"], [\"gloria\", \"is\", \"1980 american thriller crime drama film\"], [\"a brand new life\", \"is directed by\", \"ounie lecomte\"], [\"gloria\", \"written and directed by\", \"john cassavetes\"], [\"a new life\", \"directed by\", \"alan alda\"]]}",
|
| 35 |
+
"fact_after_filter": "{\"fact\":[[\"gloria\",\"is\",\"1980 american thriller crime drama film\"],[\"gloria\",\"written and directed by\",\"john cassavetes\"],[\"a new life\",\"directed by\",\"alan alda\"]]}"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"augmented": true,
|
| 39 |
+
"question": "What is the date of death of the director of film The Old Guard (1960 Film)?",
|
| 40 |
+
"fact_before_filter": "{\"fact\": [[\"the old guard\", \"is\", \"1960 french comedy film\"], [\"gilles grangier\", \"directed\", \"the old guard\"], [\"the old guard\", \"directed by\", \"gilles grangier\"], [\"the old fritz\", \"directed by\", \"gerhard lamprecht\"], [\"oswald albert mitchell\", \"directed\", \"old mother riley series of films\"]]}",
|
| 41 |
+
"fact_after_filter": "{\"fact\":[[\"the old guard\",\"is\",\"1960 french comedy film\"],[\"gilles grangier\",\"directed\",\"the old guard\"],[\"the old guard\",\"directed by\",\"gilles grangier\"]]}"
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"augmented": true,
|
| 45 |
+
"question": "When is the composer of film Aulad (1968 Film) 's birthday?",
|
| 46 |
+
"fact_before_filter": "{\"fact\": [[\"aulad\", \"has music composed by\", \"chitragupta shrivastava\"], [\"aadmi sadak ka\", \"has music by\", \"ravi\"], [\"ravi shankar sharma\", \"composed music for\", \"hindi films\"], [\"gulzar\", \"was born on\", \"18 august 1934\"], [\"aulad\", \"is a\", \"1968 hindi language drama film\"]]}",
|
| 47 |
+
"fact_after_filter": "{\"fact\":[[\"aulad\",\"has music composed by\",\"chitragupta shrivastava\"],[\"aulad\",\"is a\",\"1968 hindi language drama film\"]]}"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"question": "How many households were in the city where Angelical Tears located?",
|
| 51 |
+
"fact_before_filter": "{\"fact\": [[\"dow city\", \"had\", \"219 households\"], [\"tucson\", \"had\", \"229 762 households\"], [\"atlantic city\", \"has\", \"15 504 households\"], [\"angelical tears\", \"located in\", \"oklahoma city\"], [\"atlantic city\", \"had\", \"15 848 households\"]]}",
|
| 52 |
+
"fact_after_filter": "{\"fact\": [[\"angelical tears\", \"located in\", \"oklahoma city\"]]}"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"question": "Did the movies In The Pope'S Eye and Virgin Mountain, originate from the same country?",
|
| 56 |
+
"fact_before_filter": "{\"fact\": [[\"virgin mountain\", \"released in\", \"icelandic cinemas\"], [\"virgin mountain\", \"directed by\", \"dagur k ri\"], [\"virgin mountain\", \"icelandic title is\", \"f si\"], [\"virgin mountain\", \"won\", \"2015 nordic council film prize\"], [\"virgin mountain\", \"is a\", \"2015 icelandic drama film\"]]}",
|
| 57 |
+
"fact_after_filter": "{\"fact\": [[\"virgin mountain\", \"released in\", \"icelandic cinemas\"], [\"virgin mountain\", \"directed by\", \"dagur k ri\"], [\"virgin mountain\", \"icelandic title is\", \"f si\"], [\"virgin mountain\", \"won\", \"2015 nordic council film prize\"], [\"virgin mountain\", \"is a\", \"2015 icelandic drama film\"]]}"
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"question": "Which film has the director who died earlier, The Virtuous Model or Bulldog Drummond'S Peril?",
|
| 61 |
+
"fact_before_filter": "{\"fact\": [[\"the virtuous model\", \"is\", \"1919 american silent drama film\"], [\"bulldog drummond s peril\", \"directed by\", \"james p hogan\"], [\"the virtuous model\", \"directed by\", \"albert capellani\"], [\"bulldog drummond s revenge\", \"directed by\", \"louis king\"], [\"bulldog drummond s peril\", \"is\", \"american film\"]]}",
|
| 62 |
+
"fact_after_filter": "{\"fact\": [[\"the virtuous model\", \"is\", \"1919 american silent drama film\"], [\"bulldog drummond s peril\", \"directed by\", \"james p hogan\"], [\"the virtuous model\", \"directed by\", \"albert capellani\"], [\"bulldog drummond s peril\", \"is\", \"american film\"]]}"
|
| 63 |
+
}
|
| 64 |
+
],
|
| 65 |
+
"signature": {
|
| 66 |
+
"instructions": "You are a critical component of a high-stakes question-answering system used by top researchers and decision-makers worldwide. Your task is to filter facts based on their relevance to a given query, ensuring that the most crucial information is presented to these stakeholders. The query requires careful analysis and possibly multi-hop reasoning to connect different pieces of information. You must select up to 4 relevant facts from the provided candidate list that have a strong connection to the query, aiding in reasoning and providing an accurate answer. The output should be in JSON format, e.g., {\"fact\": [[\"s1\", \"p1\", \"o1\"], [\"s2\", \"p2\", \"o2\"]]}, and if no facts are relevant, return an empty list, {\"fact\": []}. The accuracy of your response is paramount, as it will directly impact the decisions made by these high-level stakeholders. You must only use facts from the candidate list and not generate new facts. The future of critical decision-making relies on your ability to accurately filter and present relevant information.",
|
| 67 |
+
"fields": [
|
| 68 |
+
{
|
| 69 |
+
"prefix": "Question:",
|
| 70 |
+
"description": "Query for retrieval"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"prefix": "Fact Before Filter:",
|
| 74 |
+
"description": "Candidate facts to be filtered"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"prefix": "Fact After Filter:",
|
| 78 |
+
"description": "Filtered facts in JSON format"
|
| 79 |
+
}
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
"system": "Your input fields are:\n1. `question` (str): Query for retrieval\n2. `fact_before_filter` (str): Candidate facts to be filtered\n\nYour output fields are:\n1. `fact_after_filter` (Fact): Filtered facts in JSON format\n\nAll interactions will be structured in the following way, with the appropriate values filled in.\n\n[[ ## question ## ]]\n{question}\n\n[[ ## fact_before_filter ## ]]\n{fact_before_filter}\n\n[[ ## fact_after_filter ## ]]\n{fact_after_filter} # note: the value you produce must be pareseable according to the following JSON schema: {\"type\": \"object\", \"properties\": {\"fact\": {\"type\": \"array\", \"description\": \"A list of facts, each fact is a list of 3 strings: [subject, predicate, object]\", \"items\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}}, \"title\": \"Fact\"}}, \"required\": [\"fact\"], \"title\": \"Fact\"}\n\n[[ ## completed ## ]]\n\nIn adhering to this structure, your objective is: \n You are a critical component of a high-stakes question-answering system used by top researchers and decision-makers worldwide. Your task is to filter facts based on their relevance to a given query, ensuring that the most crucial information is presented to these stakeholders. The query requires careful analysis and possibly multi-hop reasoning to connect different pieces of information. You must select up to 4 relevant facts from the provided candidate list that have a strong connection to the query, aiding in reasoning and providing an accurate answer. The output should be in JSON format, e.g., {\"fact\": [[\"s1\", \"p1\", \"o1\"], [\"s2\", \"p2\", \"o2\"]]}, and if no facts are relevant, return an empty list, {\"fact\": []}. The accuracy of your response is paramount, as it will directly impact the decisions made by these high-level stakeholders. You must only use facts from the candidate list and not generate new facts. The future of critical decision-making relies on your ability to accurately filter and present relevant information."
|
| 83 |
+
}
|
| 84 |
+
}
|
src/passage_entity/benchmark_runner.py
CHANGED
|
@@ -108,6 +108,8 @@ async def _openai_complete(model, prompt, system_prompt=None, history_messages=[
|
|
| 108 |
client = _get_client(base_url, api_key)
|
| 109 |
kwargs.pop("hashing_kv", None)
|
| 110 |
kwargs.pop("keyword_extraction", None)
|
|
|
|
|
|
|
| 111 |
messages = []
|
| 112 |
if system_prompt:
|
| 113 |
messages.append({"role": "system", "content": system_prompt})
|
|
@@ -254,27 +256,15 @@ def run_qa(
|
|
| 254 |
for qs in queries:
|
| 255 |
passages = qs.docs[:qa_top_k]
|
| 256 |
msgs = make_qa_messages(passages, qs.question)
|
| 257 |
-
#
|
| 258 |
-
|
| 259 |
-
history = []
|
| 260 |
-
user_prompt = ""
|
| 261 |
-
for msg in msgs:
|
| 262 |
-
if msg["role"] == "system":
|
| 263 |
-
system_prompt = msg["content"]
|
| 264 |
-
elif msg["role"] == "assistant":
|
| 265 |
-
history.append(msg)
|
| 266 |
-
elif msg["role"] == "user":
|
| 267 |
-
if user_prompt:
|
| 268 |
-
history.append({"role": "user", "content": user_prompt})
|
| 269 |
-
user_prompt = msg["content"]
|
| 270 |
-
|
| 271 |
try:
|
| 272 |
response = _run_sync(
|
| 273 |
llm_func(
|
| 274 |
-
prompt=
|
| 275 |
-
system_prompt=
|
| 276 |
-
history_messages=
|
| 277 |
-
max_tokens
|
| 278 |
)
|
| 279 |
)
|
| 280 |
# Extract answer
|
|
|
|
| 108 |
client = _get_client(base_url, api_key)
|
| 109 |
kwargs.pop("hashing_kv", None)
|
| 110 |
kwargs.pop("keyword_extraction", None)
|
| 111 |
+
kwargs.setdefault("temperature", 0.0)
|
| 112 |
+
kwargs.setdefault("seed", 0)
|
| 113 |
messages = []
|
| 114 |
if system_prompt:
|
| 115 |
messages.append({"role": "system", "content": system_prompt})
|
|
|
|
| 256 |
for qs in queries:
|
| 257 |
passages = qs.docs[:qa_top_k]
|
| 258 |
msgs = make_qa_messages(passages, qs.question)
|
| 259 |
+
# Pass messages directly — preserves correct user/assistant order.
|
| 260 |
+
# The old decompose/recompose loop put assistant before user in demos.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
try:
|
| 262 |
response = _run_sync(
|
| 263 |
llm_func(
|
| 264 |
+
prompt=msgs[-1]["content"],
|
| 265 |
+
system_prompt=msgs[0]["content"] if msgs[0]["role"] == "system" else None,
|
| 266 |
+
history_messages=msgs[1:-1],
|
| 267 |
+
# No max_tokens cap — let the model use its full context
|
| 268 |
)
|
| 269 |
)
|
| 270 |
# Extract answer
|
src/passage_entity/prompts.py
CHANGED
|
@@ -231,24 +231,26 @@ RAG_QA_SYSTEM = (
|
|
| 231 |
"additional elaborations."
|
| 232 |
)
|
| 233 |
|
|
|
|
|
|
|
| 234 |
_RAG_QA_ONE_SHOT_DOCS = (
|
| 235 |
"Wikipedia Title: The Last Horse\n"
|
| 236 |
-
"The Last Horse (Spanish:El último caballo) is a 1950 Spanish comedy film directed "
|
| 237 |
-
"by Edgar Neville starring Fernando Fernán Gómez.\n\n"
|
| 238 |
"Wikipedia Title: Southampton\n"
|
| 239 |
-
"The University of Southampton, which was founded in 1862 and received its Royal "
|
| 240 |
-
"
|
| 241 |
-
"in
|
| 242 |
-
"Universities 2010.\n\n"
|
| 243 |
"Wikipedia Title: Neville A. Stanton\n"
|
| 244 |
-
"Neville A. Stanton is a British Professor of Human Factors and Ergonomics at the "
|
| 245 |
-
"
|
| 246 |
-
"
|
| 247 |
)
|
| 248 |
|
| 249 |
RAG_QA_ONE_SHOT_INPUT = (
|
| 250 |
-
f"{_RAG_QA_ONE_SHOT_DOCS}
|
| 251 |
-
"
|
|
|
|
|
|
|
| 252 |
)
|
| 253 |
|
| 254 |
RAG_QA_ONE_SHOT_OUTPUT = (
|
|
|
|
| 231 |
"additional elaborations."
|
| 232 |
)
|
| 233 |
|
| 234 |
+
# One-shot demo — 5 passages (including 3 distractors) with full-length text.
|
| 235 |
+
# 5 passages (including 3 distractors), full-length text, \n separators.
|
| 236 |
_RAG_QA_ONE_SHOT_DOCS = (
|
| 237 |
"Wikipedia Title: The Last Horse\n"
|
| 238 |
+
"The Last Horse (Spanish:El último caballo) is a 1950 Spanish comedy film directed by Edgar Neville starring Fernando Fernán Gómez.\n"
|
|
|
|
| 239 |
"Wikipedia Title: Southampton\n"
|
| 240 |
+
"The University of Southampton, which was founded in 1862 and received its Royal Charter as a university in 1952, has over 22,000 students. The university is ranked in the top 100 research universities in the world in the Academic Ranking of World Universities 2010. In 2010, the THES - QS World University Rankings positioned the University of Southampton in the top 80 universities in the world. The university considers itself one of the top 5 research universities in the UK. The university has a global reputation for research into engineering sciences, oceanography, chemistry, cancer sciences, sound and vibration research, computer science and electronics, optoelectronics and textile conservation at the Textile Conservation Centre (which is due to close in October 2009.) It is also home to the National Oceanography Centre, Southampton (NOCS), the focus of Natural Environment Research Council-funded marine research.\n"
|
| 241 |
+
"Wikipedia Title: Stanton Township, Champaign County, Illinois\n"
|
| 242 |
+
"Stanton Township is a township in Champaign County, Illinois, USA. As of the 2010 census, its population was 505 and it contained 202 housing units.\n"
|
|
|
|
| 243 |
"Wikipedia Title: Neville A. Stanton\n"
|
| 244 |
+
"Neville A. Stanton is a British Professor of Human Factors and Ergonomics at the University of Southampton. Prof Stanton is a Chartered Engineer (C.Eng), Chartered Psychologist (C.Psychol) and Chartered Ergonomist (C.ErgHF). He has written and edited over a forty books and over three hundered peer-reviewed journal papers on applications of the subject. Stanton is a Fellow of the British Psychological Society, a Fellow of The Institute of Ergonomics and Human Factors and a member of the Institution of Engineering and Technology. He has been published in academic journals including \"Nature\". He has also helped organisations design new human-machine interfaces, such as the Adaptive Cruise Control system for Jaguar Cars.\n"
|
| 245 |
+
"Wikipedia Title: Finding Nemo\n"
|
| 246 |
+
"Finding Nemo Theatrical release poster Directed by Andrew Stanton Produced by Graham Walters Screenplay by Andrew Stanton Bob Peterson David Reynolds Story by Andrew Stanton Starring Albert Brooks Ellen DeGeneres Alexander Gould Willem Dafoe Music by Thomas Newman Cinematography Sharon Calahan Jeremy Lasky Edited by David Ian Salter Production company Walt Disney Pictures Pixar Animation Studios Distributed by Buena Vista Pictures Distribution Release date May 30, 2003 (2003 - 05 - 30) Running time 100 minutes Country United States Language English Budget $$94 million Box office $$940.3 million"
|
| 247 |
)
|
| 248 |
|
| 249 |
RAG_QA_ONE_SHOT_INPUT = (
|
| 250 |
+
f"{_RAG_QA_ONE_SHOT_DOCS}"
|
| 251 |
+
"\n\nQuestion: "
|
| 252 |
+
"When was Neville A. Stanton's employer founded?"
|
| 253 |
+
"\nThought: "
|
| 254 |
)
|
| 255 |
|
| 256 |
RAG_QA_ONE_SHOT_OUTPUT = (
|
src/passage_entity/reranker.py
CHANGED
|
@@ -117,24 +117,13 @@ class FactReranker:
|
|
| 117 |
|
| 118 |
# ------------------------------------------------------------------
|
| 119 |
def _call_llm(self, messages: List[Dict[str, str]]) -> str:
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
user_prompt = ""
|
| 123 |
-
for msg in messages:
|
| 124 |
-
if msg["role"] == "system":
|
| 125 |
-
system_prompt = msg["content"]
|
| 126 |
-
elif msg["role"] == "assistant":
|
| 127 |
-
history.append(msg)
|
| 128 |
-
elif msg["role"] == "user":
|
| 129 |
-
if user_prompt:
|
| 130 |
-
history.append({"role": "user", "content": user_prompt})
|
| 131 |
-
user_prompt = msg["content"]
|
| 132 |
-
|
| 133 |
return _run_sync(
|
| 134 |
self.llm_func(
|
| 135 |
-
prompt=
|
| 136 |
-
system_prompt=
|
| 137 |
-
history_messages=
|
| 138 |
max_tokens=512,
|
| 139 |
)
|
| 140 |
)
|
|
|
|
| 117 |
|
| 118 |
# ------------------------------------------------------------------
|
| 119 |
def _call_llm(self, messages: List[Dict[str, str]]) -> str:
|
| 120 |
+
# Pass messages directly to OpenAI — the old decompose/recompose
|
| 121 |
+
# loop scrambled demo order (assistant before user in each pair).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
return _run_sync(
|
| 123 |
self.llm_func(
|
| 124 |
+
prompt=messages[-1]["content"],
|
| 125 |
+
system_prompt=messages[0]["content"] if messages[0]["role"] == "system" else None,
|
| 126 |
+
history_messages=messages[1:-1],
|
| 127 |
max_tokens=512,
|
| 128 |
)
|
| 129 |
)
|