
랩터는 문서에서 재귀 트리 구조를 구성하여 검색 된 언어 모델을 검색하는 새로운 접근 방식을 소개합니다. 이를 통해 전통적인 언어 모델의 일반적인 한계를 해결하면서 큰 텍스트에서보다 효율적이고 상황을 인식하는 정보 검색이 가능합니다.
자세한 방법론 및 구현은 원래 논문을 참조하십시오.
랩터를 사용하기 전에 Python 3.8+가 설치되어 있는지 확인하십시오. 랩터 저장소를 복제하고 필요한 종속성을 설치하십시오.
git clone https://github.com/parthsarthi03/raptor.git
cd raptor
pip install -r requirements.txt랩터를 시작하려면 다음 단계를 따르십시오.
먼저 OpenAI API 키를 설정하고 랩터 구성을 초기화하십시오.
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 ()인덱싱을 위해 랩터에 텍스트 문서를 추가하십시오.
with open ( 'sample.txt' , 'r' ) as file :
text = file . read ()
RA . add_documents ( text )이제 랩터를 사용하여 색인화 된 문서를 기반으로 질문에 답변 할 수 있습니다.
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 )저장된 트리를 랩터에 다시 넣습니다.
RA = RetrievalAugmentation ( tree = SAVE_PATH )
answer = RA . answer_question ( question = question )Raptor는 유연하게 설계되었으며 요약, 질문 응답 (QA) 및 임베딩 생성을 위해 모든 모델을 통합 할 수 있습니다. 다음은 자신의 모델로 랩터를 확장하는 방법입니다.
요약에 다른 언어 모델을 사용하려면 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 사용자 정의 모델을 구현 한 후 다음과 같이 랩터와 통합하십시오.
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 ) LLAMA/MISTRAL/GEMMA와 같은 자신의 요약/QA 모델을 지정하는 방법에 대한 예제 및 SBERT와 같은 임베딩 모델을 랩터와 함께 사용하는 방법에 대한 demo.ipynb 확인하십시오.
참고 : 랩터를 구성하는 더 많은 예와 방법이 다가올 예정입니다. 문서 및 저장소 업데이트에 고급 사용 및 추가 기능이 제공됩니다.
랩터는 오픈 소스 프로젝트이며 기부금을 환영합니다. 버그를 고치거나 새로운 기능 추가 또는 문서 개선에 관계없이 도움을 주시면 도움이됩니다.
랩터는 MIT 라이센스에 따라 릴리스됩니다. 자세한 내용은 저장소의 라이센스 파일을 참조하십시오.
랩터가 연구에 도움이되면 다음과 같이 인용하십시오.
@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 }
}더 많은 예제, 구성 안내서 및 업데이트를 위해 계속 지켜봐 주시기 바랍니다.