Llama-3-8B-RAG-v1 / README.md
naklecha's picture
Update README.md
e20ebc2 verified
|
raw
history blame
3.8 kB
metadata
license: llama3
datasets:
  - glaiveai/RAG-v1
language:
  - en
tags:
  - RAG

Llama-3-8B-RAG-v1

This model is a fine-tuned version of Llama-3-8B for Retrieval-Augmented Generation (RAG) tasks.

Model Details

  • Developed by: GlaiveAI
  • Model type: Llama-3 finetuned for RAG tasks

Uses

This model is designed for RAG tasks, where it can answer questions based on provided documents.

How to Get Started with the Model

Use the code below to get started with the model:

NOTE: Try to use the same system prompt and document formatting as the example provided below, this is the same format that was used to finetune the model.

from transformers import AutoTokenizer, pipeline

model_name = "glaiveai/Llama-3-8B-RAG-v1"
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Example user query
user_query = """Document:0

Title: Financial Compliance and Company Statements

Text: [Document text...]

Document:1

Title: Certification of Financial Reports by CEO of Black Knight, Inc.

Text: [Document text...]

Answer Mode: Grounded

Question: How does the CEO of Black Knight, Inc. ensure compliance with the Securities Exchange Act of 1934, and what are the implications of the certification provided?"""

# Prepare chat template
chat = [
   {"role": "system", "content": "You are a conversational AI assistant that is provided a list of documents and a user query to answer based on information from the documents. The user also provides an answer mode which can be 'Grounded' or 'Mixed'. For answer mode Grounded only respond with exact facts from documents, for answer mode Mixed answer using facts from documents and your own knowledge. Cite all facts from the documents using <co: doc_id></co> tags."},
   {"role": "user", "content": user_query}
]

prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)

# Set up pipeline and generate response
pipe = pipeline('text-generation', model=model_name, tokenizer=model_name, device=0)
output = pipe(
    prompt, 
    max_length=1000, 
    num_return_sequences=1, 
    top_k=50, 
    top_p=0.95, 
    temperature=0.5, 
    do_sample=True, 
    return_full_text=False
)

print(output[0]['generated_text'])

Output of above code block

CopyCited Documents: 1
Answer: <co:1>The CEO of Black Knight, Inc., Anthony M. Jabbour, ensures compliance with the Securities Exchange Act of 1934 by certifying that the periodic financial report and financial statements comply fully with the requirements of Section 13(a) or 15(d) of the Act. This certification confirms that the information in the reports fairly presents, in all material respects, the financial condition and results of operations of Black Knight, Inc.</co> This certification is crucial as it assures stakeholders of the reliability of the financial statements provided by the company, thereby maintaining investor confidence and adherence to legal financial reporting standards.
In this output:

The model cites Document 1 as the source of its information.
It provides a grounded answer based on the content of Document 1, as requested in the "Answer Mode: Grounded" instruction.
The answer explains how the CEO ensures compliance and the implications of the certification.
The citation is marked with <co:1></co> tags, indicating that this information comes directly from Document 1.

Code Explanation

The code is split into two main parts:

  1. Chat Template Preparation: We create a chat list with a system message and a user query. The apply_chat_template method is used to format this chat into a prompt suitable for the model.
  2. Pipeline Setup and Generation: We set up a text-generation pipeline with our model and tokenizer. The prepared prompt is passed to the pipeline to generate a response.