Giter Site home page Giter Site logo

nlp_rag_demo's Introduction

Retrieval Augmented Generation (RAG) Intro Project 🤖🔍📝

RAG教学示例项目

  1. 项目使用了LlamaIndex框架演示了RAG的基本流程,也欢迎使用其它框架如LangChain等进行实验。
  2. 项目主体来自Retrieval-Augmented-Generation-Intro-Project,本项目对llama_index的最新版本进行了适配。
  3. 项目使用了百度千帆提供的Yi-34B-Chat的接口(限时免费,需自行申请API Key和Secret Key),也可尝试使用其它免费的API如阿里云,需在代码中相应位置做替换。

Project Structure 📂

  • README.md: 项目总览

  • code: 文件夹下包含三个教学实验,三个实验均有各自对应.ipynb,.py以及.sh可直接运行;同时提供了KDD CUP 2024 CRAG: Comprehensive Rag Benchmark使用的训练数据和评测脚本。

    • 1_Basic_RAG_Pipeline: RAG基础的pipeline演示 image

    • 2_Sentence_window_retrieval: 将文档拆分成小的组块(chunk),将检索结果的上下文都拼接到prompt中

    • 3_Auto-merging_Retrieval: 将文档按照块大小拆分成不同层级的节点,在检索时使用叶子节点检索,然后检查父节点包含的子节点中被检索到的比例,高于一定阈值时将父节点作为检索结果,否则将被检索到的子节点作为检索结果,AutoMergingRetrieval的详细介绍可参考 https://zhaozhiming.github.io/2024/03/19/auto-merging-rag/ image

    • model_response.py: 提供了API访问和本地部署LLM两种方式,选择本地部署的同学可以进一步改造代码,使用vllm框架加速推理

    • crag.sh: KDD CUP 2024 CRAG: Comprehensive Rag Benchmark使用的训练数据

    • metric.py: 评测脚本,计算模型生成内容与标准答案的BLEU和Rouge-l指标

  • data: 实验所需的语料,包括

Getting Started 🚀

  1. 克隆或下载项目仓库到本地:
  git clone https://github.com/ZhaoFangkun1/NLP_RAG_Demo.git
  1. 准备环境
  conda create -n rag python=3.10
  conda activate rag
  pip install llama_index
  pip install llama-index-embeddings-huggingface
  1. 进入code文件夹,依次运行三种实验脚本
cd code
1. sh Basic_RAG_Pipeline.sh
2. sh Sentence_window_retrieval.sh
3. sh Auto-merging_Retrieval.sh
  1. 更改数据为提供的CRAG数据集进行测试,同时也可尝试其它的数据集
sh crag.sh
python metric.py
  1. 鼓励进行模型训练或流程上的改进

项目要求:下面三项内容,至少选择其二开展进一步探索并完成实验报告

  1. 检索策略优化:尝试更多的组块拆分策略,以及更好的检索算法和重排算法
  2. 微调BGE的检索或(和)重排模型:
    • 自行将CRAG全量训练集进行划分,微调BGE检索以及重排模型,可参考 https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/finetune/README.md
    • 微调时需要构造query对应的chunk正负样例,但是CRAG数据集并未给出query对应的chunk正例(只给出了与每个query可能相关的网页、每个query对应的答案),因此需要设计方案为query构造正例(除人工标注外,还可通过prompt LLM进行query和chunk的相关性判定)
  3. 对LLM进行进一步预训练或微调:
    • 根据自己的算力情况,使用给定的CRAG数据对LLM做进一步的预训练或有监督微调
    • 对使用的LLM框架不做限制,可参考llama-factory,megatron-lm框架,以及阿里进行二次封装之后的Pai-Megatron-Patch框架

nlp_rag_demo's People

Contributors

zhaofangkun1 avatar yuanmm8 avatar yelloworange10 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.