
Raptor แนะนำวิธีการใหม่ ๆ ในการดึงโมเดลภาษาที่ถูกเรียกคืนโดยการสร้างโครงสร้างต้นไม้แบบเรียกซ้ำจากเอกสาร สิ่งนี้ช่วยให้การดึงข้อมูลที่มีประสิทธิภาพและรับรู้บริบทมากขึ้นในข้อความขนาดใหญ่โดยจัดการกับข้อ จำกัด ทั่วไปในรูปแบบภาษาแบบดั้งเดิม
สำหรับวิธีการโดยละเอียดและการใช้งานโปรดดูเอกสารต้นฉบับ:
ก่อนที่จะใช้ Raptor ให้ตรวจสอบให้แน่ใจว่ามีการติดตั้ง Python 3.8+ โคลนที่เก็บ Raptor และติดตั้งการพึ่งพาที่จำเป็น:
git clone https://github.com/parthsarthi03/raptor.git
cd raptor
pip install -r requirements.txtหากต้องการเริ่มต้นกับ Raptor ให้ทำตามขั้นตอนเหล่านี้:
ขั้นแรกให้ตั้งค่าคีย์ OpenAI API ของคุณและเริ่มต้นการกำหนดค่า Raptor:
import os
os . environ [ "OPENAI_API_KEY" ] = "your-openai-api-key"
from raptor import RetrievalAugmentation
# Initialize with default configuration. For advanced configurations, check the documentation. [WIP]
RA = RetrievalAugmentation ()เพิ่มเอกสารข้อความของคุณไปยัง Raptor สำหรับการจัดทำดัชนี:
with open ( 'sample.txt' , 'r' ) as file :
text = file . read ()
RA . add_documents ( text )ตอนนี้คุณสามารถใช้ Raptor เพื่อตอบคำถามตามเอกสารที่จัดทำดัชนี:
question = "How did Cinderella reach her happy ending?"
answer = RA . answer_question ( question = question )
print ( "Answer: " , answer )บันทึกต้นไม้ที่สร้างขึ้นไปยังเส้นทางที่ระบุ:
SAVE_PATH = "demo/cinderella"
RA . save ( SAVE_PATH )โหลดต้นไม้ที่บันทึกไว้กลับเข้าไปใน Raptor:
RA = RetrievalAugmentation ( tree = SAVE_PATH )
answer = RA . answer_question ( question = question )Raptor ได้รับการออกแบบให้มีความยืดหยุ่นและช่วยให้คุณสามารถรวมโมเดลใด ๆ สำหรับการสรุปการตอบคำถาม (QA) และการสร้างการฝัง นี่คือวิธีการขยาย Raptor ด้วยโมเดลของคุณเอง:
หากคุณต้องการใช้แบบจำลองภาษาอื่นสำหรับการสรุปคุณสามารถทำได้โดยขยายคลาส BaseSummarizationModel ใช้วิธี summarize เพื่อรวมตรรกะการสรุปที่กำหนดเองของคุณ:
from raptor import BaseSummarizationModel
class CustomSummarizationModel ( BaseSummarizationModel ):
def __init__ ( self ):
# Initialize your model here
pass
def summarize ( self , context , max_tokens = 150 ):
# Implement your summarization logic here
# Return the summary as a string
summary = "Your summary here"
return summary สำหรับรุ่น QA ที่กำหนดเองให้ขยายคลาส BaseQAModel และใช้วิธี answer_question วิธีนี้ควรส่งคืนคำตอบที่ดีที่สุดที่พบโดยโมเดลของคุณเนื่องจากบริบทและคำถาม:
from raptor import BaseQAModel
class CustomQAModel ( BaseQAModel ):
def __init__ ( self ):
# Initialize your model here
pass
def answer_question ( self , context , question ):
# Implement your QA logic here
# Return the answer as a string
answer = "Your answer here"
return answer หากต้องการใช้แบบจำลองการฝังที่แตกต่างกันให้ขยายคลาส BaseEmbeddingModel ใช้วิธี create_embedding ซึ่งควรส่งคืนการแสดงเวกเตอร์ของข้อความอินพุต:
from raptor import BaseEmbeddingModel
class CustomEmbeddingModel ( BaseEmbeddingModel ):
def __init__ ( self ):
# Initialize your model here
pass
def create_embedding ( self , text ):
# Implement your embedding logic here
# Return the embedding as a numpy array or a list of floats
embedding = [ 0.0 ] * embedding_dim # Replace with actual embedding logic
return embedding หลังจากใช้โมเดลที่กำหนดเองของคุณแล้วให้รวมเข้ากับ Raptor ดังนี้:
from raptor import RetrievalAugmentation , RetrievalAugmentationConfig
# Initialize your custom models
custom_summarizer = CustomSummarizationModel ()
custom_qa = CustomQAModel ()
custom_embedding = CustomEmbeddingModel ()
# Create a config with your custom models
custom_config = RetrievalAugmentationConfig (
summarization_model = custom_summarizer ,
qa_model = custom_qa ,
embedding_model = custom_embedding
)
# Initialize RAPTOR with your custom config
RA = RetrievalAugmentation ( config = custom_config ) ตรวจสอบ demo.ipynb สำหรับตัวอย่างเกี่ยวกับวิธีการระบุการสรุปของคุณเอง/โมเดล QA ของคุณเองเช่น Llama/Mistral/Gemma และโมเดลการฝังเช่น Sbert สำหรับใช้กับ Raptor
หมายเหตุ: ตัวอย่างเพิ่มเติมและวิธีการกำหนดค่า Raptor กำลังจะมาถึง การใช้งานขั้นสูงและคุณสมบัติเพิ่มเติมจะมีให้ในการอัปเดตเอกสารและที่เก็บ
Raptor เป็นโครงการโอเพ่นซอร์สและยินดีต้อนรับผลงาน ไม่ว่าคุณจะแก้ไขข้อบกพร่องเพิ่มคุณสมบัติใหม่หรือปรับปรุงเอกสารความช่วยเหลือของคุณจะได้รับการชื่นชม
Raptor ได้รับการปล่อยตัวภายใต้ใบอนุญาต MIT ดูไฟล์ใบอนุญาตในที่เก็บสำหรับรายละเอียดทั้งหมด
หาก Raptor ช่วยในการวิจัยของคุณโปรดอ้างอิงดังนี้:
@inproceedings { sarthi2024raptor ,
title = { RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval } ,
author = { Sarthi, Parth and Abdullah, Salman and Tuli, Aditi and Khanna, Shubh and Goldie, Anna and Manning, Christopher D. } ,
booktitle = { International Conference on Learning Representations (ICLR) } ,
year = { 2024 }
}คอยติดตามตัวอย่างเพิ่มเติมคู่มือการกำหนดค่าและการอัปเดต