Repository navigation
methods: add HyDE - #49
Open
aminbigdeli wants to merge 1 commit into
Open
aminbigdeli wants to merge 1 commit into
aminbigdeli wants to merge 1 commit into
Conversation
Add HyDE ("Precise Zero-Shot Dense Retrieval without Relevance Labels",
Gao et al., 2022) as a text reformulation method: the LLM generates 8
hypothetical documents with a task-specific prompt, and the reformulated
query is the original query followed by the documents. This works with any
retriever (BM25, SPLADE++, dense) instead of averaging embeddings.
- Port the 7 task prompts from the original implementation (web search,
scifact, arguana, trec-covid, fiqa, dbpedia-entity, trec-news), selected
with the `task` param; an unknown task raises ValueError
- task_for_dataset() maps BEIR datasets to their prompt and everything else
to web search; the example pipeline uses it when `task` isn't set
- Paper sampling defaults (temperature 0.7, max_tokens 512, top_p 1.0,
stop "\n\n\n") in defaults.yaml and the pipeline config
- `querygym run --output-format plain` writes one column per document
- Tests, docs, changelog, README and site method list
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds HyDE from Precise Zero-Shot Dense Retrieval without Relevance Labels (Gao et al., 2022) as a new reformulation method (
"hyde").The original HyDE averages the embeddings of the query and 8 LLM-generated hypothetical documents. Like every other QueryGym method, this version emits text instead: the reformulated query is the original query followed by the 8 generated documents (
query + doc_1 + … + doc_8). That way it works with any retriever (BM25, SPLADE++, BGE). The query appears once, matching its 1-in-9 weight in the original embedding average.Type of Change
Related Issues
None.
Changes Made
querygym/methods/hyde.py):HyDEmakesn_docs(default 8) LLM calls per query, then concatenates the query and the documents. Empty generations are dropped; if all are empty, the original query is returned. Metadata:task,n_docs,hypothetical_docs.prompt_bank.yaml): the 7 task prompts copied verbatim from the original implementation:web search,scifact,arguana,trec-covid,fiqa,dbpedia-entity,trec-news. Thetaskparam selects one (defaultweb search). An unknown or misspelled task raisesValueErrorinstead of silently falling back. The Mr. TyDi (multilingual) prompt is not included.task_for_dataset()maps the 6 BEIR datasets to their own prompt. Everything else usesweb search: MS MARCO, DL-HARD, BRIGHT, custom query files and unknown dataset names. The example pipeline (reformulate_queries.py) applies it whentaskisn't set; an explicittaskalways wins. The chosen task is recorded inmethod_params, so it's part ofparams_hash.temperature 0.7,max_tokens 512,top_p 1.0,stop ["\n\n\n"]) inquerygym/config/defaults.yamlandexamples/querygym_pyserini/reformulation_config.yaml.querygym run --method hyde --output-format plainwrites one column per document.methods/__init__.py,core/runner.py, and thequerygympackage exports.web/site/src/data/methods.json(marketing site; also supplies the leaderboard's paper link).Testing
pytest): 137 passed, including 35 new tests intests/test_methods_hyde.pyThe new tests use a fake LLM and cover:
n_docsandrepeat_query_weightparamsI also ran the example pipeline with the LLM and searcher stubbed out:
beir-v1.0.0-scifactscifactbright-biologyweb search.tsvweb searchtask: fiqafiqa(overrides the mapping)Not yet tested against a real LLM endpoint.
Checklist
blackandruffclean on the new files)Additional Notes
repeat_query_weightcan raise the query's weight. BGE truncates at 512 tokens, so it effectively sees the query plus about the first document.create_reformulatordefaults:qg.create_reformulator("hyde")withoutllm_configgets the factory'stemperature=0.8andmax_tokens=256, as every method does. The docs say to pass the paper settings explicitly.querygym runand the example pipeline already use them.license: "CC-BY-4.0"like the rest of the prompt bank. The original HyDE repo doesn't include a license file.