20230515LLM笔记

0.前言

先叠个盾:我AI水平有限,哪写的不对欢迎大佬指正。

1.原理

LLM是根据上文预测下一个最大可能性的token,直到语句结束或超长。常见的对话只是表现形式的一种,实际运行的原理是对文本的补全预测。
关于部分人对于模型表现出的行为产生了偏离实际的想法,需要强调现在的模型还没有记忆,时刻记得无论输出什么内容,即使行为再像一个人,它也依旧是静态的
训练数据里是把对话作为整体的,因此当你输入的内容被拼接成训练数据里的前半部分,模型就会根据输入补全后面的内容,这部分内容再以回复的形式展现到聊天框。下一句你发送的内容的前面会被拼接上之前所有的历史记录输入到模型中进行下一次预测,表现出的记忆能力是这样做到的,并不是模型本身有记忆。

2.prompt方案

2.1.Input-output (IO) prompting

最原始的prompt方法,直接向模型输入prompt,并得到输出

2.2.embedding + 向量数据库

当输入的prompt超过模型长度限制后,一个方向是增加模型的context,比如GPT4能到32k,实测足够传递很长的信息给它了,但如果还不够
另一个方向就是缩减prompt的长度。
embedding可以使文本转为向量,利用向量数据库存储大量内容,在构造prompt时使用向量搜索相关信息动态拼接prompt,可以用来减少prompt长度完成大容量知识库的搜索
早在2018毕业的时候就有同学使用word2vec生成词向量并做文本的情感分析,原理类似。
但这里有问题需要注意,词向量本身有个维度是N,一个句子会被分为多个词,怎么把句子转成一个向量需要根据不同场景选择策略
例如CoSENT(Cosine Sentence) model可以做到将句子映射到768维的稠密向量
以下是GPT的回答
Based on the description you provided, the “CoSENT” or “Cosine Sentence” model appears to be a sentence encoder that maps sentences into a 768-dimensional dense vector space. This type of model is often used for tasks such as sentence embeddings, text matching, or semantic search.
Sentence embedding models like “CoSENT” aim to capture the semantic meaning of sentences and represent them as fixed-length vectors in a high-dimensional space. These vectors can then be used for various natural language processing tasks, including similarity comparison, clustering, or retrieval.
While I’m not familiar with the specific details and architecture of the “CoSENT” model, based on the functionality you described, it seems to fall under the category of language models. Language models, including both generative models like ChatGPT and encoder models like “CoSENT,” contribute to the broader field of natural language processing and understanding.

参考资料

https://github.com/facebookresearch/dinov2
常见的向量数据库 https://python.langchain.com/en/latest/modules/indexes/vectorstores.html

3.prompt技巧

3.1.通用技巧

清晰的描述问题,包括合理使用界符分隔数据和指令

3.2.few-shot prompting

在prompt中提供部分例子可以得到更好的效果
Language models are few-shot learners. NeurIPS.
https://proceedings.neurips.cc/paper/2020/file/1457c0d6bfcb4967418bfb8ac142f64a-Paper.pdf
https://zhuanlan.zhihu.com/p/200978538

3.2.CoT prompting

在prompt中说明请逐步思考并提供部分示例
英文let’s think step by step
Chain of Thought https://arxiv.org/pdf/2203.11171.pdf

Self-consistency with CoT (CoT-SC)

https://arxiv.org/pdf/2203.11171.pdf
https://zhuanlan.zhihu.com/p/609739922

采样方法

temperature sampling (Ackley et al., 1985; Ficler & Goldberg, 2017),
top-k sampling (Fanet al., 2018; Holtzman et al., 2018; Radford et al., 2019)
nucleus sampling (Holtzman et al.2020)
Sample-and-Rank
Beam Search
Ensemble-based Approaches
概率论概念:
边缘化 https://cloud.tencent.com/developer/article/1096441

Auto CoT

为了缓解手动设计的困难,Auto-CoT方法自动构建具有questions和reasons chains的演示。

3.3.USP 自适应prompt

一个通用的自适应prompt方法,突破了零样本学习的瓶颈

  • 谷歌提出了一种 Universal Self-adaptive Prompting (USP) 方法,对LLMs的零样本学习进行了优化,同时也适用于少样本学习任务。USP只需要少量未标记的数据,就能大幅提升LLMs在20多个自然语言理解和生成任务上的表现。实际上,结果比起少样本基线方法甚至更好!
  • 论文:Universal Self-adaptive Prompting

4.能力扩充

4.1.和外界交互的能力

Toolformer
https://arxiv.org/pdf/2302.04761.pdf
On the other hand, recent work has explored the use of pre-trained language models for planning and acting in interactive environments (Ahn et al., 2022; Nakano et al., 2021; Yao et al., 2020; Huang et al., 2022a),

4.2.支持AI自主制造工具

待收集资料+测试
https://arxiv.org/pdf/2305.17126.pdf

5.多次prompt组合调度

5.1.ToT 增加回溯、全局计划能力

https://arxiv.org/pdf/2305.10601.pdf
https://github.com/ysymyth/tree-of-thought-llm

3.2.ReAct范式

Thought Act Observation,让AI思考、行动、观察并重复这个过程
https://arxiv.org/abs/2210.03629

5.3.多步骤推理自动生成框架ART

《ART: Automatic multi-step reasoning and tool-use for large language models》
https://link.zhihu.com/?target=https%3A//arxiv.org/abs/2303.09014

6.服务层实现框架

6.1.LangChain增加调度逻辑、支持外部工具调用

https://github.com/hwchase17/langchain
https://liaokong.gitbook.io/llm-kai-fa-jiao-cheng/#vectorstores-xiang-liang-shu-ju-ku
https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/chroma.html#persistance
SayCan dataset (Ahn et al., 2022) 包含自然语言指令 到 机器人动作序列 的映射

参考

https://wqw547243068.github.io/prompt

0 Comments
Leave a Reply