Last active
March 23, 2026 10:42
-
-
Save ZiTAL/c89a6993e8818c70e16b6624016a8200 to your computer and use it in GitHub Desktop.
python: reranking local model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| podman build -t local-reranker . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use Python 3.11 base image | |
| FROM python:3.11-slim | |
| # Set a working directory inside the container | |
| WORKDIR /app | |
| # Copy your project files | |
| COPY . /app | |
| # Install system dependencies (optional, needed for PyTorch) | |
| RUN apt-get update && apt-get install -y git wget build-essential && rm -rf /var/lib/apt/lists/* | |
| # Install Python dependencies | |
| RUN pip install --upgrade pip | |
| RUN pip install torch sentence-transformers transformers==4.50.2 | |
| # Expose port if you plan to run a local API | |
| EXPOSE 8000 | |
| # Command to run your script | |
| CMD ["python", "index.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sentence_transformers import CrossEncoder | |
| model = CrossEncoder( | |
| # "BAAI/bge-reranker-base", | |
| "mixedbread-ai/mxbai-rerank-large-v1", | |
| device="cpu" # or "cpu" | |
| ) | |
| query = "What is the capital of France?" | |
| docs = ["Paris is the capital of France.", | |
| "Berlin is the capital of Germany.", | |
| "Madrid is in Spain."] | |
| pairs = [(query, doc) for doc in docs] | |
| scores = model.predict(pairs) | |
| ranked = sorted(zip(docs, scores), key=lambda x: x[1], reverse=True) | |
| for doc, score in ranked: | |
| print(score, doc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| mkdir -p cache | |
| podman run --rm -it \ | |
| -v ./cache:/root/.cache/huggingface \ | |
| -v $(pwd):/app \ | |
| local-reranker python index.py |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result: