Overview
An API that takes a podcast title and transcript and returns the five sentences most relevant to the title. It pairs lexical ranking with a semantic re-ranker, following the approach Spotify described for podcast segment retrieval at TREC 2020.
Architecture
Stage 1: BM25 lexical ranking. An implementation of Okapi BM25 written from scratch, with no retrieval library. Each transcript sentence is scored against the title using term frequency, inverse document frequency, and length normalization. The top 10 move on to stage 2.
Stage 2: DistilBERT semantic re-ranking. The msmarco-distilbert-base-tas-b model encodes the title and the candidate sentences as dense vectors, and the candidates are re-ordered by cosine similarity. This catches sentences that mean the same thing as the title without sharing its words.
Tech Stack
- API Framework: FastAPI and Uvicorn
- Lexical Ranking: Custom BM25 implementation
- Semantic Re-ranking: MSMARCO DistilBERT (sentence-transformers)
- Tokenization: NLTK
- Containerization: Docker
References
- Spotify Podcast Segment Retrieval, TREC 2020