framolfese
commited on
Commit
โข
4291eca
1
Parent(s):
1297d29
Create readme
Browse files
README.md
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
base_model:
|
6 |
+
- intfloat/e5-base-v2
|
7 |
+
tags:
|
8 |
+
- retrieval
|
9 |
+
- question answering
|
10 |
+
---
|
11 |
+
|
12 |
+
<div align="center">
|
13 |
+
<img src="https://github.com/SapienzaNLP/zebra/assets/zebra.png?raw=true" height="150">
|
14 |
+
</div>
|
15 |
+
|
16 |
+
<div align="center">
|
17 |
+
<h1>ZEBRA: Zero-Shot Example-Based Retrieval Augmentation for Commonsense Question Answering</h1>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
<div style="display:flex; justify-content: center; align-items: center; flex-direction: row;">
|
21 |
+
<a href="https://2024.emnlp.org/"><img src="https://img.shields.io/badge/EMNLP-2024-4b44ce"></a>
|
22 |
+
<a href="https://arxiv.org/abs/placeholder"><img src="https://img.shields.io/badge/arXiv-placeholder-b31b1b.svg"></a>
|
23 |
+
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><img src="https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg"></a>
|
24 |
+
<a href="https://huggingface.co/collections/sapienzanlp/zebra-66e3ec50c8ce415ea7572d0e"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Collection-FCD21D"></a>
|
25 |
+
<a href="https://github.com/SapienzaNLP/zebra"><img src="https://img.shields.io/badge/GitHub-Repo-121013?logo=github&logoColor=white"></a>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
A retrieval augmentation framework for zero-shot commonsense question answering with LLMs.
|
29 |
+
|
30 |
+
## ๐ ๏ธ Installation
|
31 |
+
|
32 |
+
Installation from PyPi
|
33 |
+
|
34 |
+
```bash
|
35 |
+
pip install zebra
|
36 |
+
```
|
37 |
+
|
38 |
+
Installation from source
|
39 |
+
|
40 |
+
```bash
|
41 |
+
git clone https://github.com/framolfese/zebra.git
|
42 |
+
cd zebra
|
43 |
+
conda create -n zebra python==3.10
|
44 |
+
conda activate zebra
|
45 |
+
pip install -e .
|
46 |
+
```
|
47 |
+
|
48 |
+
## ๐ Quick Start
|
49 |
+
|
50 |
+
ZEBRA is a plug-and-play retrieval augmentation framework for **Commonsense Question Answering**. \
|
51 |
+
It is composed of two pipeline stages: *knowledge generation* and *informed reasoning*. \
|
52 |
+
The knowledge generation step is responsible for:
|
53 |
+
- given a question, retrieving relevant examples of question-knowledge pairs from a large collection
|
54 |
+
- prompting a LLM to generate useful explanations for the given input question by leveraging the relationships between the retrieved question-knowledge pairs.
|
55 |
+
|
56 |
+
The informed reasoning step is responsible for prompting a LLM for the question answering task by taking advantage of the previously generated explanations.
|
57 |
+
|
58 |
+
Here is an example of how to use ZEBRA for question answering:
|
59 |
+
|
60 |
+
```python
|
61 |
+
from zebra import Zebra
|
62 |
+
|
63 |
+
# Load Zebra with language model, retriever, document index and explanations.
|
64 |
+
zebra = Zebra(
|
65 |
+
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
66 |
+
retriever="sapienzanlp/zebra-retriever-e5-base-v2",
|
67 |
+
document_index="sapienzanlp/zebra-kb"
|
68 |
+
)
|
69 |
+
|
70 |
+
# Provide a question and answer choices.
|
71 |
+
questions = [
|
72 |
+
"What should you do if you see someone hurt and in need of help?",
|
73 |
+
"If your friend is upset, what is the best way to support them?",
|
74 |
+
"What should you do if your phone battery is running low in a public place?",
|
75 |
+
"What should you do if you are running late for an important meeting?",
|
76 |
+
]
|
77 |
+
|
78 |
+
choices = [
|
79 |
+
["Walk away.", "Call for help.", "Take a photo for social media."],
|
80 |
+
["Listen to them and offer comfort.", "Tell them they are overreacting.", "Ignore them and walk away."],
|
81 |
+
["Borrow a stranger's phone.", "Use public charging station.", "Leave your phone unattended while it charges."],
|
82 |
+
["Rush through traffic.", "Call and inform them you will be late.", "Do not show up at all."],
|
83 |
+
]
|
84 |
+
|
85 |
+
# Generate knowledge and perform question answering.
|
86 |
+
zebra_output = zebra.pipeline(questions=questions, choices=choices)
|
87 |
+
```
|
88 |
+
|
89 |
+
The output contains, for each question, a list of generated explanations and the predicted answer:
|
90 |
+
|
91 |
+
```bash
|
92 |
+
ZebraOutput(
|
93 |
+
explanations=[
|
94 |
+
[
|
95 |
+
"Walking away would be neglecting the person's need for help and potentially putting them in danger.",
|
96 |
+
'Calling for help, such as 911, is the most effective way to get the person the assistance they need.',
|
97 |
+
"Taking a photo for social media might spread awareness, but it's not a direct way to help the person in need."
|
98 |
+
],
|
99 |
+
[
|
100 |
+
'Listening and offering comfort shows empathy and understanding.',
|
101 |
+
"Telling someone they're overreacting can be dismissive and unhelpful.",
|
102 |
+
'Ignoring someone in distress can be hurtful and unkind.'
|
103 |
+
],
|
104 |
+
[
|
105 |
+
"Borrow a stranger's phone: Unwise, as it's a security risk and may lead to theft or damage.",
|
106 |
+
"Use public charging station: Safe and convenient, as it's a designated charging area.",
|
107 |
+
'Leave your phone unattended while it charges: Not recommended, as it may be stolen or damaged.'
|
108 |
+
],
|
109 |
+
[
|
110 |
+
'Rush through traffic: This option is risky and may lead to accidents or stress.',
|
111 |
+
'Call and inform them you will be late: This is the most likely option, as it shows respect for the meeting and allows for adjustments.',
|
112 |
+
'Do not show up at all: This is unacceptable, as it shows disrespect for the meeting and may damage relationships.'
|
113 |
+
],
|
114 |
+
],
|
115 |
+
answers=[
|
116 |
+
"Call for help.",
|
117 |
+
"Listen to them and offer comfort.",
|
118 |
+
"Use public charging station.",
|
119 |
+
"Call and inform them you will be late."
|
120 |
+
],
|
121 |
+
)
|
122 |
+
```
|
123 |
+
|
124 |
+
You can also call the `zebra.pipeline` method with the `return_dict` parameter set to `True` to ask ZEBRA to return also the retrieved examples along with their explanations.
|
125 |
+
|
126 |
+
## Models and Data
|
127 |
+
|
128 |
+
Models and data can be found at the following [HuggingFace Collection ๐ค](https://huggingface.co/collections/sapienzanlp/zebra-66e3ec50c8ce415ea7572d0e).
|
129 |
+
|
130 |
+
## ๐ Performance
|
131 |
+
|
132 |
+
We evaluate the performance of ZEBRA on 8 well-established commonsense question answering datasets. The following table shows the results (accuracy) of the models before / after the application of ZEBRA.
|
133 |
+
|
134 |
+
| Model | CSQA | ARC-C | ARC-E | OBQA | PIQA | QASC | CSQA2 | WG | AVG |
|
135 |
+
| ------------------------ | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- |
|
136 |
+
| Mistral-7B-Instruct-v0.2 | 68.2 / **73.3** | 72.4 / **75.2** | 85.8 / **87.4** | 68.8 / **75.8** | 76.1 / **80.2** | 66.1 / **68.3** | 58.5 / **67.5** | 55.8 / **60.7** | 68.9 / **73.5** |
|
137 |
+
| Phi3-small-8k-Instruct | 77.2 / **80.9** | 90.4 / **91.6** | 96.9 / **97.7** | 90.4 / **91.2** | 86.6 / **88.1** | **83.5** / 81.0 | 68.0 / **74.6** | 79.1 / **81.0** | 84.0 / **85.8** |
|
138 |
+
| Meta-Llama-3-8b-Instruct | 73.9 / **78.7** | 79.4 / **83.5** | 91.7 / **92.9** | 73.4 / **79.6** | 78.3 / **84.0** | 78.2 / **79.1** | 64.3 / **69.4** | 56.2 / **63.2** | 74.4 / **78.8** |
|
139 |
+
| Phi3-mini-128k-Instruct | 73.4 / **74.8** | 85.7 / **88.0** | 95.4 / **96.0** | 82.8 / **87.8** | 80.4 / **84.2** | **74.7** / 73.9 | 59.3 / **64.6** | 67.3 / **72.9** | 77.4 / **80.5** |
|
140 |
+
|
141 |
+
You can also download the official paper results at the following [Google Drive Link](https://drive.google.com/file/d/1l7bY-TkqnmVQn5M5ynQfT-0upMcRlMnT/view?usp=drive_link).
|
142 |
+
|
143 |
+
## Cite this work
|
144 |
+
|
145 |
+
If you use any part of this work, please consider citing the paper as follows:
|
146 |
+
|
147 |
+
```bibtex
|
148 |
+
@inproceedings{molfese-etal-2024-zebra,
|
149 |
+
title = "ZEBRA: Zero-Shot Example-Based Retrieval Augmentation for Commonsense Question Answering",
|
150 |
+
author = "Molfese, Francesco Maria and
|
151 |
+
Conia, Simone and
|
152 |
+
Orlando, Riccardo and
|
153 |
+
Navigli, Roberto",
|
154 |
+
editor = "",
|
155 |
+
booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing",
|
156 |
+
month = nov,
|
157 |
+
year = "2024",
|
158 |
+
address = "Miami",
|
159 |
+
publisher = "Association for Computational Linguistics",
|
160 |
+
url = "",
|
161 |
+
doi = "",
|
162 |
+
pages = "",
|
163 |
+
abstract = "",
|
164 |
+
}
|
165 |
+
```
|
166 |
+
|
167 |
+
## ๐ชช License
|
168 |
+
|
169 |
+
The data and software are licensed under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/).
|
170 |
+
|
171 |
+
## Acknowledgements
|
172 |
+
[Future AI Research](https://future-ai-research.it/) and CREATIVE (CRoss-modalunderstanding and gEnerATIon of Visual and tExtual content) for supporting this work.
|