如何从文档创建 RAG 评估数据集

如何使用Hugging Face微调大语言模型(LLMs) 微调LLM时,了解你的使用场景和要解决的问题至关重要。这将帮助你选择合适的模型,或者帮助你创建一个数据集来微调你的模型。如果你还没有定义你的使用场景,你可能需要重新思考。并非所有的使用场景都需要微调,建议在微调你自己的模型之前,先评估和尝试已经微调过的模型或基于API的模型。例如,我们将使用以下使用场景:我们想要微调一个模型,它可以基于自然语言指令生成SQL查询,然后可以集成到我们的BI工具中。目标是减少创建SQL查询所需的时间,并使非技术用户更容易创建SQL查询。 阅读详情

在这里插入图片描述

在本文中,将展示如何创建自己的 RAG 数据集,该数据集包含任何语言的文档的上下文、问题和答案。

检索增强生成 (RAG) [1] 是一种允许 LLM 访问外部知识库的技术。

通过上传 PDF 文件并将其存储在矢量数据库中,我们可以通过矢量相似性搜索检索这些知识,然后将检索到的文本作为附加上下文插入到 LLM 提示中。

这为LLM提供了新的知识,并减少了LLM编造事实(幻觉)的可能性。

RAG 流程概述,对于文档存储:输入文档 -> 文本块 -> 编码器模型 -> 向量数据库,对于 LLM 提示:用户问题 -> 编码器模型 -> 向量数据库 -> 前 k 个相关块 -> 生成器 LLM 模型,然后,LLM 使用检索到的上下文回答问题。

在这里插入图片描述

然而,我们需要在 RAG 流程中设置许多参数,研究人员也一直在提出新的改进建议。我们如何知道应该选择哪些参数以及哪些方法可以真正提高我们特定用例的性能?

这就是为什么我们需要一个validation/dev/test数据集来评估我们的 RAG 管道。数据集应该来自我们感兴趣的领域和我们想要使用的语言。

使用 VLLM 部署本地 LLM

首先,我们要建立并运行本地大模型。

我使用VLLM设置了一个与 OpenAI 兼容的 LLM 服务,其中包含量化的Llama-3.2–3B-Instruct。确保你使用的 LLM 已经针对你想要使用的语言进行过训练。

使用 Docker 和 VLLM 部署本地 LLM 非常简单:

使用Docker:

docker run --runtime nvidia --gpus all \ 
    -v ~/.cache/huggingface:/root/.cache/huggingface \ 
    -- env  "HUGGING_FACE_HUB_TOKEN=<secret>" \ 
    -p 8000:8000 \ 
    --ipc=host \ 
    vllm/vllm-openai:latest \ 
    --model AMead10/Llama-3.2-3B-Instruct-AWQ \ 
    --quantization awq \ 
    --max-model-len 2048

使用Docker Compose:

services:
  vllm:
    image: vllm/vllm-openai:latest
    command: ["--model", "AMead10/Llama-3.2-3B-Instruct-AWQ", "--max-model-len", "2048", "--quantization", "awq"]
    ports:
      - 8000:8000
    volumes:
      - ~/.cache/huggingface:/root/.cache/huggingface
    environment:
      - "HUGGING_FACE_HUB_TOKEN=<secret>"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

现在我们可以将本地的 LLM 与官方 OpenAI Python SDK 一起使用。

如果我们想使用官方 OpenAI 模型,只需更改base_url、api_key和model变量。


%pip install openai 

from openai import OpenAI 
client = OpenAI( 
    base_url= "http://localhost:8000/v1" , 
    api_key= "None" , 
) 

chat_completion = client.chat.completions.create( 
    messages=[ 
        { 
            "role" : "user" , 
            "content" : "Say this is a test" , 
        } 
    ], 
    model= "AMead10/Llama-3.2-3B-Instruct-AWQ" , 
)

让我们进行快速的健全性检查,看看一切是否按预期进行:

print(chat_completion.choices[ 0 ].message.content) 

“这似乎是一个测试。有什么具体的事情你想测试或讨论吗?我可以帮你。”

创建 RAG 评估数据集

在这里插入图片描述

我们加载文档并将上下文传递给生成器 LLM,生成器会生成问题和答案。问题、答案和上下文是传递给 LLM 评委的一个数据样本。然后,LLM 评委会生成质量分数,该分数可用于过滤掉不良样本。 自动从文档生成 RAG 评估数据样本的工作流程。图片由作者提供 自动生成 RAG 数据集的基本工作流程从从文档(例如 PDF 文件)读取我们的知识库开始。

然后我们要求生成器 LLM从给定的文档上下文生成问答对。

最后,我们使用评委 LLM进行质量控制。LLM 将为每个问答上下文样本打分,我们可以使用该分数来过滤掉不良样本。

为什么不使用像Ragas这样的框架来为 RAG 生成合成测试集?因为 Ragas 内部使用的是英语 LLM 提示。目前无法将 Ragas 与非英语文档一起使用。

我在本文中使用了 OpenAI 指南“RAG 评估” [2] 作为代码的基础。不过,我尝试简化他们的示例代码,并根据一些研究结果更改了评估 [3、4、5]。

读取文件

我们将使用 LangChain 读取包含所有文件的文件夹。

首先,我们需要安装所有必要的软件包。LangChain 的 DirectoryLoader 使用非结构化库来读取各种文件类型。在本文中,我将仅读取 PDF,以便我们可以安装较小版本的unstructured。

pip install langchain==0.3.6 langchain-community==0.3.4 unstructured[pdf]==0.16.3 tqdm

现在我们可以读取数据文件夹以获取 LangChain 文档。以下代码首先从文件夹中加载所有 PDF 文件,然后将它们分块为相对较大的 2000 个块。

from langchain_text_splitters.character import RecursiveCharacterTextSplitter
from langchain_community.document_loaders.directory import DirectoryLoader

loader = DirectoryLoader("/path/to/data/folder", glob="**/*.pdf", show_progress=True)
docs = loader.load()

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=2000,
    chunk_overlap=200,
    add_start_index=True,
    separators=["\n\n", "\n", ".", " ", ""],
)

docs_processed = []
for doc in docs:
    docs_processed.extend(text_splitter.split_documents([doc]))

结果是docs_processed包含类型的项目的列表Document。每个文档都有一些metadata和实际的page_content。

此文档列表是我们的知识库,我们将根据其上下文创建问答对page_content。

生成问答上下文样本

使用 OpenAI 客户端和我们之前创建的模型,我们首先编写一个生成器函数来从我们的文档中创建问题和答案。

def qa_generator_llm(context: str, client: OpenAI, model: str = "AMead10/Llama-3.2-3B-Instruct-AWQ"):
    generation_prompt = """
Your task is to write a factoid question and an answer given a context.
Your factoid question should be answerable with a specific, concise piece of factual information from the context.
Your factoid question should be formulated in the same style as questions users could ask in a search engine.
This means that your factoid question MUST NOT mention something like "according to the passage" or "context".

Provide your answer as follows:

Output:::
Factoid question: (your factoid question)
Answer: (your answer to the factoid question)

Now here is the context.

Context: {context}\n
Output:::"""

    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "system",
                "content": "You are a question-answer pair generator."
            },
            {
                "role": "user",
                "content": generation_prompt.format(context=context),
            }
        ],
        model=model,
        temperature=0.5,
        top_p=0.99,
        max_tokens=500
    )

    return chat_completion.choices[0].message.content

如果我们想使用英语以外的语言,我们将需要翻译generation_prompt(和系统指令)。

接下来,我们只需循环遍历知识库中的所有文档块,并为每个块生成一个问题和一个答案。

from tqdm.auto import tqdm

outputs = []
for doc in tqdm(docs_processed):
    # Generate QA couple
    output_QA = qa_generator_llm(doc.page_content, client)
    try:
        question = output_QA.split("Factoid question: ")[-1].split("Answer: ")[0]
        answer = output_QA.split("Answer: ")[-1]
        assert len(answer) < 500, "Answer is too long"
        outputs.append(
            {
                "context": doc.page_content,
                "question": question,
                "answer": answer,
                "source_doc": doc.metadata["source"],
            }
        )
    except Exception as e:
        print(e)

根据我们拥有的 PDF 文件数量,这可能需要一段时间。如有必要,请不要忘记翻译字符串output_QA.split。

为了生成 RAG 评估数据集,我使用了一份来自欧盟的关于欧盟 AI 法案监管的 PDF (根据CC BY 4.0许可)。这是我生成的原始outputs数据集:

[{'context': 'Official Journal of the European Union\n\n2024/1689\n\nREGULATION (EU) 2024/1689 OF THE EUROPEAN PARLIAMENT AND OF THE COUNCIL\n\nof 13 June 2024\n\nlaying down harmonised rules on artificial intelligence and amending Regulations (EC) No 300/2008, (EU) No 167/2013, (EU) No 168/2013, (EU) 2018/858, (EU) 2018/1139 and (EU) 2019/2144 and Directives 2014/90/EU, (EU) 2016/797 and (EU) 2020/1828 (Artificial Intelligence Act)\n\n(Text with EEA relevance)\n\nTHE EUROPEAN PARLIAMENT AND THE COUNCIL OF THE EUROPEAN UNION,\n\nHaving regard to the Treaty on the Functioning of the European Union, and in particular Articles 16 and 114 thereof,\n\nHaving regard to the proposal from the European Commission,\n\nAfter transmission of the draft legislative act to the national parliaments,\n\nHaving regard to the opinion of the European Economic and Social Committee (1),\n\nHaving regard to the opinion of the European Central Bank (2),\n\nHaving regard to the opinion of the Committee of the Regions (3),\n\nActing in accordance with the ordinary legislative procedure (4),\n\nWhereas:\n\n(1)',
  'question': 'What is the date on which Regulation (EU) 2024/1689 of the European Parliament and of the Council was laid down?\n',
  'answer': '13 June 2024',
  'source_doc': 'documents/OJ_L_202401689_EN_TXT.pdf'},
 {'context': 'Having regard to the opinion of the Committee of the Regions (3),\n\nActing in accordance with the ordinary legislative procedure (4),\n\nWhereas:\n\n(1)\n\nThe purpose of this Regulation is to improve the functioning of the internal market by laying down a uniform legal framework in particular for the development, the placing on the market, the putting into service and the use of artificial intelligence systems (AI systems) in the Union, in accordance with Union values, to promote the uptake of human centric and trustworthy artificial intelligence (AI) while ensuring a high level of protection of health, safety, fundamental rights as enshrined in the Charter of Fundamental Rights of the European Union (the ‘Charter’), including democracy, the rule of law and environmental protection, to protect against the harmful effects of AI systems in the Union, and to support innovation. This Regulation ensures the free movement, cross-border, of AI-based goods and services, thus preventing Member States from imposing restrictions on the development, marketing and use of AI systems, unless explicitly authorised by this Regulation.\n\n(2)\n\nThis Regulation should be applied in accordance with the values of the Union enshrined as in the Charter, facilitating the protection of natural persons, undertakings, democracy, the rule of law and environmental protection, while boosting innovation and employment and making the Union a leader in the uptake of trustworthy AI.\n\n(3)',
  'question': 'What is the purpose of the proposed Regulation on the development, placing on the market, putting into service, and use of artificial intelligence systems in the Union?\n',
  'answer': 'To improve the functioning of the internal market by laying down a uniform legal framework for the development, placing on the market, putting into service, and use of artificial intelligence systems in the Union.',
  'source_doc': 'documents/OJ_L_202401689_EN_TXT.pdf'},
 {'context': '(3)\n\nAI systems can be easily deployed in a large variety of sectors of the economy and many parts of society, including across borders, and can easily circulate throughout the Union. Certain Member States have already explored the adoption of national rules to ensure that AI is trustworthy and safe and is developed and used in accordance with fundamental rights obligations. Diverging national rules may lead to the fragmentation of the internal market and may decrease legal certainty for operators that develop, import or use AI systems. A consistent and high level of protection throughout the Union should therefore be ensured in order to achieve trustworthy AI, while divergences hampering the free circulation, innovation, deployment and the uptake of AI systems and related products and services within the internal market should be prevented by laying down uniform obligations for operators and\n\n(1) (2) (3) (4)\n\nOJ C 517, 22.12.2021, p. 56. OJ C 115, 11.3.2022, p. 5. OJ C 97, 28.2.2022, p. 60. Position of the European Parliament of 13 March 2024 (not yet published in the Official Journal) and decision of the Council of 21 May 2024.\n\nELI: http://data.europa.eu/eli/reg/2024/1689/oj\n\nEN L series\n\n12.7.2024\n\n1/144\n\nEN\n\n2/144\n\n(4)\n\n(5)\n\n(6)\n\n(7)\n\n(8)\n\n(5) (6)\n\nOJ L, 12.7.2024',
  'question': 'What is the official journal number for the regulation related to trustworthy AI, as of 12.7.2024?\n',
  'answer': '(4)',
  'source_doc': 'documents/OJ_L_202401689_EN_TXT.pdf'},
  ...
]

过滤掉错误的问答对

接下来,我们使用LLM 作为评判者,自动过滤掉坏样本。

当使用 LLM 学位作为评估样本质量的评判标准时,最好使用与生成样本时不同的模型,因为存在自我偏好偏差[6] —— 你不会给自己的论文评分,对吧?

在评判我们生成的问题和答案时,我们可以使用很多可能的提示。

为了构建我们的提示,我们可以使用G-Eval论文 [3]中的一个结构:

  • 我们从任务介绍( task introduction)开始
  • 我们提出了评估标准(evaluation criteria)
  • 我们希望模型能够进行思维链(CoT)推理 [7],以提高其性能
  • 我们最后要求总分

对于评估标准,我们可以使用一个列表,其中每个标准如果得到满足就会加一分。

评估标准应确保问题、答案和上下文相互契合、合理。

以下是 OpenAI RAG 评估手册中的两个评估标准 [2]:

  • 依据性:是否可以从给定的背景来回答该问题?
  • 独立:这个问题不需要任何背景就能理解吗?(为了避免出现这样的问题"What is the name of the function used in this guide?")

RAGAS 论文 [5] 中还有另外两个评估标准:

  • 忠实:答案应基于给定的背景
  • 答案相关性:答案应该解决实际提出的问题

我们可以尝试添加更多标准或更改我使用的标准文本。

该judge_llm()函数会批评问题、答案和上下文样本,并在最后得出总体评分:

def judge_llm(
    context: str,
    question: str,
    answer: str,
    client: OpenAI,
    model: str = "AMead10/Llama-3.2-3B-Instruct-AWQ",
):
    critique_prompt = """
You will be given a question, answer, and a context.
Your task is to provide a total rating using the additive point scoring system described below.
Points start at 0 and are accumulated based on the satisfaction of each evaluation criterion:

Evaluation Criteria:
- Groundedness: Can the question be answered from the given context? Add 1 point if the question can be answered from the context
- Stand-alone: Is the question understandable free of any context, for someone with domain knowledge/Internet access? Add 1 point if the question is independent and can stand alone.
- Faithfulness: The answer should be grounded in the given context. Add 1 point if the answer can be derived from the context
- Answer Relevance: The generated answer should address the actual question that was provided. Add 1 point if the answer actually answers the question

Provide your answer as follows:

Answer:::
Evaluation: (your rationale for the rating, as a text)
Total rating: (your rating, as a number between 0 and 4)

You MUST provide values for 'Evaluation:' and 'Total rating:' in your answer.

Now here are the question, answer, and context.

Question: {question}\n
Answer: {answer}\n
Context: {context}\n
Answer::: """

    chat_completion = client.chat.completions.create(
        messages=[
            {"role": "system", "content": "You are a neutral judge."},
            {
                "role": "user",
                "content": critique_prompt.format(
                    question=question, answer=answer, context=context
                ),
            },
        ],
        model=model,
        temperature=0.1,
        top_p=0.99,
        max_tokens=800
    )

    return chat_completion.choices[0].message.content

现在我们循环遍历生成的数据集并批评每个样本:

for output in tqdm(outputs):
    try:
        evaluation = judge_llm(
            context=output["context"],
            question=output["question"],
            answer=output["answer"],
            client=client,
        )
        score, eval = (
            int(evaluation.split("Total rating: ")[-1].strip()),
            evaluation.split("Total rating: ")[-2].split("Evaluation: ")[1],
        )
        output.update(
            {
                "score": score,
                "eval": eval
            }
        )
    except Exception as e:
        print(e)

让我们过滤掉所有坏样本。

由于生成的数据集将成为评估目的的基本事实,因此我们只应允许非常高质量的数据样本。这就是为什么我决定只保留得分最高的样本。

dataset = [doc for doc in outputs if doc["score"] >= 4]

以下是我们最终的 RAG 评估数据集(以 Pandas DataFrame 格式):

import pandas as pd

pd.set_option("display.max_colwidth", 200)

df = pd.DataFrame(dataset)
display(df)

在这里插入图片描述

我们生成的英语 RAG 评估数据集的可视化,包含以下列:上下文、问题、答案、源文档、分数和评估。

保存数据集

我们可以将 Pandas DataFrame 转换为 Hugging Face 数据集。然后,我们可以将其保存到磁盘并在需要时加载它。

%pip install datasets==3.0.2

# save
from datasets import Dataset
dataset = Dataset.from_pandas(df, split="test")
dataset.save_to_disk("path/to/dataset/directory")

# load
from datasets import load_dataset
dataset = load_dataset("path/to/dataset/directory")

我们还可以将数据集上传到Hugging Face Hub。

实验结论

从文档集合中自动创建 RAG 评估数据集非常简单。我们所需要的只是 LLM 生成器的提示、LLM 评委的提示,以及中间的一些 Python 代码。

要更改 RAG 评估数据集的域,我们只需交换提供给的文档DirectoryLoader。文档不必是 PDF 文件,也可以是 CSV 文件、markdown 文件等。

要更改我们的 RAG 评估数据集的语言,我们只需将 LLM 提示从英语翻译成另一种语言。

如果生成的数据样本不足以满足我们的用例,我们可以尝试修改提示。此外,使用更大、更好的 LLM 将提高数据集的质量。

如何学习AI大模型?

大模型时代,火爆出圈的LLM大模型让程序员们开始重新评估自己的本领。 “AI会取代那些行业?”“谁的饭碗又将不保了?”等问题热议不断。

不如成为「掌握AI工具的技术人」,毕竟AI时代,谁先尝试,谁就能占得先机!

想正式转到一些新兴的 AI 行业,不仅需要系统的学习AI大模型。同时也要跟已有的技能结合,辅助编程提效,或上手实操应用,增加自己的职场竞争力。

但是LLM相关的内容很多,现在网上的老课程老教材关于LLM又太少。所以现在小白入门就只能靠自学,学习成本和门槛很高

那么我作为一名热心肠的互联网老兵,我意识到有很多经验和知识值得分享给大家,希望可以帮助到更多学习大模型的人!至于能学习到多少就看你的学习毅力和能力了 。我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。

这份完整版的大模型 AI 学习资料已经上传优快云,朋友们如果需要可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】

👉 福利来袭优快云大礼包:《2025最全AI大模型学习资源包》免费分享,安全可点 👈

全套AGI大模型学习大纲+路线

AI大模型时代的学习之旅:从基础到前沿,掌握人工智能的核心技能!

img

640套AI大模型报告合集

这套包含640份报告的合集,涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师,还是对AI大模型感兴趣的爱好者,这套报告合集都将为您提供宝贵的信息和启示。

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

👉学会后的收获:👈
• 基于大模型全栈工程实现(前端、后端、产品经理、设计、数据分析等),通过这门课可获得不同能力;

• 能够利用大模型解决相关实际项目需求: 大数据时代,越来越多的企业和机构需要处理海量数据,利用大模型技术可以更好地处理这些数据,提高数据分析和决策的准确性。因此,掌握大模型应用开发技能,可以让程序员更好地应对实际项目需求;

• 基于大模型和企业数据AI应用开发,实现大模型理论、掌握GPU算力、硬件、LangChain开发框架和项目实战技能, 学会Fine-tuning垂直训练大模型(数据准备、数据蒸馏、大模型部署)一站式掌握;

• 能够完成时下热门大模型垂直领域模型训练能力,提高程序员的编码能力: 大模型应用开发需要掌握机器学习算法、深度学习框架等技术,这些技术的掌握可以提高程序员的编码能力和分析能力,让程序员更加熟练地编写高质量的代码。

👉 福利来袭优快云大礼包:《2025最全AI大模型学习资源包》免费分享,安全可点 👈

img

这份完整版的大模型 AI 学习资料已经上传优快云,朋友们如果需要可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】

作为普通人,入局大模型时代需要持续学习和实践,不断提高自己的技能和认知水平,同时也需要有责任感和伦理意识,为人工智能的健康发展贡献力量。

深度记忆在RAG系统中的应用:提高LLM检索准确性的实用指南 通过本文,我们展示了如何使用Activeloop的Deep Memory优化RAG系统,并通过实际的代码示例展示了如何提高检索准确性。 阅读详情

相关推荐

RAG评估方法-四种方法、两个自动化评估工具,中文/英文RAG评估数据集

RAG自动评估工具,RAG自动数据生成,RAG公开数据集,RAG中文数据集,RAG英文数据集

m0_46850835的博客 1万+

huggingface_hub 的 token 链接

无论你选择哪种方法,都可以获取模型的 token 链接,以便在自然语言处理任务中使用。"Hugging Face Hub"(也称为Hugging Face Model Hub)是一个用于分享和获取自然语言处理(NLP)模型和相关资源的平台。类来获取模型和分词器(tokenizer),并且从这些对象中提取 token 链接。如果你想手动构建 token 链接,可以使用分词器的 "convert_tokens_to_ids。这段代码将加载指定的模型和分词器,并通过分词器获取指定标记的 token 链接。

weixin_44912950的博客 2190

RAG知识库 Ragas效果评估框架

context_recall:是否检索到了回答问题所需的所有相关信息,提供的回答正确地解决了问题并与真实情况一致,表明上下文精度和召回率很高。faithfulness:生成答案的事实准确性,得分为 0.75,表明尽管答案大部分是准确的,但可能存在细微的不完整之处。answer_relevancy:生成答案与问题的相关性。相关性得分非常高(0.995013),表明答案与问题高度相关。context_precision:检索到的上下文的准确度。用的langchain,使用的deepseek模型。

weixin_42357472的博客 286

如何从文档构建自己的 RAG 评估数据集

在本文中,将展示如何创建自己的 RAG 数据集,该数据集包含任何语言的文档的上下文、问题和答案。检索增强生成 (RAG) [1] 是一种允许 LLM 访问外部知识库的技术。通过上传 PDF 文件并将其存储在矢量数据库中,我们可以通过矢量相似性搜索检索这些知识,然后将检索到的文本作为附加上下文插入到 LLM 提示中。这为LLM提供了新的知识,并减少了LLM编造事实(幻觉)的可能性。

Androiddddd的博客 1597

RAG文档资料,用于用llamaindex构建RAG的测试程序

RAG文档资料,用于用llamaindex构建RAG的测试程序

第二十三章 Nest集成日志框架Winston

Winston是一个非常流行的Node.js日志框架,而Nest.js是一个基于Node.js的后端框架。修改 winston.module.ts 内容如下 添加 forRoot 方法,接收 winston 的 createLogger 方法的参数,返回动态模块的 providers、exports。这里用到了 printf 的 format 函数,它可以自定义打印的日志格式 且使用了chalk 加上了颜色,并且打印了 dayjs 格式化的时间。可以看到控制台打印了自定义的 logger 的自定义。

枫ゞ的博客 1069

如何从文档构建自己的 RAG 评估数据集,看完这一篇你就懂了!!

检索增强生成 (RAG) 是一种允许 LLM 访问外部知识库的技术。 通过上传 PDF 文件并将其存储在矢量数据库中,我们可以通过矢量相似性搜索检索这些知识,然后将检索到的文本作为附加上下文插入到 LLM 提示中。 这为LLM提供了新的知识,并减少了LLM编造事实(幻觉)的可能性。

2401_85325557的博客 1314

线性回归做糖尿病分析(diabetes数据集),并分析单个特征值与病情的关系

1.diabetes数据集 共442个样本,每个样本有十个特征,分别是 [‘age’, ‘sex’, ‘bmi’, ‘bp’, ‘s1’, ‘s2’, ‘s3’, ‘s4’, ‘s5’, ‘s6’],对应年龄、性别、体质指数、平均血压、S1~S6一年后疾病级数指标。 Targets为一年后患疾病的定量指标,值在25到346之间。 ...

t18438605018的博客 1万+

自己写一个RAG应用

RAGRAG 是一个人工智能框架,用于从外部知识库中检索事实,使大型语言模型(LLM)基于最准确的最新信息,并让用户深入了解 LLM 的生成过程。大语言模型训练完后,其内部知识库就已经确定了,所以它无法回答你超过其知识库内容的问题。除非你有能力对其进行微调,否则最简单的方法就是使用RAG检索外部知识库。有人可能会认为,RAG是不是就是让模型在回答问题前先去指定的外部知识库检索一下知识,然后再回答?

阿不的博客 1116

EDA开源仿真工具verilator入门4:访问函数介绍

访问函数(Visitor Function)是verilator算法实现的主要工作方式之一,本节将介绍一下访问函数。

fangfanglovezhou的博客 1075

激光雷达点云可视化:Open3D与PCL实战

激光雷达点云可视化:Open3D与PCL实战 ,人工智能,计算机视觉,大模型,AI,该文围绕激光雷达点云可视化,介绍了Open3D与PCL的实战应用。先阐述点云基础概念、特点及可视化意义,接着讲解Open3D的简介、环境配置,以及其在点云读取、显示、颜色设置、下采样和滤波等方面的实战操作,还介绍了PCL的基础、环境配置及相关实战,包括点云读取、显示、颜色设置、下采样和滤波,同时对比了两者的易用性、功能覆盖、性能和适用场景,给出综合实战案例与常见问题解决方法,为点云可视化处理提供了全面指导。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 12万+

【AI大模型】如何从文档创建 RAG 评估数据集,收藏这一篇就够了!!

检索增强生成 (RAG) [1] 是一种允许 LLM 访问外部知识库的技术。 通过上传 PDF 文件并将其存储在矢量数据库中,我们可以通过矢量相似性搜索检索这些知识,然后将检索到的文本作为附加上下文插入到 LLM 提示中。 这为LLM提供了新的知识,并减少了LLM编造事实(幻觉)的可能性。

2401_85327249的博客 1241

Palantir 凭什么两年涨 20 倍?深度解析解决 AI 幻觉的 “本体论“ 核心原理

本文深度解析了Palantir本体(Ontology)的核心原理及其在企业AI应用中的革命性价值。本体通过构建结构化的语义层与动态执行层,将企业分散的数字资产(数据集、虚拟表、模型)映射为现实世界的数字孪生,使大模型能够在**严格的业务规则与数据边界内**进行推理与决策,从而从架构层面彻底解决AI幻觉问题。这一技术架构不仅帮助Palantir实现股价两年增长20倍、市值突破4000亿美金的商业成功,更成为SAP、Salesforce等ERP巨头争相模仿的下一代企业智能标准范式。通过航空业飞机故障应急处理等实

program哲学 225

【RAG】21-RAG评估工具与数据集:列出RAG评估的工具和数据集,用于评估RAG的资源汇总

通过使用这些评估工具和数据集,研究人员可以系统地分析RAG系统的性能瓶颈,发现潜在问题,并针对性地进行技术迭代。这不仅有助于提升RAG系统的整体性能,还能推动相关领域的学术研究和产业应用向更高水平发展。因此,梳理和汇总RAG评估的工具和数据集,对于推动RAG技术的进步具有重要意义。

rengang66的博客 727

【RKNN】RKNN(Rockchip Neural Network)​​ 的详解

RKNN 为 Rockchip 硬件提供了高效的 AI 推理解决方案,适合需要低功耗、实时响应的边缘场景

浩瀚之水的专栏 1685

手把手教你学PCIE(11.3)--pcie的认证和合规性测试

PCIe 设备的认证和合规性测试是确保设备正常工作和达到预期性能的关键步骤。通过使用 PCI-SIG 提供的测试工具和第三方测试工具,可以全面评估 PCIe 设备的物理层、链路层、事务层和互操作性,确保设备符合行业标准和规范。

MHD0815的博客 1360

全网最全RAG评估指南:全面解析RAG评估指标并提供代码示例

最近我一直在关注和优化RAG(Retrieval-Augmented Generation)相关的内容,总结了一下RAG的痛点和最佳实践,然后重点会介绍如何评估RAG。

zhishi0000的博客 1万+

Mamba-YOLOv8深度解析:基于状态空间模型的下一代目标检测架构(含完整代码与实战部署)文末含资料链接!

通过本文的完整指南,您将掌握从理论创新到工程落地的全流程技术细节。立即动手实践,开启目标检测的新纪元!

FJN110的博客 519

RAG评估方法-四种方法、两个自动化评估工具,中文/英文RAG评估数据集_rag评估工具

现有RAG模型的评估主要强调三个主要质量分数和四个基本能力,它们共同决定了RAG模型的两个主要目标的评估:检索和生成。质量分数:上下文相关性(Context Relevance)、答案真实性(Answer Faithfulness)和答案相关性(Answer Relevance)。

python1222_的博客 3047

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【RAG评估】综述:一文了解RAG评估方法、工具与指标

前面我们学习了RAG的基本框架并进行了实践,我们也知道使用它的目的是为了改善大模型在一些方面的不足:如训练数据不全、无垂直领域数据、容易出现幻觉等。

DEVELOPERAA的博客 5754

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

更多文档,相同长度:隔离RAG中多文档的挑战

我们还公开了数据集和代码。MuSiQue的设计使得问题可以根据其中几个输入文档(2-4个)来回答,而其他文档则作为检索场景中的现实干扰因素,因为它们围绕问题的主题,但不包含回答问题所需的信息。我们发现,从MuSiQue (Trivedi 等人 2022) 构建的自定义集合提供了一个方便的近似值,使我们能够在受控环境中探索长上下文和多文档理解之间的关系,同时使用真实世界的文本。我们的结果表明,在检索设置的环境中,包含更多文档的输入会使任务复杂化,突显了检索系统需要平衡相关性和多样性以最小化冲突的需求。

栖客 1127

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

清华:基于LLM的RAG评估数据集生成框架

现有的RAG评估基准在评估垂直领域的RAG模型,面临可靠性的挑战。论文提出了一个名为RAGEval的全面评估框架,用于自动生成特定场景下的RAG评估数据集,并引入了新的评估指标来提高评估的准确性和可靠性。

大模型任我行的博客 1625
上一篇: RAG 基本流程及处理技巧 with LangChain
下一篇: AI大模型标注:你看不上的数据标注正在成为高薪工作
爱喝白开水a
博客等级 码龄3年 6793粉丝 763原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值