samrawal / semantic-passage-reranking

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧱 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.


Languages

Language:Python 100.0%