• Stars
    star
    323
  • Rank 125,759 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a gaggle of deep neural architectures for text ranking and question answering, designed for Pyserini

PyGaggle

PyPI LICENSE

PyGaggle provides a gaggle of deep neural architectures for text ranking and question answering. It was designed for tight integration with Pyserini, but can be easily adapted for other sources as well.

Currently, this repo contains implementations of the rerankers for MS MARCO Passage Retrieval, MS MARCO Document Retrieval, TREC-COVID and CovidQA.

Installation

  1. Clone the repo with git clone --recursive https://github.com/castorini/pygaggle.git

  2. Make you sure you have an installation of Python 3.8+. All python commands below refer to this.

  3. For pip, do pip install -r requirements.txt

    • If you prefer Anaconda, use conda env create -f environment.yml && conda activate pygaggle.

A Simple Reranking Example

Here's how to initalize the T5 reranker from Document Ranking with a Pretrained Sequence-to-Sequence Model:

from pygaggle.rerank.base import Query, Text
from pygaggle.rerank.transformer import MonoT5

reranker =  MonoT5()

Alternatively, here's the BERT reranker from Passage Re-ranking with BERT, which isn't as good as the T5 reranker:

from pygaggle.rerank.base import Query, Text
from pygaggle.rerank.transformer import MonoBERT

reranker =  MonoBERT()

Either way, continue with a complete reranking example:

# Here's our query:
query = Query('who proposed the geocentric theory')

# Option 1: fetch some passages to rerank from MS MARCO with Pyserini
from pyserini.search import LuceneSearcher
searcher = LuceneSearcher.from_prebuilt_index('msmarco-passage')
hits = searcher.search(query.text)

from pygaggle.rerank.base import hits_to_texts
texts = hits_to_texts(hits)

# Option 2: here's what Pyserini would have retrieved, hard-coded
passages = [['7744105', 'For Earth-centered it was  Geocentric Theory proposed by greeks under the guidance of Ptolemy and Sun-centered was Heliocentric theory proposed by Nicolas Copernicus in 16th century A.D. In short, Your Answers are: 1st blank - Geo-Centric Theory. 2nd blank - Heliocentric Theory.'], ['2593796', 'Copernicus proposed a heliocentric model of the solar system â\x80\x93 a model where everything orbited around the Sun. Today, with advancements in science and technology, the geocentric model seems preposterous.he geocentric model, also known as the Ptolemaic system, is a theory that was developed by philosophers in Ancient Greece and was named after the philosopher Claudius Ptolemy who lived circa 90 to 168 A.D. It was developed to explain how the planets, the Sun, and even the stars orbit around the Earth.'], ['6217200', 'The geocentric model, also known as the Ptolemaic system, is a theory that was developed by philosophers in Ancient Greece and was named after the philosopher Claudius Ptolemy who lived circa 90 to 168 A.D. It was developed to explain how the planets, the Sun, and even the stars orbit around the Earth.opernicus proposed a heliocentric model of the solar system â\x80\x93 a model where everything orbited around the Sun. Today, with advancements in science and technology, the geocentric model seems preposterous.'], ['3276925', 'Copernicus proposed a heliocentric model of the solar system â\x80\x93 a model where everything orbited around the Sun. Today, with advancements in science and technology, the geocentric model seems preposterous.Simple tools, such as the telescope â\x80\x93 which helped convince Galileo that the Earth was not the center of the universe â\x80\x93 can prove that ancient theory incorrect.ou might want to check out one article on the history of the geocentric model and one regarding the geocentric theory. Here are links to two other articles from Universe Today on what the center of the universe is and Galileo one of the advocates of the heliocentric model.'], ['6217208', 'Copernicus proposed a heliocentric model of the solar system â\x80\x93 a model where everything orbited around the Sun. Today, with advancements in science and technology, the geocentric model seems preposterous.Simple tools, such as the telescope â\x80\x93 which helped convince Galileo that the Earth was not the center of the universe â\x80\x93 can prove that ancient theory incorrect.opernicus proposed a heliocentric model of the solar system â\x80\x93 a model where everything orbited around the Sun. Today, with advancements in science and technology, the geocentric model seems preposterous.'], ['4280557', 'The geocentric model, also known as the Ptolemaic system, is a theory that was developed by philosophers in Ancient Greece and was named after the philosopher Claudius Ptolemy who lived circa 90 to 168 A.D. It was developed to explain how the planets, the Sun, and even the stars orbit around the Earth.imple tools, such as the telescope â\x80\x93 which helped convince Galileo that the Earth was not the center of the universe â\x80\x93 can prove that ancient theory incorrect. You might want to check out one article on the history of the geocentric model and one regarding the geocentric theory.'], ['264181', 'Nicolaus Copernicus (b. 1473â\x80\x93d. 1543) was the first modern author to propose a heliocentric theory of the universe. From the time that Ptolemy of Alexandria (c. 150 CE) constructed a mathematically competent version of geocentric astronomy to Copernicusâ\x80\x99s mature heliocentric version (1543), experts knew that the Ptolemaic system diverged from the geocentric concentric-sphere conception of Aristotle.'], ['4280558', 'A Geocentric theory is an astronomical theory which describes the universe as a Geocentric system, i.e., a system which puts the Earth in the center of the universe, and describes other objects from the point of view of the Earth. Geocentric theory is an astronomical theory which describes the universe as a Geocentric system, i.e., a system which puts the Earth in the center of the universe, and describes other objects from the point of view of the Earth.'], ['3276926', 'The geocentric model, also known as the Ptolemaic system, is a theory that was developed by philosophers in Ancient Greece and was named after the philosopher Claudius Ptolemy who lived circa 90 to 168 A.D. It was developed to explain how the planets, the Sun, and even the stars orbit around the Earth.ou might want to check out one article on the history of the geocentric model and one regarding the geocentric theory. Here are links to two other articles from Universe Today on what the center of the universe is and Galileo one of the advocates of the heliocentric model.'], ['5183032', "After 1,400 years, Copernicus was the first to propose a theory which differed from Ptolemy's geocentric system, according to which the earth is at rest in the center with the rest of the planets revolving around it."]]

texts = [ Text(p[1], {'docid': p[0]}, 0) for p in passages] # Note, pyserini scores don't matter since T5 will ignore them.

# Either option, let's print out the passages prior to reranking:
for i in range(0, 10):
    print(f'{i+1:2} {texts[i].metadata["docid"]:15} {texts[i].score:.5f} {texts[i].text}')

# Finally, rerank:
reranked = reranker.rerank(query, texts)

# Print out reranked results:
for i in range(0, 10):
    print(f'{i+1:2} {reranked[i].metadata["docid"]:15} {reranked[i].score:.5f} {reranked[i].text}')

Reranking with a different checkpoint

There are many checkpoints for monoBERT and monoT5 in our Hugging Face model page: https://huggingface.co/castorini

The MonoT5() class uses castorini/monot5-base-msmarco by default. In the example below, we show how to use a different checkpoint (i.e., castorini/monot5-base-msmarco-10k):

from transformers import T5ForConditionalGeneration
model = T5ForConditionalGeneration.from_pretrained('castorini/monot5-base-msmarco-10k')
reranker = MonoT5(model=model)

Experiments on IR collections

The following documents describe how to use PyGaggle on various IR test collections:

Experiments on QA collections

The following documents describe how to use PyGaggle for QA:

More Repositories

1

pyserini

Pyserini is a Python toolkit for reproducible information retrieval research with sparse and dense representations.
Python
1,477
star
2

anserini

Anserini is a Lucene toolkit for reproducible information retrieval research
Java
982
star
3

daam

Diffusion attentive attribution maps for interpreting Stable Diffusion.
Jupyter Notebook
607
star
4

hedwig

PyTorch deep learning models for document classification
Python
586
star
5

honk

PyTorch implementations of neural network models for keyword spotting
Python
504
star
6

docTTTTTquery

docTTTTTquery document expansion model
Python
344
star
7

BuboQA

Simple question answering over knowledge graphs (Mohammed et al., NAACL 2018)
Python
280
star
8

rank_llm

Repository for prompt-decoding using LLMs (GPT3.5, GPT4, Vicuna, and Zephyr)
Python
247
star
9

howl

Wake word detection modeling toolkit for Firefox Voice, supporting open datasets like Speech Commands and Common Voice.
Python
191
star
10

castor

PyTorch deep learning models for text processing
Python
180
star
11

DeeBERT

DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference
Python
150
star
12

birch

Document ranking via sentence modeling using BERT
Python
142
star
13

covidex

A multi-stage neural search engine for the COVID-19 Open Research Dataset
TypeScript
136
star
14

duobert

Multi-stage passage ranking: monoBERT + duoBERT
Python
109
star
15

MP-CNN-Torch

Multi-Perspective Convolutional Neural Networks for modeling textual similarity (He et al., EMNLP 2015)
Lua
107
star
16

anserini-notebooks

Anserini notebooks
Jupyter Notebook
69
star
17

mr.tydi

Mr. TyDi is a multi-lingual benchmark dataset built on TyDi, covering eleven typologically diverse languages.
Python
68
star
18

honkling

Web app for keyword spotting using TensorflowJS
JavaScript
67
star
19

afriberta

AfriBERTa: Exploring the Viability of Pretrained Multilingual Language Models for Low-resourced Languages
Python
60
star
20

data

Castorini data
Python
59
star
21

dhr

Dense hybrid representations for text retrieval
Python
55
star
22

NCE-CNN-Torch

Noise-Contrastive Estimation for Question Answering with Convolutional Neural Networks (Rao et al. CIKM 2016)
Lua
54
star
23

chatty-goose

A Python framework for conversational search
Python
38
star
24

transformers-arithmetic

Python
38
star
25

d-bert

Distilling BERT using natural language generation.
Python
35
star
26

hf-spacerini

Plug-and-play Search Interfaces with Pyserini and Hugging Face
Python
30
star
27

SimpleDBpediaQA

simple QA over knowledge graphs on DBpedia
Python
25
star
28

bertserini

BERTserini
Python
24
star
29

berxit

Python
21
star
30

anserini-tools

Evaluation tools shared across anserini, pyserini, and pygaggle
Python
21
star
31

onboarding

Onboarding guide to Jimmy Lin's research group at the University of Waterloo
21
star
32

VDPWI-NN-Torch

Very Deep Pairwise Word Interaction Neural Networks for modeling textual similarity (He and Lin, NAACL/HLT 2016)
Lua
19
star
33

TREC-COVID

TREC-COVID results - this is a mirror of data on the TREC website in a more convenient format.
Roff
14
star
34

perm-sc

Official codebase for permutation self-consistency.
Python
14
star
35

LiT5

Python
13
star
36

honk-models

Pre-trained models for Honk
11
star
37

howl-deploy

JavaScript deployment for Howl, the wake word detection modeling toolkit for Firefox Voice
JavaScript
10
star
38

TrecQA-NegEx

Code and dataset for SIGIR 2017 short paper "Automatically Extracting High-Quality Negative Examples for Answer Selection in Question Answering"
Python
10
star
39

Tweets2013-IA

The Tweets2013 Internet Archive collection
Scala
10
star
40

AfriTeVa-keji

Python
10
star
41

meanmax

MeanMax estimators.
Python
9
star
42

cqe

Python
9
star
43

SM-CNN-Torch

Torch implementation of Severyn and Moschitti's SIGIR 2015 CNN model for question answering
Lua
9
star
44

ONNX-demo

Python
8
star
45

anserini-notebooks-afirm2020

Colab notebooks for AFIRM '20
Jupyter Notebook
7
star
46

serverless-bert-reranking

Python
7
star
47

parrot

Keyword spotting using audio from speech synthesis services and YouTube
Python
7
star
48

earlyexiting-monobert

Python
7
star
49

afriteva

Text - 2 - Text for African languages
Python
6
star
50

tct_colbert

Python
5
star
51

transformers-selective

Python
5
star
52

serverless-inference

Neural network inference on serverless architecture
Python
5
star
53

norbert

NorBERT: Anserini + dl4marco-bert
Python
4
star
54

rank_llm_data

3
star
55

touche-error-analysis

Old is Gold? Systematic Error Analysis of Neural Retrieval Models against BM25 for Argument Retrieval
Python
3
star
56

numbert

Passage Ranking Library using various pretrained LMs
Python
3
star
57

anserini-spark

Anserini-Spark integration
Java
3
star
58

kim-cnn-vis

An in-browser visualization of Kim CNN
JavaScript
3
star
59

replicate-lce

Python
3
star
60

kws-gen-data

Data for KWS generator.
2
star
61

pyserini-data

Python
2
star
62

candle

PyTorch utilities for parameter pruning and multiplies reduction
Python
2
star
63

BuboQA-models

2
star
64

gooselight2

Search frontend for Anserini
Ruby
2
star
65

africlirmatrix

AfriCLIRMatrix is a test collection for cross-lingual information retrieval research in 15 diverse African languages.
2
star
66

biasprobe

Python
2
star
67

sigtestv

SIGnificance TESTing Violations: an end-to-end toolkit for evaluating neural networks.
Python
1
star
68

howl-models

1
star
69

SolrAnserini

Anserini integration with Solr
Python
1
star
70

gooselight

🦆 Anserini + Blacklight 🦆
Ruby
1
star
71

BuboQA-data

Hosting dataset for BuboQA
1
star
72

anlessini

Java
1
star
73

honkling-models

JavaScript
1
star