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.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c010472945e1301a397f2f096f6437eb42ef94af9fae21f23dd175d53a0cb341
MD5 fd496c520a05b50f144ebad1f18943aa
BLAKE2b-256 05f174e7b9c52c8b1c8a243310de3579c83137d478c6f46a5638daaa22ca0cb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7a1f347d28d90fa91e9f3b11794ceebee27d666163a23bd3c45b65d6d0bcc3f
MD5 d78fa326ee59dc7b375e4b285daca836
BLAKE2b-256 9857920509ff3ebffc5d8e98fb0dee0067c882bbdc22c1e965b1ee037db0b534

See more details on using hashes here.

Supported by

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