llama-index packs infer retrieve rerank integration
Project description
Infer-Retrieve-Rerank LlamaPack
This is our implementation of the paper "In-Context Learning for Extreme Multi-Label Classification by Oosterlinck et al.
The paper proposes "infer-retrieve-rerank", a simple paradigm using frozen LLM/retriever models that can do "extreme"-label classification (the label space is huge).
- Given a user query, use an LLM to predict an initial set of labels.
- For each prediction, retrieve the actual label from the corpus.
- Given the final set of labels, rerank them using an LLM.
All of these can be implemented as LlamaIndex abstractions.
A full notebook guide can be found here.
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack InferRetrieveRerankPack --download-dir ./infer_retrieve_rerank_pack
You can then inspect the files at ./infer_retrieve_rerank_pack
and use them as a template for your own project!
Code Usage
You can download the pack to a ./infer_retrieve_rerank_pack
directory:
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
InferRetrieveRerankPack = download_llama_pack(
"InferRetrieveRerankPack", "./infer_retrieve_rerank_pack"
)
From here, you can use the pack, or inspect and modify the pack in ./infer_retrieve_rerank_pack
.
Then, you can set up the pack like so:
# create the pack
pack = InferRetrieveRerankPack(
labels, # list of all label strings
llm=llm,
pred_context="<pred_context>",
reranker_top_n=3,
verbose=True,
)
The run()
function runs predictions.
pred_reactions = pack.run(inputs=[s["text"] for s in samples])
You can also use modules individually.
# call the llm.complete()
llm = pack.llm
label_retriever = pack.label_retriever
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file llama_index_packs_infer_retrieve_rerank-0.5.0.tar.gz
.
File metadata
- Download URL: llama_index_packs_infer_retrieve_rerank-0.5.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb503bd375a3b9868933599d2c814b8a3d8513487c94aa7728f7d7c50bef02e4 |
|
MD5 | ffaa13fc0feff6ed9d064340622f9674 |
|
BLAKE2b-256 | c93d3fccb50a51c9d76d8abd023b2faf61e016c4a81386108ca5b4012c95fca5 |
File details
Details for the file llama_index_packs_infer_retrieve_rerank-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_packs_infer_retrieve_rerank-0.5.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e2f88861dec47727fc4c371962939b9fc6cdef4a8a45353fd6bcfa2c4473c29 |
|
MD5 | 951974b782460284846446893ce651f6 |
|
BLAKE2b-256 | b8c165779017fb54118f51977f06246ca90ae73f006c58199381583b96f2f15a |