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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.3.1.tar.gz
Algorithm Hash digest
SHA256 df26db15f37adbfac68e52823887cbaa88f2c804166185152cfcc5c6a2338a39
MD5 a4115db4d3c8f15993245b15d541fb80
BLAKE2b-256 8219c66c3162efdf0582042d85581fecfb25ffe0667e1cd28a07ad12f227ce0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_packs_raft_dataset-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c0868c6b13808d55d75fd6c10978f9314a6560a31a86ed6ea2408df20728d31
MD5 87023ee6c27153c376375ba9fe5ebc16
BLAKE2b-256 5ea2d5e687cd2275f3b19b7773c60b30c27892f3ffa448d7e894ff0e874ca520

See more details on using hashes here.

Supported by

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