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
Hashes for llama_index_packs_infer_retrieve_rerank-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc6c9176a0da2222f6e7e76e5e9c433beb9b5370a69a8e3835fce29ba842abf |
|
MD5 | f2ad4f7d388dbdd00e35b1f2e0ab8d2c |
|
BLAKE2b-256 | 2c284215cb8e51ce0646b20a0c2ff1b9c3889e8197f69b67a973de2bfeb64fbf |
Hashes for llama_index_packs_infer_retrieve_rerank-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc2066cb8fc058f9cb94a99413beeb2ce19ce882371068ea6da17e8db4e1747 |
|
MD5 | 0e5723f651e96a83ec00801049b2e2c6 |
|
BLAKE2b-256 | 695d94931e695dc95fbf8cc851aba19752c697e0db95109cc234ae63560d864b |