面向开发者的LLM入门课程-评估英文版提(1): 英文版提示 1.创建LLM应用 from langchain.chains import RetrievalQA from langchain.chat_models import ChatOpenAI fr……
哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门课程-评估英文版提(1)”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。
面向开发者的LLM入门课程-评估英文版提(1):
英文版提示
1.创建LLM应用
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders import CSVLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.evaluation.qa import QAGenerateChain
import pandas as pdfile = ‘../data/OutdoorClothingCatalog_1000.csv’
loader = CSVLoader(file_path=file)
data = loader.load()test_data = pd.read_csv(file,skiprows=0,usecols=[1,2])
display(test_data.head())llm = ChatOpenAI(temperature = 0.0)
index = VectorstoreIndexCreator(
vectorstore_cls=DocArrayInMemorySearch
).from_loaders([loader])qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type=”stuff”,
retriever=index.vectorstore.as_retriever(),
verbose=True,
chain_type_kwargs = {
“document_separator”: “<<<<>>>>>”
}
)print(data[10],”n”)
print(data[11],”n”)examples = [
{
“query”: “Do the Cozy Comfort Pullover Set have side pockets?”,
“answer”: “Yes”
},
{
“query”: “What collection is the Ultra-Lofty 850 Stretch Down Hooded
Jacket from?”,
“answer”: “The DownTek collection”
}
]example_gen_chain = QAGenerateChain.from_llm(ChatOpenAI())
from langchain.evaluation.qa import QAGenerateChain #导入QA生成链,它将接收文档,并从
每个文档中创建一个问题答案对
example_gen_chain = QAGenerateChain.from_llm(ChatOpenAI())#通过传递chat open AI语言
模型来创建这个链
new_examples = example_gen_chain.apply([{“doc”: t} for t in data[:5]])#查看用例数据
print(new_examples)examples += [ v for item in new_examples for k,v in item.items()]
qa.run(examples[0][“query”])
page_content=”: 10nname: Cozy Comfort Pullover Set, Stripendescription: Perfect
for lounging, this striped knit set lives up to its name. We used ultrasoft
fabric and an easy design that’s as comfortable at bedtime as it is when we have
to make a quick run out.nnSize & Fitn- Pants are Favorite Fit: Sits lower on
the waist.n- Relaxed Fit: Our most generous fit sits farthest from the
body.nnFabric & Caren- In the softest blend of 63% polyester, 35% rayon and 2%
spandex.nnAdditional Featuresn- Relaxed fit top with raglan sleeves and
rounded hem.n- Pull-on pants have a wide elastic waistband and drawstring, side
pockets and a modern slim leg.nnImported.” metadata={‘source’:
‘../data/OutdoorClothingCatalog_1000.csv’, ‘row’: 10}
page_content=’: 11nname: Ultra-Lofty 850 Stretch Down Hooded
Jacketndescription: This technical stretch down jacket from our DownTek
collection is sure to keep you warm and comfortable with its full-stretch
construction providing exceptional range of motion. With a slightly fitted style
that falls at the hip and best with a midweight layer, this jacket is suitable
for light activity up to 20° and moderate activity up to -30°. The soft and
durable 100% polyester shell offers complete windproof protection and is
insulated with warm, lofty goose down. Other features include welded baffles for
a no-stitch construction and excellent stretch, an adjustable hood, an interior
media port and mesh stash pocket and a hem drawcord. Machine wash and dry.
Imported.’ metadata={‘source’: ‘../data/OutdoorClothingCatalog_1000.csv’, ‘row’:
11}
[{‘qa_pairs’: {‘query’: “What is the description of the Women’s Campside
Oxfords?”, ‘answer’: “The description of the Women’s Campside Oxfords is that
they are an ultracomfortable lace-to-toe Oxford made of super-soft canvas. They
have thick cushioning and quality construction, providing a broken-in feel from
the first time they are worn.”}}, {‘qa_pairs’: {‘query’: ‘What are the dimensions
of the small and medium sizes of the Recycled Waterhog Dog Mat, Chevron Weave?’,
‘answer’: ‘The dimensions of the small size of the Recycled Waterhog Dog Mat,
Chevron Weave are 18″ x 28″. The dimensions of the medium size are 22.5″ x
34.5″.’}}, {‘qa_pairs’: {‘query’: “What are the features of the Infant and
Toddler Girls’ Coastal Chill Swimsuit, Two-Piece?”, ‘answer’: “The swimsuit has
bright colors, ruffles, and exclusive whimsical prints. It is made of four-waystretch and chlorine-resistant fabric, which keeps its shape and resists snags.
The fabric is UPF 50+ rated, providing the highest rated sun protection possible
by blocking 98% of the sun’s harmful rays. The swimsuit also has crossover noslip straps and a fully lined bottom for a secure fit and maximum coverage.”}},
{‘qa_pairs’: {‘query’: ‘What is the fabric composition of the Refresh Swimwear,
V-Neck Tankini Contrasts?’, ‘answer’: ‘The Refresh Swimwear, V-Neck Tankini
Contrasts is made of 82% recycled nylon and 18% Lycra® spandex for the body, and
90% recycled nylon with 10% Lycra® spandex for the lining.’}}, {‘qa_pairs’:
{‘query’: ‘What is the fabric composition of the EcoFlex 3L Storm Pants?’,
‘answer’: ‘The EcoFlex 3L Storm Pants are made of 100% nylon, exclusive of
trim.’}}]
> Entering new RetrievalQA chain…
> Finished chain.
‘Yes, the Cozy Comfort Pullover Set does have side pockets.’
嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门课程-评估英文版提(1)”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!
还没有评论呢,快来抢沙发~