首页/文章/ 详情

PrivateGPT | 使用自定义大语言模型部署私有知识库(安装+测试)

8月前浏览1992
1 引言

ChatGPT的诞生诱发出许多开源大语言模型产品,从而可以让所有人本地部署私有知识库,GPT4all便是其中一个,GPT4all的优点是不需要使用GPU即可运行,本公 众 号曾经有两篇文章讨论过GPT4all,参看【GPT4all---本地部署的微型大语言模型】和【号称性能最好的开源大语言模型测试---l13b-snoozy】。基于GPT4all,可以在本地部署私有化的PrivateGPT,这意味着用户能够在不联网的情况下在本机上使用自己的知识库。本文描述了安装这个应用程序的步骤,并用自己的数据进行了测试。

PrivateGPT使用的库包括LangChain【LangChain---大型语言模型(LLM)的标准接口】, GPT4All, LlamaCpp, Chroma以及SentenceTransformers【SentenceTransformers库更新V2.0.0】。

2 预安装软件

为了安装PrivateGPT,必须预先安装下面两个软件:
(1) Visual Studio Code,用来部署和调式PrivateGPT;
(2) git,用来从github克隆载源码。 

3 安装步骤

(1) 首先打开Visual Studio Code, 使用File>New Window建立新窗口,然后在终端(Terminal)下转换到desktop目录;
(2) 使用命令git clone privateGPT.git, 从github上拷贝源代码,从而建立了privateGPT子目录;
(3) 进入privateGPT子目录,执行如下命令安装所有需要的库。
    pip install -r requirements.txt

    (4) 把默认的文件名example.env改为.env,这个文件用来设置模型:

      PERSIST_DIRECTORY=dbMODEL_TYPE=GPT4AllMODEL_PATH=models/ggml-gpt4all-l13b-snoozy.binEMBEDDINGS_MODEL_NAME=all-MiniLM-L6-v2MODEL_N_CTX=1000MODEL_N_BATCH=8TARGET_SOURCE_CHUNKS=4
      (5) 模型使用先前的ggml-gpt4all-l13b-snoozy.bin,这个文件尺寸大约8G,建立一个新的文件夹models,把这个bin文件放入models文件夹内。
      (6) 把需要训练的文档放入source_documents文件夹内,在此放入了3个txt文件和2个pdf文件。
      (7) 执行ingest.py,产生数据库。这个代码使用了LangChain库,参看文章【LangChain---大型语言模型(LLM)的标准接口使用大语言模型实现与岩土数据集GeotechSet的对话---DFN试验
        from langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.vectorstores import Chromafrom langchain.embeddings import HuggingFaceEmbeddingsfrom langchain.docstore.document import Document

        (8) 执行privateGPT.py产生用户交互。

        4 初步测试
        【1】问:What is static liquefaction?
        回答:Static liquefaction【使用非排干脆性指数粗略估算静态液化(undrained brittleness index)】 refers to the phenomenon where tailings materials can exhibit liquid-like behavior under certain conditions, such as during earthquakes or other disturbances, leading to a loss of structural integrity in the dam. It has historically received less attention than seismic-induced liquefaction but may be beneficial for studies on liquefaction and tailings dams静力和地震荷载下尾矿坝的稳定性】.(静态液化是指尾矿材料在某些条件下(例如在地震或其他扰动期间)表现出类似液体的行为,导致坝体结构完整性丧失的现象。历史上,它比地震引起的液化受到的关注较少,但可能有益于液化和尾矿坝的研究。)
        Liquidity and Liquefaction: Tailings materials can sometimes exhibit liquid-like behavior under certain conditions, a phenomenon known as liquefaction. This can occur during earthquakes or other disturbances, leading to a loss of structural integrity in the dam. Engineering measures are taken to prevent or mitigate the effects of liquefaction.(流动性和液化:尾矿材料有时在某些条件下会表现出类似液体的行为,这种现象称为液化。这种情况可能发生在地震或其他扰动期间,导致坝体结构完整性丧失。采取工程措施来防止或减轻液化的影响。)【什么是流动液化(flow liquefaction)
        5 增加数据集
        在上述5个文件的基础之上,随机增加了17个pdf文件,重新建立数据集。然后问了相同的问题:
        【1】问:What is static liquefaction?
        回答:Static liquefaction refers to a phenomenon in which soil or other granular materials become fluid-like due to the application of external forces such as pressure. It can occur without any seismic activity and has been studied extensively for its potential impact on tailings dams, particularly those containing fine-grained sediments that are prone to liquefaction under static loads.(静态液化是指土或其他颗粒状物质由于施加压力等外力而变成流体状的现象。它可以在没有任何地震活动的情况下发生,并且因其对尾矿坝的潜在影响而被广泛研究,特别是那些含有在静载荷下容易液化的细粒沉积物的尾矿坝。)
        NorSand本构模型(Jefferies 1993)【FLAC3D的NorSand模型是当前基于力学的静态液化的基础(Jefferies & Been, 2015),在最近 的TSF破坏研究中得到了应用(Morgenstern 等人,2016;Morgenstern 等人,2019 ;Robertson 等人,2019 年)。NorSand的基础是临界状态理论[Tailing dams – slow responses to risks long known.]。
        【2】问:Explain Stability of tailings dams under static and seismic loading.
        回答: 

        This article discusses the stability of tailings dams under both static and seismic loading conditions. Tailings dams are earth structures that store waste materials from mining operations, but have been known to fail in recent years due to their unstable nature. The authors conducted a study using two-dimensional finite element analysis to investigate the behavior and stability of these types of dams under different loads. Their findings suggest that tailings dams can be made more stable through proper design and construction techniques, as well as regular monitoring and maintenance practices.(本文讨论了静力和地震荷载条件下尾矿坝的稳定性。尾矿坝是储存采矿作业废料的土结构,但近年来由于其不稳定的性质而破坏。作者使用二维有限元分析进行了一项研究,以研究这些类型的坝体在不同荷载下的行为和稳定性。他们的研究结果表明,通过适当的设计和施工技术以及定期监测和维护实践,可以使尾矿坝更加稳定。)

        过去几十年来,随着世界范围内发生大量尾矿坝溃坝事件,尾矿坝的稳定性引起了广泛关注。本研究的重点是研究这种土结构在静态和动态荷载下的行为和稳定性。Psarropoulos, P. N. and Y. Tsompanakis (2008) Stability of tailings dams under static and seismic loading. Canadian Geotechnical Journal 45(5): 663-675.【地震载荷作用下的边坡稳定性分析(Seismic Loading)

        【3】问:What is Mount Polley tailings dam failure?
        回答: The Mount Polley tailings dam failure【能精确预警尾矿坝的溃坝吗?|波利山(Mount Polley)尾矿坝事故调查】 refers to the breach of the tailings dam at the Mount Polley mine in British Columbia, Canada, which resulted in a release of millions of cubic meters of water and tailings into nearby waterways. This incident led to an investigation and review of tailings dam design, construction, and management practices worldwide. (波利山尾矿坝溃坝是指加拿大不列颠哥伦比亚省波利山矿尾矿坝溃决,导致数百万立方米的水和尾矿泄漏到附近水道中。这一事件引发了对全球尾矿坝设计、施工和管理实践的调查和审查。)  (A new look at the statistics of tailings dam failures)。
        来源:计算岩土力学
        岩土理论FLAC3D材料试验
        著作权归作者所有,欢迎分享,未经许可,不得转载
        首次发布时间:2023-09-11
        最近编辑:8月前
        计算岩土力学
        传播岩土工程教育理念、工程分析...
        获赞 123粉丝 881文章 1732课程 0
        点赞
        收藏
        未登录
        还没有评论

        课程
        培训
        服务
        行家

        VIP会员 学习 福利任务 兑换礼品
        下载APP
        联系我们
        帮助与反馈