Factural Correctness
Factural Correctness是事實正確性是評價LLM生成的反饋和reference的事實正確性。該指標用于確定生成的響應與參考文獻的一致程度。Factural Correctness取值在0到1之間,越接近于1結果越好。
為了衡量回應和參考文獻之間的一致性,該指標使用 LLM 首先將response和reference分解為claims(主張),然后使用自然語言推理確定回應和參考文獻之間的事實重疊。
● TP(True Positive):Response中的Claims在reference中存在的個數。
● FP(False Positive):Response中Claims不在reference中存在的個數。
● FN(False Negative):Reference中Claims不在Response中的個數。
通過上面的定義,計算Precison、Recall、F1,通過mode參數來控制,默認是F1。
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics._factual_correctness import FactualCorrectness
from langchain_ollama import ChatOllama
from ollama_wrapper import OllamaLLMWrapper
import asyncio
async def main():modle = "llama3.1:8b"llm = ChatOlla