小智头像图片
AI教程 2025年01月17日
0 收藏 0 点赞 448 浏览 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写作-DeepSeek高阶提示词之自媒体爆款创作篇: 自媒体爆款创作篇 6.10W+标题生成器 “生成20个关…

小智头像图片
448

AI写作-DeepSeek高阶提示词之职场打工人必备篇: 职场打工人必备篇 1.会议纪要秒整理 “将以下会议…

小智头像图片
448

AI绘画-即梦3.0提示词示例之场景化种草型​: 场景化种草型​ 公式:产品+使用场景+氛围渲染+情感化…

小智头像图片
64

AI绘画-即梦3.0提示词示例之限时折扣型​: 限时折扣型​ 公式:产品+价格锚点+紧迫感元素+霓虹灯风…

小智头像图片
448

AI绘画-即梦3.0提示词示例之新品发布型: 新品发布型​ 公式:产品+核心卖点+高级质感+极简排版 ​ …

小智头像图片
448

AI绘画-即梦3.0提示词示例之节日促销型​: 节日促销型​ 公式:产品+节日主题+视觉元素+动态文字+风…

小智头像图片
448

AI绘画-即梦3.0提示词示例之暗黑哥特​: 暗黑哥特​ 提示词: 哥特体、烛光照明、高反差,荆棘十字…

小智头像图片
448

AI绘画-即梦3.0提示词示例之奶油治愈​: 奶油治愈​ 提示词: 奶乎乎、柔焦镜头、低对比,猫咪蜷缩…

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

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

助力原创内容

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

扫描二维码

手机访问本站

二维码
vip弹窗图片