关于chatgpt:从-GPT4All-体验-LLM

5次阅读

共计 5639 个字符,预计需要花费 15 分钟才能阅读完成。

大型语言模型最近变得流行起来。ChatGPT 很时尚。尝试 ChatGPT 以理解 LLM 的内容很容易,但有时,您可能须要一个能够在您的计算机上运行的离线代替计划。在这篇文章中,您将理解 GPT4All 作为能够装置在计算机上的 LLM。

举荐:应用 NSDT 场景编辑器助你疾速搭建可编辑的 3D 利用场景

什么是 GPT4All?

术语“GPT”源自 Radford 等人 2018 年论文的题目“通过生成预训练进步语言了解”。本文形容了如何证实变压器模型可能了解人类语言。

从那时起,许多人尝试应用转换器架构开发语言模型,并且曾经发现足够大的模型能够给出杰出的后果。然而,开发的许多模型都是专有的。有付费订阅的服务或具备某些限度条款的许可证。因为尺寸的起因,有些甚至无奈在商用硬件上运行。

GPT4All 我的项目试图在通用硬件上向公众提供 LLM。它容许你训练和部署模型。还提供预训练模型,其尺寸较小,能够在 CPU 上正当运行。

如何获取 GPT4All

让咱们只关注应用事后训练的模型。

在撰写本文时,GPT4All 可从 https://gpt4all.io/index.html 取得,您能够将其作为桌面应用程序或应用 Python 库运行。您能够下载操作系统的安装程序以运行桌面客户端。客户端只有几百 MB。您应该会看到一个装置屏幕,如下所示:

装置客户端后,首次启动它将提醒您装置模型,该模型能够大至数 GB。首先,您能够抉择“”(GPT4All-J 型号)。这是一个绝对较小但风行的模型。gpt4all-j-v1.3-groovy

客户端和模型准备就绪后,您能够在输入框中键入音讯。该模型可能冀望特定模式的输出,例如,特定的语言或款式。该模型须要对话格调(如 ChatGPT),并且通常能够很好地解决英语。例如,上面是它如何响应输出“给我 10 种颜色及其 RGB 代码的列表”:

如何在 Python 中应用 GPT4All

GPT4All 的要害组件是模型。桌面客户端只是它的接口。除了客户端,您还能够通过 Python 库调用模型。

不出所料,该库被命名为“”,“,您能够应用以下命令装置它:gpt4all pip
pip install gpt4all
之后,您只需几行代码即可在 Python 中应用它:

import gpt4all 
gptj = gpt4all.GPT4All("ggml-gpt4all-j-v1.3-groovy")
messages = [{"role": "user", "content": "Give me a list of 10 colors and their RGB code"}]
ret = gptj.chat_completion(messages)
print(ret)

运行上述代码将下载模型文件(如果尚未下载)。之后,加载模型,提供输出,并将响应作为 Python 字典返回,如下所示:

{'model': 'ggml-gpt4all-j-v1.3-groovy', 
'usage': {'prompt_tokens': 272,
           'completion_tokens': 301,
           'total_tokens': 573},
 'choices': [
    {'message':
        {'role': 'assistant',
         'content': 'Here is a list of 10 colors and their RGB code:Red (255, 0, 0)  Green (0, 255, 0) Blue (0, 0, 255)  Yellow (255, 255, 0) Orange (255, 127, 0)  Purple (0, 128, 255) Pink (255, 192, 203)  Blue-Green (0, 0, 255)  Green-Blue (0, 0, 255)  Blue-Purple (0, 0, 255)  Blue-Green (0, 0, 255)  Blue-Purple (0, 0'}
    }
 ]
}

下面的示例应用输出作为一个字典的列表。更简单的输出是许多字典的列表,每个字典都蕴含键和 . 能够是、或,而 是文本字符串。如果您应用的是 GPT4All-J 模型(如示例所示),则您的角色是在计算机 . 输出应该是这两方之间的一系列对话。以下是逐渐构建对话的办法:

rolecontentrole”system””assistant””user”content”user””assistant”

import json
import gpt4all

 gptj = gpt4all.GPT4All("ggml-gpt4all-j-v1.3-groovy")
messages = [{"role": "user", "content": "Can you explain what is a large language model?"}]
ret = gptj.chat_completion(messages) messages.append(ret["choices"][0]["message"])

messages.append({"role": "user", "content": "Can you give some examples applications?"})
ret = gptj.chat_completion(messages)

 messages.append(ret["choices"][0]["message"])
messages.append({"role": "user", "content": "Are there any limitations?"})
ret = gptj.chat_completion(messages)

 messages.append(ret["choices"][0]["message"])
messages.append({"role": "user", "content": "Summarize the above in two sentences."})
ret = gptj.chat_completion(messages)

 print(json.dumps(messages, indent=4))
print(json.dumps(ret, indent=4))

请留神,您屡次调用了该模型。每次它响应时,您都会获取输入并将其附加到音讯列表中,以便累积上下文。而后,增加新对话框并再次调用该模型。您须要收集音讯,因为每次调用模型时,它都会在不晓得上一个对话的状况下从新开始。因而,您的工作是保留历史记录以揭示模型其先前的反馈。

上面是上述代码输入的示例,其中打印了模型的最初一个输出音讯及其响应。您可能会从另一个模型中取得更好的后果。因为模型中的随机性,您还可能会失去不同的后果:

[
    {
        "role": "user",
        "content": "Can you explain what is a large language model?"
    },
    {
        "role": "assistant",
        "content": "A large language model is a type of artificial intelligence that can process and understand natural language, such as speech or text. It is trained on large amounts of data and can perform tasks such as language translation, sentiment analysis or even answering questions. Large language models are becoming increasingly popular in various industries, including finance and healthcare."
    },
    {
        "role": "user",
        "content": "Can you give some examples applications?"
    },
    {
        "role": "assistant",
        "content": "Large language models are being used in a variety of applications, such as:- Language translation and machine translation, where large language models are trained on vast amounts of data to improve accuracy and speed.- Sentiment analysis, where large language models are trained to analyze social media data and identify patterns in user opinions.- Question answering, where large language models are trained to answer questions based on a large corpus of data.- Healthcare, where large language models are being used to analyze patient data and identify patterns in health trends.- Finance, where large language models are being used to analyze financial data and identify patterns in"
    },
    {
        "role": "user",
        "content": "Are there any limitations?"
    },
    {
        "role": "assistant",
        "content": "Yes, there are some limitations to large language models. One of the main challenges is that they require a lot of data to train, which can be expensive and time-consuming. Additionally, large language models can be computationally expensive and may require specialized hardware to run. Another limitation is that large language models may not be able to understand the nuances of human language, which can make them less effective in certain situations. Finally, large language models may not be able to understand the context of a conversation or text, which can make them less effective in certain applications."
    },
    {
        "role": "user",
        "content": "Summarize the above in two sentences."
    }
]
{
    "model": "ggml-gpt4all-j-v1.3-groovy",
    "usage": {
        "prompt_tokens": 2113,
        "completion_tokens": 542,
        "total_tokens": 2655
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "Large language models are a type of artificial intelligence that can process and understand natural language, such as speech or text. They are trained on large amounts of data and can perform tasks such as language translation, sentiment analysis or even answering questions. They are becoming increasingly popular in various industries, including finance and healthcare. However, there are some limitations such as expensive data and specialized hardware, computational expense, lack of understanding nuances in human language and context."
            }
        }
    ]
}

总结

GPT4All 是一个不错的工具,您能够在计算机上应用。它容许您摸索与大型语言模型的交互,并帮忙您更好地理解模型的性能和限度。在这篇文章中,您理解到:

  • GPT4All 有一个桌面客户端,您能够将其装置在计算机上
  • GPT4All 有一个 Python 接口,容许您在代码中与语言模型进行交互
  • 有多种语言模型可用

原文链接:https://www.mvrlink.com/experience-llm-from-gpt4all/

正文完
 0