小智头像图片
AI教程 2025年01月17日
0 收藏 0 点赞 461 浏览 5594 个字
摘要 :

面向开发者的LLM入门教程-问答英文版: 英文版 1.加载向量数据库 from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddin……

哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门教程-问答英文版”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。

面向开发者的LLM入门教程-问答英文版

面向开发者的LLM入门教程-问答英文版:

英文版

1.加载向量数据库

from langchain.vectorstores import Chroma
from langchain.embeddings.openai import OpenAIEmbeddings
persist_directory = ‘docs/chroma/cs229_lectures/’
embedding = OpenAIEmbeddings()
vectordb = Chroma(persist_directory=persist_directory,
embedding_function=embedding)

print(vectordb._collection.count())

209

向量检索

question = “What are major topics for this class?”
docs = vectordb.similarity_search(question,k=3)
print(len(docs))

3

2.构造检索式问答链

# 使用 ChatGPT3.5,温度设置为0
from langchain.chat_models import ChatOpenAI

# 导入检索式问答链
from langchain.chains import RetrievalQA

llm = ChatOpenAI(model_name=llm_name, temperature=0)

# 声明一个检索式问答链
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever()
)

# 可以以该方式进行检索问答
question = “What are major topics for this class?”
result = qa_chain({“query”: question})
print(result[“result”])

The context does not provide a clear answer to this question.

3.基于模板的检索式问答链

from langchain.prompts import PromptTemplate

# Build prompt
template = “””Use the following pieces of context to answer the question at the
end. If you don’t know the answer, just say that you don’t know, don’t try to
make up an answer. Use three sentences maximum. Keep the answer as concise as
possible. Always say “thanks for asking!” at the end of the answer.
{context}
Question: {question}
Helpful Answer:”””
QA_CHAIN_PROMPT = PromptTemplate.from_template(template)
# Run chain
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever(),
return_source_documents=True,
chain_type_kwargs={“prompt”: QA_CHAIN_PROMPT}
)

question = “Is probability a class topic?”
result = qa_chain({“query”: question})
print(“ANswering:”)
print(result[“result”])
print(“Source document: “)
print(result[“source_documents”][0])

ANswering:
Yes, probability is assumed to be a prerequisite for this class. The instructor
assumes familiarity with basic probability and statistics, and will go over some
of the prerequisites in the discussion sections as a refresher course. Thanks for
asking!
Source document:
page_content=”of this class will not be very program ming intensive, although we
will do some nprogramming, mostly in either MATLAB or Octa ve. I’ll say a bit
more about that later. nI also assume familiarity with basic proba bility and
statistics. So most undergraduate nstatistics class, like Stat 116 taught here
at Stanford, will be more than enough. I’m gonna nassume all of you know what ra
ndom variables are, that all of you know what expectation nis, what a variance
or a random variable is. And in case of some of you, it’s been a while nsince
you’ve seen some of this material. At some of the discussion sections, we’ll
actually ngo over some of the prerequisites, sort of as a refresher course
under prerequisite class. nI’ll say a bit more about that later as well.
nLastly, I also assume familiarity with basi c linear algebra. And again, most
undergraduate nlinear algebra courses are more than enough. So if you’ve taken
courses like Math 51, n103, Math 113 or CS205 at Stanford, that would be more
than enough. Basically, I’m ngonna assume that all of you know what matrix es
and vectors are, that you know how to nmultiply matrices and vectors and
multiply matrix and matrices, that you know what a matrix inverse is. If you know
what an eigenvect or of a matrix is, that’d be even better. nBut if you don’t
quite know or if you’re not qu ite sure, that’s fine, too. We’ll go over it in
nthe review sections.” metadata={‘source’: ‘docs/cs229_lectures/MachineLearningLecture01.pdf’, ‘page’: 4}

4.基于MapReduce的检索式问答链

qa_chain_mr = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever(),
chain_type=”map_reduce”
)

question = “Is probability a class topic?”
result = qa_chain_mr({“query”: question})

print(result[“result”])

There is no clear answer to this question based on the given portion of the
document. The document mentions statistics and algebra as topics that may be
covered, but it does not explicitly state whether probability is a class topic.

5.基于Refine的检索式问答链

qa_chain_mr = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever(),
chain_type=”refine”
)
question = “Is probability a class topic?”
result = qa_chain_mr({“query”: question})
print(result[“result”])

The topic of probability is assumed to be a prerequisite and not a main topic of
the class. The instructor assumes that students are familiar with basic
probability and statistics, including random variables, expectation, variance,
and basic linear algebra. The class will cover learning algorithms, including a
discussion on overfitting and the probabilistic interpretation of linear
regression. The instructor will use this probabilistic interpretation to derive
the first classification algorithm, which will be discussed in the class. The
classification problem involves predicting a discrete value, such as in medical
diagnosis or housing sales. The class will not be very programming-intensive, but
some programming will be done in MATLAB or Octave. The instructor will provide a
refresher course on the prerequisites in some of the discussion sections.
Additionally, the discussion sections will be used to cover extensions for the
material taught in the main lectures, as machine learning is a vast field with
many topics to explore.

6.实验

qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever()
)
question = “Is probability a class topic?”
result = qa_chain({“query”: question})
print(“Q: “, question)
print(“A: “, result[“result”])
question = “why are those prerequesites needed?”
result = qa_chain({“query”: question})
print(“Q: “, question)
print(“A: “, result[“result”])

Q: Is probability a class topic?
A: Yes, probability is a topic that will be assumed to be familiar to students
in this class. The instructor assumes that students have a basic understanding of
probability and statistics, and will go over some of the prerequisites as a
refresher course in the discussion sections.
Q: why are those prerequesites needed?
A: The prerequisites are needed because in this class, the instructor assumes
that all students have a basic knowledge of computer science and knowledge of
basic computer skills and principles. This includes knowledge of big-O notation
and linear algebra, which are important concepts in machine learning. Without
this basic knowledge, it may be difficult for students to understand the material
covered in the class.

面向开发者的LLM入门教程-聊天Chat:复现之前代码
面向开发者的LLM入门教程-聊天Chat:复现之前代码:聊天Chat 回想一下检索增强生成 (retrieval augmented generation,RAG) 的整体工...

嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门教程-问答英文版”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!

微信打赏二维码 微信扫一扫

支付宝打赏二维码 支付宝扫一扫

版权: 转载请注明出处:https://www.ai-blog.cn/2844.html

相关推荐

AI编程-Trae+Figma强强联手前端也能秒出高颜值页面!: 本篇文章介绍用Trae+ Figma MCP来对页面样…

小智头像图片
461

AI写作-网文写作7步法模板教程【步骤三】第一次摩擦​: 【步骤三】第一次摩擦​ ​ ​ ​ 具体怎么写要…

小智头像图片
36

AI写作-网文写作7步法模板教程【步骤二】制作信息差​: 【步骤二】制作信息差​ ​ ​ ​ 在实际写作过…

小智头像图片
461

AI写作-网文写作7步法模板教程【步骤一】展示优势: 【步骤一】展示优势​ ​ ​ ​ 核心套路在于首先…

小智头像图片
461

AI写作-网文写作7步法模板教程-七步故事模板: 七步故事模板​ 1.通过情节,展示主角的优势或潜力,…

小智头像图片
461

AI编程-用Cursor设计移动app原型新手教程: 本篇文章介绍用Cursor来做移动app原型设计的实践,对比…

小智头像图片
111

AI写作-AI写小说教程-创建个人小说智能体(4): 2.4 生成小说架构 1.滑到下方记忆模块中,长期记…

小智头像图片
461

AI写作-AI写小说教程-创建个人小说智能体(3): 2.3 添加插件​ 1.返回Bot主页后,我们点击插件中…

小智头像图片
461
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力原创内容

快速提升站内名气成为大牛

扫描二维码

手机访问本站

二维码
vip弹窗图片