Skip to content

samrawal/semantic-passage-reranking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

🧱 passage-reranking-transformers

Off-the-shelf sentence/passage ranking via Transformers.

  • Inputs: Query and list of sentences/paragraphs.
  • Outputs: List of ranked sentences/paragraphs, in order of predicted relevance to query.

Several finetuned Passage Reranking models (trained on MSMARCO dataset) are available online:

Much of the code adapted from the HuggingFace Transformers repo.

Quickstart

Download rerank.py.

from rerank import Rerank

query = "How do plants make food?"
sentences = [
    "All living things need food and energy to survive",
    "Plants make food and produce oxygen through photosynthesis",
    "The foodmaking and energy process for plants to survive is called photosynthesis",
    "The process is complex but with the sun, water, nutrients from the soil, oxygen, and chlorophyll, a plant makes its own food in order to survive",
    "Chlorophyll is a green chemical inside a plant that allows plants to use the Sun's energy to make food",
]


model_path = "nboost/pt-tinybert-msmarco"
rerank = Rerank(model_path)
results = rerank.rerank(query, sentences, topn=3)

Requirements

  • torch
  • numpy
  • transformers
  • tqdm

About

Off-the-shelf sentence/passage ranking via Transformers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages