Skip to main content

llama-index packs RAFT Dataset paper implementation

Project description

RAFT: Adapting Language Model to Domain Specific RAG Llama Pack

This LlamaPack implements RAFT: Adapting Language Model to Domain Specific RAG paper

Retrieval Augmented FineTuning (RAFT) is a training recipe introduced in this paper that aims to improve the performance of large language models (LLMs) in open-book, in-domain question-answering tasks. Given a question and a set of retrieved documents, RAFT trains the LLM to identify and cite verbatim the most relevant sequences from the documents that help answer the question, while ignoring irrelevant or distracting information. By explicitly training the model to distinguish between relevant and irrelevant information and to provide evidence from the relevant documents, RAFT encourages the LLM to develop better reasoning and explanation abilities, ultimately improving its ability to answer questions accurately and rationally in scenarios where additional context or knowledge is available.

A key component of RAFT is how the dataset is generated for fine-tuning. Each QA pair also includes an "oracle" document from which the answer to the question can be deduced as well as "distractor" documents which are irrelevant. During training this forces the model to learn which information is relevant/irrelevant and also memorize domain knowledge.

We've implemented the dataset generation part in a LlamaPack. Check out our full notebook here.

Installation

pip install llama-index

CLI Usage

You can download llamapacks directly using llamaindex-cli, which comes installed with the llama-index python package:

llamaindex-cli download-llamapack RAFTDatasetPack --download-dir ./raft_dataset_pack

You can then inspect the files at ./raft_dataset_pack and use them as a template for your own project.

Code Usage

You can download the pack to a the ./raft_dataset_pack directory:

from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
RAFTDatasetPack = download_llama_pack("RAFTDatasetPack", "./raft_dataset_pack")

# You can use any llama-hub loader to get documents!
raft_dataset = RAFTDatasetPack(file_path)

From here, you can use the pack, or inspect and modify the pack in ./raft_dataset_pack.

The run() function contains around logic behind RAFT: Adapting Language Model to Domain Specific RAG paper

dataset = raft_dataset.run()

This will return the dataset which can be further used for finetuned purpose. Please refer to original blog on using the dataset for fine-tuning.

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

llama_index_packs_raft_dataset-0.4.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_packs_raft_dataset-0.4.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b9ea6749d64fd2b9f8d24b59a59c8addd7e6312c74e516312cf211081353ecff
MD5 4d0e03f5c3050f81a4d3dfd24149c137
BLAKE2b-256 1e8d371c9545139cf85698a31e626fed43c0c441c59127555c3f0f7562ceb722

See more details on using hashes here.

File details

Details for the file llama_index_packs_raft_dataset-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31a594d34b5f1b6769d0459e175a1f82d50f9ae1d92b2d66cb2c2640af4d1006
MD5 8a7d98d646f4cde695591822b7ffb0a7
BLAKE2b-256 8597ac1db4badfa165557ec028e2e595fe9b9a21d6100c97a190e25b27dcd66a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page