AI教程 2025年01月17日
0 收藏 0 点赞 393 浏览 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

相关推荐
01-27

Kimi神级写作指令-充当正则表达式生成器的提示词: 正则表达式是不是让你又爱又恨?想匹配特定文本…

427
01-27

Kimi神级写作指令-充当数学家的提示词: 数学计算是不是让你头大?复杂的表达式、繁琐的步骤,是不…

393
01-27

Kimi神级写作指令-充当全栈软件开发人员的提示词: 想开发一个Web应用程序,却不知道从何下手?或…

393
01-27

Kimi神级写作指令-充当对弈棋手的提示词: 喜欢下棋但找不到对手?或者想提升棋艺却苦于没有合适的…

393
01-27

Kimi神级写作指令-作为专业DBA的提示词: 数据库查询是不是让你头大?写SQL语句时总是担心性能不够…

393
01-27

Kimi神级写作指令-作为项目经理的提示词: 项目管理是不是让你头大?进度拖延、任务混乱、团队沟通…

393
01-27

Kimi神级写作指令-作为 IT 专家的提示词: 电脑蓝屏、软件崩溃、网络连接失败……这些技术问题是不是…

393
01-27

Kimi神级写作指令-担任 SVG 设计师的提示词: 你是不是经常需要一些简单的图像素材,但又不想打开…

393
发表评论
暂无评论

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

助力原创内容

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

扫描二维码

手机访问本站