Abruf Augmented Generation (RAG) ist eine Technik, die Großsprachmodelle (LLMs) intelligenter und genauer macht, indem sie externe Informationen beim Generieren von Text verwenden können.
Die große Herausforderung besteht jedoch darin, die richtigen Dokumente oder Passagen aus einer riesigen Datenerfassung auszuwählen.
RANKGPT befasst sich mit diesem Problem, indem sie den Wiederaufbauschritt in Lag-Pipelines verbessert. Es nutzt die tiefen Verständnisfunktionen von LLMs, um besser zu bewerten und (wieder) zu bewerten, welche Informationen am relevantesten sind.
In diesem Artikel werden wir RankGPT vorstellen und zeigen, wie Sie es in Ihre RAG -AI -Anwendungen integrieren können.
Abruf Augmented Generation (RAG) ist eine Methode, die LLMs mit Informationsabrufsystemen kombiniert. Dies bedeutet, dass ein LLM aufgefordert wird, Text zu generieren, relevante Informationen aus externen Quellen einnehmen kann, wodurch die Antworten genauer und informierter werden.
retriever - Die Aufgabe des Retrievers besteht darin, relevante Dokumente oder Textsegmente aus einer großen Reihe von Dokumenten zu finden, die auf der Abfrage des Benutzers basieren. Es verwendet Algorithmen wie BM25, um die Dokumente nach ihrer Relevanz zu bewerten.
RANKGPT geht über einfache Schlüsselwortübereinstimmung hinaus, indem sie die tiefere Bedeutung und den Kontext von Abfragen und Dokumenten verstehen. Dies ermöglicht es ihm, genauere Informationen für LLMs bereitzustellen und den relevantesten Inhalt basierend auf seiner tatsächlichen Bedeutung zu identifizieren, nicht nur für Schlüsselwörter.
effiziente und kostengünstige Destillation
RANKGPT verwendet die Destillation der Permutation, um die Ranglisten in großen Modellen wie GPT-4 in kleinere, spezialisierte Modelle zu übertragen.
Diese kleineren Modelle halten eine hohe Leistung bei und sind viel effizienter. Beispielsweise übertraf ein destilliertes 440 -m -Modell ein 3B -beaufsichtigtes Modell auf dem BEIR -Benchmark, wodurch die Rechenkosten erheblich gesenkt werden und gleichzeitig bessere Ergebnisse erzielt wurden.
RANKGPT enthält den neuer Testsatz, um die Robustheit zu gewährleisten und Datenkontaminationsbedenken zu beheben. Dieser Satz bewertet die Fähigkeit des Modells, Passagen basierend auf den jüngsten und unbekannten Informationen zu bewerten.
GPT-4 erzielte bei diesem Test eine modernste Leistung und zeigt die Fähigkeit, neue und unsichtbare Abfragen effektiv umzugehen.
RANKGPT (GPT-4) übertrifft alle anderen Modelle über TREC und BIR, wobei ein durchschnittlicher NDCG@10-Score von 53,68, wie in der folgenden Tabelle gezeigt, gezeigt. Es erzielte die höchsten Ergebnisse in den BEIR-Datensätzen und besiegte starke beaufsichtigte Modelle wie Monot5 (3B) und Cohere Rerank-V2. Auch mit GPT-3,5-Turbo erzielt RANKGPT wettbewerbsfähig und beweist, dass es sich um einen hochwirksamen Reranker handelt.
Quelle: Weiwei Sun et al., 2023
RankGPT (GPT-4) tritt auch stark auf den Mr.Tydi-Datensätzen ab und führt mit einem durchschnittlichen NDCG@10-Punktzahl von 62,93 und schlägt sowohl BM25 als auch MMARCOCE. Es übertrifft konsequent BM25 und übertrifft Mmarcoce sogar in vielen Sprachen, insbesondere in Indonesischen und Swahili.
Insgesamt erzielte RankGPT in vielen Sprachen wie Bengali, Indonesisch und Japanisch am höchsten. Nur wenige Fälle, in denen es etwas hinter Mmarcoce zurückblieb.
Quelle: Weiwei Sun et al., 2023
Schließlich wurde RankGPT auf dem neuer Datensatz getestet, was misst, wie gut ein Modell Passagen basierend auf den jüngsten und unbekannten Informationen bewerten kann. RankGPT (GPT-4) erzielte in allen Bewertungsmetriken (NDCG@1, NDCG@5 und NDCG@10), insbesondere mit der NDCG@10-Punktzahl von 90,45, am höchsten. Es übertraf andere starke Modelle wie Monot5 (3B) und Monobert (340 m), was seine starke Leistung als Reranker hervorhebt.
Quelle: Weiwei Sun et al., 2023
In allen Benchmark-Ergebnissen übertrifft RANKGPT (GPT-4) andere Methoden konsequent, unabhängig davon
Implementieren von RANKGPT in Lag -PipelinesSchritt 1: Klonen Sie das RANKGPT -Repository
git clone https://github.com/sunnweiwei/RankGPT
Navigieren Sie zum RankGPT -Verzeichnis und installieren Sie die erforderlichen Pakete. Möglicherweise möchten Sie eine virtuelle Umgebung erstellen und Pakete mit den bereitgestellten Anforderungen installieren.txt:
pip install -r requirements.txt
Hier verwenden wir die simple Beispielabfrage und abgerufene Dokumente, die vom ursprünglichen RANKGPT -Repository bereitgestellt werden.
item = { 'query': 'How much impact do masks have on preventing the spread of the COVID-19?', 'hits': [ {'content': 'Title: Universal Masking is Urgent in the COVID-19 Pandemic: SEIR and Agent Based Models, Empirical Validation, Policy Recommendations Content: We present two models for the COVID-19 pandemic predicting the impact of universal face mask wearing upon the spread of the SARS-CoV-2 virus--one employing a stochastic dynamic network based compartmental SEIR (susceptible-exposed-infectious-recovered) approach, and the other employing individual ABM (agent-based modelling) Monte Carlo simulation--indicating (1) significant impact under (near) universal masking when at least 80% of a population is wearing masks, versus minimal impact when only 50% or less of the population is wearing masks, and (2) significant impact when universal masking is adopted early, by Day 50 of a regional outbreak, versus minimal impact when universal masking is adopted late. These effects hold even at the lower filtering rates of homemade masks. To validate these theoretical models, we compare their predictions against a new empirical data set we have collected'}, {'content': 'Title: Masking the general population might attenuate COVID-19 outbreaks Content: The effect of masking the general population on a COVID-19 epidemic is estimated by computer simulation using two separate state-of-the-art web-based softwares, one of them calibrated for the SARS-CoV-2 virus. The questions addressed are these: 1. Can mask use by the general population limit the spread of SARS-CoV-2 in a country? 2. What types of masks exist, and how elaborate must a mask be to be effective against COVID-19? 3. Does the mask have to be applied early in an epidemic? 4. A brief general discussion of masks and some possible future research questions regarding masks and SARS-CoV-2. Results are as follows: (1) The results indicate that any type of mask, even simple home-made ones, may be effective. Masks use seems to have an effect in lowering new patients even the protective effect of each mask (here dubbed"one-mask protection") is'}, {'content': 'Title: To mask or not to mask: Modeling the potential for face mask use by the general public to curtail the COVID-19 pandemic Content: Face mask use by the general public for limiting the spread of the COVID-19 pandemic is controversial, though increasingly recommended, and the potential of this intervention is not well understood. We develop a compartmental model for assessing the community-wide impact of mask use by the general, asymptomatic public, a portion of which may be asymptomatically infectious. Model simulations, using data relevant to COVID-19 dynamics in the US states of New York and Washington, suggest that broad adoption of even relatively ineffective face masks may meaningfully reduce community transmission of COVID-19 and decrease peak hospitalizations and deaths. Moreover, mask use decreases the effective transmission rate in nearly linear proportion to the product of mask effectiveness (as a fraction of potentially infectious contacts blocked) and coverage rate (as'} ] }
Sie können die bereitgestellte Permutationspipeline verwenden, um die abgerufenen Dokumente einfach mit RANKGPT weiterzuleiten.
from rank_gpt import permutation_pipeline new_item = permutation_pipeline( item, rank_start=0, rank_end=3, model_name='gpt-3.5-turbo', api_key='Your OPENAI Key!' ) print(new_item)
Dies führt zu der folgenden neuen Reihenfolge der Dokumente:
{ 'query': 'How much impact do masks have on preventing the spread of the COVID-19?', 'hits': [ {'content': 'Title: Universal Masking is Urgent in the COVID-19 Pandemic: SEIR and Agent Based Models, Empirical Validation, Policy Recommendations Content: We present two models for the COVID-19 pandemic predicting the impact of universal face mask wearing upon the spread of the SARS-CoV-2 virus--one employing a stochastic dynamic network based compartmental SEIR (susceptible-exposed-infectious-recovered) approach, and the other employing individual ABM (agent-based modelling) Monte Carlo simulation--indicating (1) significant impact under (near) universal masking when at least 80% of a population is wearing masks, versus minimal impact when only 50% or less of the population is wearing masks, and (2) significant impact when universal masking is adopted early, by Day 50 of a regional outbreak, versus minimal impact when universal masking is adopted late. These effects hold even at the lower filtering rates of homemade masks. To validate these theoretical models, we compare their predictions against a new empirical data set we have collected'}, {'content': 'Title: To mask or not to mask: Modeling the potential for face mask use by the general public to curtail the COVID-19 pandemic Content: Face mask use by the general public for limiting the spread of the COVID-19 pandemic is controversial, though increasingly recommended, and the potential of this intervention is not well understood. We develop a compartmental model for assessing the community-wide impact of mask use by the general, asymptomatic public, a portion of which may be asymptomatically infectious. Model simulations, using data relevant to COVID-19 dynamics in the US states of New York and Washington, suggest that broad adoption of even relatively ineffective face masks may meaningfully reduce community transmission of COVID-19 and decrease peak hospitalizations and deaths. Moreover, mask use decreases the effective transmission rate in nearly linear proportion to the product of mask effectiveness (as a fraction of potentially infectious contacts blocked) and coverage rate (as'}, {'content': 'Title: Masking the general population might attenuate COVID-19 outbreaks Content: The effect of masking the general population on a COVID-19 epidemic is estimated by computer simulation using two separate state-of-the-art web-based softwares, one of them calibrated for the SARS-CoV-2 virus. The questions addressed are these: 1. Can mask use by the general population limit the spread of SARS-CoV-2 in a country? 2. What types of masks exist, and how elaborate must a mask be to be effective against COVID-19? 3. Does the mask have to be applied early in an epidemic? 4. A brief general discussion of masks and some possible future research questions regarding masks and SARS-CoV-2. Results are as follows: (1) The results indicate that any type of mask, even simple home-made ones, may be effective. Masks use seems to have an effect in lowering new patients even the protective effect of each mask (here dubbed"one-mask protection") is'} ] }
Für eine Schritt-für-Schritt-Implementierung der Permutationspipeline können Sie direkt mit RANKGPT interagieren, um Permutationsanweisungen wie folgt zu erstellen und zu verarbeiten:
from rank_gpt import ( create_permutation_instruction, run_llm, receive_permutation ) # Create permutation generation instruction messages = create_permutation_instruction( item=item, rank_start=0, rank_end=3, model_name='gpt-3.5-turbo' )
[{'role': 'system', 'content': 'You are RankGPT, an intelligent assistant that can rank passages based on their relevancy to the query.'}, {'role': 'user', 'content': 'I will provide you with 3 passages, each indicated by number identifier []. \nRank the passages based on their relevance to query: How much impact do masks have on preventing the spread of the COVID-19?.'}, {'role': 'assistant', 'content': 'Okay, please provide the passages.'}, {'role': 'user', 'content': '[1] Title: Universal Masking is Urgent in the COVID-19 Pandemic: SEIR and Agent Based Models, Empirical Validation, Policy Recommendations Content: We present two models for the COVID-19 pandemic predicting the impact of universal face mask wearing upon the spread of the SARS-CoV-2 virus--one employing a stochastic dynamic network based compartmental SEIR (susceptible-exposed-infectious-recovered) approach, and the other employing individual ABM (agent-based modelling) Monte Carlo simulation--indicating (1) significant impact under (near) universal masking when at least 80% of a population is wearing masks, versus minimal impact when only 50% or less of the population is wearing masks, and (2) significant impact when universal masking is adopted early, by Day 50 of a regional outbreak, versus minimal impact when universal masking is adopted late. These effects hold even at the lower filtering rates of homemade masks. To validate these theoretical models, we compare their predictions against a new empirical data set we have collected'}, {'role': 'assistant', 'content': 'Received passage [1].'}, {'role': 'user', 'content': '[2] Title: Masking the general population might attenuate COVID-19 outbreaks Content: The effect of masking the general population on a COVID-19 epidemic is estimated by computer simulation using two separate state-of-the-art web-based softwares, one of them calibrated for the SARS-CoV-2 virus. The questions addressed are these: 1. Can mask use by the general population limit the spread of SARS-CoV-2 in a country? 2. What types of masks exist, and how elaborate must a mask be to be effective against COVID-19? 3. Does the mask have to be applied early in an epidemic? 4. A brief general discussion of masks and some possible future research questions regarding masks and SARS-CoV-2. Results are as follows: (1) The results indicate that any type of mask, even simple home-made ones, may be effective. Masks use seems to have an effect in lowering new patients even the protective effect of each mask (here dubbed"one-mask protection") is'}, {'role': 'assistant', 'content': 'Received passage [2].'}, {'role': 'user', 'content': '[3] Title: To mask or not to mask: Modeling the potential for face mask use by the general public to curtail the COVID-19 pandemic Content: Face mask use by the general public for limiting the spread of the COVID-19 pandemic is controversial, though increasingly recommended, and the potential of this intervention is not well understood. We develop a compartmental model for assessing the community-wide impact of mask use by the general, asymptomatic public, a portion of which may be asymptomatically infectious. Model simulations, using data relevant to COVID-19 dynamics in the US states of New York and Washington, suggest that broad adoption of even relatively ineffective face masks may meaningfully reduce community transmission of COVID-19 and decrease peak hospitalizations and deaths. Moreover, mask use decreases the effective transmission rate in nearly linear proportion to the product of mask effectiveness (as a fraction of potentially infectious contacts blocked) and coverage rate (as'}, {'role': 'assistant', 'content': 'Received passage [3].'}, {'role': 'user', 'content': 'Search Query: How much impact do masks have on preventing the spread of the COVID-19?. \nRank the 3 passages above based on their relevance to the search query. The passages should be listed in descending order using identifiers. The most relevant passages should be listed first. The output format should be [] > [], e.g., [1] > [2]. Only response the ranking results, do not say any word or explain.'}]
# Get ChatGPT predicted permutation permutation = run_llm( messages, api_key='Your OPENAI Key!', model_name='gpt-3.5-turbo' )
'[1] > [3] > [2]'
# Use permutation to re-rank the passage item = receive_permutation( item, permutation, rank_start=0, rank_end=3 )
{'query': 'How much impact do masks have on preventing the spread of the COVID-19?', 'hits': [{'content': 'Title: Universal Masking is Urgent in the COVID-19 Pandemic: SEIR and Agent Based Models, Empirical Validation, Policy Recommendations Content: We present two models for the COVID-19 pandemic predicting the impact of universal face mask wearing upon the spread of the SARS-CoV-2 virus--one employing a stochastic dynamic network based compartmental SEIR (susceptible-exposed-infectious-recovered) approach, and the other employing individual ABM (agent-based modelling) Monte Carlo simulation--indicating (1) significant impact under (near) universal masking when at least 80% of a population is wearing masks, versus minimal impact when only 50% or less of the population is wearing masks, and (2) significant impact when universal masking is adopted early, by Day 50 of a regional outbreak, versus minimal impact when universal masking is adopted late. These effects hold even at the lower filtering rates of homemade masks. To validate these theoretical models, we compare their predictions against a new empirical data set we have collected'}, {'content': 'Title: To mask or not to mask: Modeling the potential for face mask use by the general public to curtail the COVID-19 pandemic Content: Face mask use by the general public for limiting the spread of the COVID-19 pandemic is controversial, though increasingly recommended, and the potential of this intervention is not well understood. We develop a compartmental model for assessing the community-wide impact of mask use by the general, asymptomatic public, a portion of which may be asymptomatically infectious. Model simulations, using data relevant to COVID-19 dynamics in the US states of New York and Washington, suggest that broad adoption of even relatively ineffective face masks may meaningfully reduce community transmission of COVID-19 and decrease peak hospitalizations and deaths. Moreover, mask use decreases the effective transmission rate in nearly linear proportion to the product of mask effectiveness (as a fraction of potentially infectious contacts blocked) and coverage rate (as'}, {'content': 'Title: Masking the general population might attenuate COVID-19 outbreaks Content: The effect of masking the general population on a COVID-19 epidemic is estimated by computer simulation using two separate state-of-the-art web-based softwares, one of them calibrated for the SARS-CoV-2 virus. The questions addressed are these: 1. Can mask use by the general population limit the spread of SARS-CoV-2 in a country? 2. What types of masks exist, and how elaborate must a mask be to be effective against COVID-19? 3. Does the mask have to be applied early in an epidemic? 4. A brief general discussion of masks and some possible future research questions regarding masks and SARS-CoV-2. Results are as follows: (1) The results indicate that any type of mask, even simple home-made ones, may be effective. Masks use seems to have an effect in lowering new patients even the protective effect of each mask (here dubbed"one-mask protection") is'}]}
Wenn Sie mehr Dokumente einweisen müssen, als das Modell gleichzeitig verarbeiten kann, verwenden Sie eine Schiebungsfensterstrategie. Hier erfahren Sie, wie Sie eine Strategie für die Schiebefenster anwenden, um Dokumente erneut zu beziehen:
from rank_gpt import sliding_windows api_key = "Your OPENAI Key" new_item = sliding_windows( item, rank_start=0, rank_end=3, window_size=2, step=1, model_name='gpt-3.5-turbo', api_key=api_key ) print(new_item)
In diesem Beispiel hat das Gleitfenster eine Größe von 2 und eine Stufengröße von 1, was bedeutet, dass es zwei Dokumente gleichzeitig verarbeitet, wobei ein Dokument für den nächsten Ranking -Pass voranschreitet.
Durch die Verwendung von LLMs, um die Relevanz von Informationen besser zu bewerten
Dies befasst sich mit häufigen Problemen wie der Gewährleistung des Inhalts, der Verbesserung der Effizienz und der Verringerung der Wahrscheinlichkeit, irreführende Informationen zu generieren.
Insgesamt trägt RANKGPT dazu bei, zuverlässigere und genauere Lag -Anwendungen aufzubauen.
Das obige ist der detaillierte Inhalt vonRankGPT als Wiederholungsagent für RAG (Tutorial). Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!