Sentence Similarity
PyTorch
English
mistral
custom_code
Justus-Jonas commited on
Commit
e3c1b9a
·
verified ·
1 Parent(s): 1a96c5d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +198 -0
README.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - dgslibisey/MuSiQue
5
+ - hotpotqa/hotpot_qa
6
+ - xanhho/2WikiMultihopQA
7
+ - hover-nlp/hover
8
+ language:
9
+ - en
10
+ base_model:
11
+ - GritLM/GritLM-7B
12
+ - mistralai/Mistral-7B-v0.1
13
+ pipeline_tag: sentence-similarity
14
+ ---
15
+ <p align="center">
16
+ <img src="static/GritHopperLogo.jpeg" alt="GritHopper Logo" height="250px" align="left" style="position: relative; z-index: 1;">
17
+ <div align="center">
18
+ <h1>
19
+ <h1>GritHopper: Decomposition-Free<br>
20
+ Multi-Hop Dense Retrieval</h1>
21
+ </h1>
22
+ <p align="center">
23
+ 🏗️ <a href="https://github.com/UKPLab/GritHopper" target="_blank">GitHub Repo</a> | 📃 <a href="TBD" target="_blank">Paper</a>
24
+ </p>
25
+ </div>
26
+ </p>
27
+
28
+ <br clear="left"/>
29
+
30
+ <!--- BADGES: START, copied from sentence transformers, will be replaced with the actual once (removed for anonymity)--->
31
+
32
+ ---
33
+
34
+ GritHopper is the first **decoder-based** multi-hop dense retrieval model and achieves **state-of-the-art performance** on both **in-distribution and out-of-distribution** benchmarks for **decomposition-free multi-hop dense retrieval**. Built on [GRITLM](https://github.com/ContextualAI/gritlm), it is trained across diverse datasets spanning **question-answering** and **fact-checking**. Unlike traditional decomposition-based approaches, GritHopper iteratively retrieves passages without explicit sub-question decomposition, concatenating retrieved evidence with the query at each step.
35
+
36
+ Using the decoder model in an encoder-only approach (like [MDR](https://github.com/facebookresearch/multihop_dense_retrieval)), it performs each retrieval step in a single forward pass. In contrast to previous SOTA BERT-based approaches (like [BeamRetriever](https://github.com/canghongjian/beam_retriever) or [MDR](https://github.com/facebookresearch/multihop_dense_retrieval)), GritHopper generalizes significantly better to **out-of-distribution** data.
37
+
38
+ ## Key Strengths of GritHopper
39
+ - **Encoder-Only Efficiency**: Each retrieval iteration requires only a single forward pass (rather than multiple autoregressive steps).
40
+ - **Out-of-Distribution Robustness**: Achieves **state-of-the-art** performance compared to other decomposition-free methods on multiple OOD benchmarks.
41
+ - **Unified Training**: Combines dense retrieval with generative objectives, exploring how post-retrieval information on the generation loss improves dense retrieval performance.
42
+ - **Stopping**: GritHopper utilizes its generative capabilities via ReAct to control its own state. This way, it can stop itself through causal next-token prediction.
43
+
44
+ ---
45
+
46
+ ## Staring with GritHopper
47
+ GritHopper is trained on [MuSiQue](https://aclanthology.org/2022.tacl-1.31/), [2WikiMultiHopQA](https://aclanthology.org/2020.coling-main.580.pdf), [HotPotQA](https://aclanthology.org/D18-1259.pdf), [EX-Fever](https://aclanthology.org/2024.findings-acl.556/) and [HoVer](https://aclanthology.org/2020.findings-emnlp.309/).
48
+
49
+ ### GritHopper Models
50
+ | Model Name | Datasets | Description | Model Size |
51
+ |-------------------------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --- |
52
+ | GritHopper-7B | All Datasets | GritHopper trained on Answers as Post-Retrieval information (SOTA) | 7B |
53
+ ### 1. Installation
54
+
55
+ ```bash
56
+ pip install grithopper
57
+ ```
58
+ ### 2. Initialization
59
+ ```python
60
+ from grithopper import GritHopper
61
+
62
+ # Initialize GritHopper with your GRITLM model checkpoint or huggingface path
63
+ hopper = GritHopper(
64
+ model_name_or_path="GritHopper-7B",
65
+ device="cuda" # or "cpu"
66
+ )
67
+ ```
68
+
69
+ ### 3. Load Document Candidates
70
+
71
+ You can either load from a list of (title, passage) pairs and optionally dump them to a file:
72
+ ```python
73
+ documents = [
74
+ ("Title A", "Passage text for document A."),
75
+ ("Title B", "Passage text for document B."),
76
+ # ...
77
+ ]
78
+
79
+ hopper.load_document_candidates(
80
+ document_candidates=documents,
81
+ device="cuda",
82
+ output_directory_candidates_dump="my_candidates.pkl" # optional
83
+ )
84
+ ```
85
+
86
+ Or load them from a pre-encoded dump:
87
+ ```python
88
+ hopper.load_candidates_from_file(
89
+ dump_filepath="my_candidates.pkl",
90
+ device="cuda"
91
+ )
92
+ ```
93
+ ### 4. Encode a Query
94
+
95
+ ```python
96
+ question = "Who wrote the novel that was adapted into the film Blade Runner?"
97
+ previous_evidences = [("Blade Runner (Movie)", " The Movie....")] # optional
98
+
99
+
100
+ query_vector = hopper.encode_query(
101
+ multi_hop_question=question,
102
+ previous_evidences=previous_evidences, # optional
103
+ instruction_type="multi-hop" # or "fact-check" alternatively you can provide a custom instruction with insruction="your_instruction"
104
+ )
105
+ ```
106
+ ### 5. Single-Step Retrieval
107
+ ```python
108
+ result = hopper.retrieve_(
109
+ query=query_vector,
110
+ top_k=1,
111
+ get_stopping_probability=True
112
+ )
113
+
114
+ # {
115
+ # "retrieved": [
116
+ # {
117
+ # "title": "Title B",
118
+ # "passage": "Passage text for document B.",
119
+ # "score": 0.873
120
+ # }
121
+ # ],
122
+ # "continue_probability": 0.65, # present if get_stopping_probability=True
123
+ # "stop_probability": 0.35
124
+ # }
125
+ ```
126
+ If you prefer to pass the question string directly:
127
+
128
+ ```python
129
+ result = hopper.retrieve_(
130
+ query="Who is the mother of the writer who wrote the novel that was adapted into the film Blade Runner?",
131
+ # optional previous_evidences=[("Blade Runner (Movie)", " The Movie....")],
132
+ top_k=1,
133
+ get_stopping_probability=True,
134
+ )
135
+
136
+ # {
137
+ # "retrieved": [
138
+ # { "title": "Blade Runner (Movie)", "passage": "...", "score": 0.92 }
139
+ # ],
140
+ # "continue_probability": 0.75,
141
+ # "stop_probability": 0.25
142
+ # }
143
+ ```
144
+ ### 6. Iterative (Multi-Hop) Retrieval
145
+ ```python
146
+ chain_of_retrieval = hopper.iterative_retrieve(
147
+ multi_hop_question="Who wrote the novel that was adapted into the film Blade Runner?",
148
+ instruction_type="multi-hop",
149
+ automatic_stopping=True,
150
+ max_hops=4
151
+ )
152
+
153
+ # [
154
+ # {
155
+ # "retrieved": [
156
+ # { "title": "Blade Runner (Movie)", "passage": "...", "score": 0.92 }
157
+ # ],
158
+ # "continue_probability": 0.75,
159
+ # "stop_probability": 0.25
160
+ # },
161
+ # {
162
+ # "retrieved": [
163
+ # { "title": "Philip K.", "passage": "...", "score": 0.88 }
164
+ # ],
165
+ # "continue_probability": 0.65,
166
+ # "stop_probability": 0.35
167
+ # },
168
+ # ...
169
+ # ]
170
+ ```
171
+ This process continues until either:
172
+
173
+ 1. The model determines it should stop (if automatic_stopping=True and stop_probability > continue_probability).
174
+ 2. It hits max_hops.
175
+ 3. Or no documents can be retrieved at a given step.
176
+
177
+ ---
178
+ ## Citation
179
+ If you use GritHopper in your research, please cite the following paper:
180
+ ```
181
+ TBD
182
+ ```
183
+ ## Contact
184
+ Contact person: Justus-Jonas Erker, justus-jonas.erker@tu-darmstadt.de
185
+
186
+ https://www.ukp.tu-darmstadt.de/
187
+
188
+ https://www.tu-darmstadt.de/
189
+
190
+ Don't hesitate to send us an e-mail or report an issue, if something is broken (and it shouldn't be) or if you have further questions.
191
+ This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.
192
+
193
+ ## License
194
+ GritHopper is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
195
+
196
+
197
+ ### Acknowledgement
198
+ this Model is based upon the [GRITLM](https://github.com/ContextualAI/gritlm).