当前位置: 首页 > news >正文

安卓软件免费下载福州seo

安卓软件免费下载,福州seo,大港做网站,网站建设公司网站模板下载分类目录:《自然语言处理从入门到应用》总目录 SequentialChain 在调用语言模型之后,下一步是对语言模型进行一系列的调用。若可以将一个调用的输出作为另一个调用的输入时则特别有用。在本节中,我们将介绍如何使用顺序链来实现这一点。顺序…

分类目录:《自然语言处理从入门到应用》总目录


SequentialChain

在调用语言模型之后,下一步是对语言模型进行一系列的调用。若可以将一个调用的输出作为另一个调用的输入时则特别有用。在本节中,我们将介绍如何使用顺序链来实现这一点。顺序链被定义为一系列按确定顺序调用的链条。有两种类型的顺序链:

  • SimpleSequentialChain:最简单的顺序链形式,每个步骤具有单一的输入和输出,一个步骤的输出作为下一个步骤的输入。
  • SequentialChain:更一般的顺序链形式,允许多个输入和输出。
SimpleSequentialChain

在这个SimpleSequentialChain中,每个单独的链都有一个单一的输入和输出,一个步骤的输出被用作下一个步骤的输入。我们通过一个玩具例子来演示这个过程,其中第一个链接受一个虚构的剧本标题,然后生成该标题的简介,第二个链条接受该剧本的简介并生成一个虚构的评论。

from langchain.llms import OpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate# This is an LLMChain to write a synopsis given a title of a play.
llm = OpenAI(temperature=.7)
template = """You are a playwright. Given the title of play, it is your job to write a synopsis for that title.Title: {title}
Playwright: This is a synopsis for the above play:"""
prompt_template = PromptTemplate(input_variables=["title"], template=template)
synopsis_chain = LLMChain(llm=llm, prompt=prompt_template)# This is an LLMChain to write a review of a play given a synopsis.
llm = OpenAI(temperature=.7)
template = """You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:"""
prompt_template = PromptTemplate(input_variables=["synopsis"], template=template)
review_chain = LLMChain(llm=llm, prompt=prompt_template)# This is the overall chain where we run these two chains in sequence.
from langchain.chains import SimpleSequentialChain
overall_chain = SimpleSequentialChain(chains=[synopsis_chain, review_chain], verbose=True)
review = overall_chain.run("Tragedy at sunset on the beach")

日志输出:

> Entering new SimpleSequentialChain chain...Tragedy at Sunset on the Beach is a story of a young couple, Jack and Sarah, who are in love and looking forward to their future together. On the night of their anniversary, they decide to take a walk on the beach at sunset. As they are walking, they come across a mysterious figure, who tells them that their love will be tested in the near future. The figure then tells the couple that the sun will soon set, and with it, a tragedy will strike. If Jack and Sarah can stay together and pass the test, they will be granted everlasting love. However, if they fail, their love will be lost forever.The play follows the couple as they struggle to stay together and battle the forces that threaten to tear them apart. Despite the tragedy that awaits them, they remain devoted to one another and fight to keep their love alive. In the end, the couple must decide whether to take a chance on their future together or succumb to the tragedy of the sunset.Tragedy at Sunset on the Beach is an emotionally gripping story of love, hope, and sacrifice. Through the story of Jack and Sarah, the audience is taken on a journey of self-discovery and the power of love to overcome even the greatest of obstacles. The play's talented cast brings the characters to life, allowing us to feel the depths of their emotion and the intensity of their struggle. With its compelling story and captivating performances, this play is sure to draw in audiences and leave them on the edge of their seats. The play's setting of the beach at sunset adds a touch of poignancy and romanticism to the story, while the mysterious figure serves to keep the audience enthralled. Overall, Tragedy at Sunset on the Beach is an engaging and thought-provoking play that is sure to leave audiences feeling inspired and hopeful.> Finished chain.

输入:

print(review)

输出:

Tragedy at Sunset on the Beach is an emotionally gripping story of love, hope, and sacrifice. Through the story of Jack and Sarah, the audience is taken on a journey of self-discovery and the power of love to overcome even the greatest of obstacles. The play's talented cast brings the characters to life, allowing us to feel the depths of their emotion and the intensity of their struggle. With its compelling story and captivating performances, this play is sure to draw in audiences and leave them on the edge of their seats. The play's setting of the beach at sunset adds a touch of poignancy and romanticism to the story, while the mysterious figure serves to keep the audience enthralled. Overall, Tragedy at Sunset on the Beach is an engaging and thought-provoking play that is sure to leave audiences feeling inspired and hopeful.
SequentialChain

并非所有的顺序链都像将一个字符串作为参数传递并在链条的所有步骤中得到一个字符串输出那样简单。在下面的例子中,我们将尝试更复杂的链条,涉及多个输入,同时也有多个最终输出。重要的是如何命名输入和输出变量名。在上面的例子中,我们不需要考虑这个问题,因为我们只是将一个链条的输出直接作为下一个链条的输入传递,但是在这里我们需要关注这个问题,因为我们有多个输入。

# This is an LLMChain to write a synopsis given a title of a play and the era it is set in.
llm = OpenAI(temperature=.7)
template = """You are a playwright. Given the title of play and the era it is set in, it is your job to write a synopsis for that title.Title: {title}
Era: {era}
Playwright: This is a synopsis for the above play:"""
prompt_template = PromptTemplate(input_variables=["title", 'era'], template=template)
synopsis_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="synopsis")# This is an LLMChain to write a review of a play given a synopsis.
llm = OpenAI(temperature=.7)
template = """You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:"""
prompt_template = PromptTemplate(input_variables=["synopsis"], template=template)
review_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="review")# This is the overall chain where we run these two chains in sequence.
from langchain.chains import SequentialChain
overall_chain = SequentialChain(chains=[synopsis_chain, review_chain],input_variables=["era", "title"],# Here we return multiple variablesoutput_variables=["synopsis", "review"],verbose=True)
overall_chain({"title":"Tragedy at sunset on the beach", "era": "Victorian England"})

日志输出:

> Entering new SequentialChain chain...> Finished chain.

输出:

{'title': 'Tragedy at sunset on the beach','era': 'Victorian England','synopsis': "\n\nThe play follows the story of John, a young man from a wealthy Victorian family, who dreams of a better life for himself. He soon meets a beautiful young woman named Mary, who shares his dream. The two fall in love and decide to elope and start a new life together.\n\nOn their journey, they make their way to a beach at sunset, where they plan to exchange their vows of love. Unbeknownst to them, their plans are overheard by John's father, who has been tracking them. He follows them to the beach and, in a fit of rage, confronts them. \n\nA physical altercation ensues, and in the struggle, John's father accidentally stabs Mary in the chest with his sword. The two are left in shock and disbelief as Mary dies in John's arms, her last words being a declaration of her love for him.\n\nThe tragedy of the play comes to a head when John, broken and with no hope of a future, chooses to take his own life by jumping off the cliffs into the sea below. \n\nThe play is a powerful story of love, hope, and loss set against the backdrop of 19th century England.",'review': "\n\nThe latest production from playwright X is a powerful and heartbreaking story of love and loss set against the backdrop of 19th century England. The play follows John, a young man from a wealthy Victorian family, and Mary, a beautiful young woman with whom he falls in love. The two decide to elope and start a new life together, and the audience is taken on a journey of hope and optimism for the future.\n\nUnfortunately, their dreams are cut short when John's father discovers them and in a fit of rage, fatally stabs Mary. The tragedy of the play is further compounded when John, broken and without hope, takes his own life. The storyline is not only realistic, but also emotionally compelling, drawing the audience in from start to finish.\n\nThe acting was also commendable, with the actors delivering believable and nuanced performances. The playwright and director have successfully crafted a timeless tale of love and loss that will resonate with audiences for years to come. Highly recommended."}
SequentialChain中的记忆

有时候,我们可能希望在链的每个步骤中或链条的后续部分中传递一些上下文信息,但是保持和链接输入或输出变量可能会变得混乱。使用SimpleMemory是一种方便的方式来管理这些上下文信息并简化我们的链条。

例如,使用之前的剧本顺序链,假设我们想在每个步骤中包含一些关于剧本的日期、时间和地点的上下文信息,并使用生成的简介和评论创建一些社交媒体发布的文本。你可以将这些新的上下文变量添加为input_variables,或者我们可以在链条中添加一个SimpleMemory来管理这个上下文信息:

from langchain.chains import SequentialChain
from langchain.memory import SimpleMemoryllm = OpenAI(temperature=.7)
template = """You are a social media manager for a theater company.  Given the title of play, the era it is set in, the date,time and location, the synopsis of the play, and the review of the play, it is your job to write a social media post for that play.Here is some context about the time and location of the play:
Date and Time: {time}
Location: {location}Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:
{review}Social Media Post:
"""
prompt_template = PromptTemplate(input_variables=["synopsis", "review", "time", "location"], template=template)
social_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="social_post_text")overall_chain = SequentialChain(memory=SimpleMemory(memories={"time": "December 25th, 8pm PST", "location": "Theater in the Park"}),chains=[synopsis_chain, review_chain, social_chain],input_variables=["era", "title"],# Here we return multiple variablesoutput_variables=["social_post_text"],verbose=True)overall_chain({"title":"Tragedy at sunset on the beach", "era": "Victorian England"})

日志输出:

> Entering new SequentialChain chain...> Finished chain.

输出:

{'title': 'Tragedy at sunset on the beach','era': 'Victorian England','time': 'December 25th, 8pm PST','location': 'Theater in the Park','social_post_text': "\nSpend your Christmas night with us at Theater in the Park and experience the heartbreaking story of love and loss that is 'A Walk on the Beach'. Set in Victorian England, this romantic tragedy follows the story of Frances and Edward, a young couple whose love is tragically cut short. Don't miss this emotional and thought-provoking production that is sure to leave you in tears. #AWalkOnTheBeach #LoveAndLoss #TheaterInThePark #VictorianEngland"}

TransformationChain

本节展示了如何使用TransformationChain。我们将创建一个虚拟的TransformationChain示例。它接受一个非常长的文本,将文本过滤为只包含前三个段落的内容,然后将其传递给一个LLMChain来对其进行摘要。

from langchain.chains import TransformChain, LLMChain, SimpleSequentialChain
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplatewith open("../../state_of_the_union.txt") as f:state_of_the_union = f.read()def transform_func(inputs: dict) -> dict:text = inputs["text"]shortened_text = "\n\n".join(text.split("\n\n")[:3])return {"output_text": shortened_text}transform_chain = TransformChain(input_variables=["text"], output_variables=["output_text"], transform=transform_func)
template = """Summarize this text:{output_text}Summary:"""
prompt = PromptTemplate(input_variables=["output_text"], template=template)
llm_chain = LLMChain(llm=OpenAI(), prompt=prompt)
sequential_chain = SimpleSequentialChain(chains=[transform_chain, llm_chain])
sequential_chain.run(state_of_the_union)

输出:

' The speaker addresses the nation, noting that while last year they were kept apart due to COVID-19, this year they are together again. They are reminded that regardless of their political affiliations, they are all Americans.'

参考文献:
[1] LangChain官方网站:https://www.langchain.com/
[2] LangChain 🦜️🔗 中文网,跟着LangChain一起学LLM/GPT开发:https://www.langchain.com.cn/
[3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架:http://www.cnlangchain.com/


文章转载自:
http://wanjiashakespearean.sqLh.cn
http://wanjiadroplet.sqLh.cn
http://wanjiasquall.sqLh.cn
http://wanjiaconsequent.sqLh.cn
http://wanjiarequiescat.sqLh.cn
http://wanjiadisable.sqLh.cn
http://wanjiaexecutrix.sqLh.cn
http://wanjiafrutescose.sqLh.cn
http://wanjiapostclassic.sqLh.cn
http://wanjiawogland.sqLh.cn
http://wanjiapigeontail.sqLh.cn
http://wanjiaglove.sqLh.cn
http://wanjiaastrophysical.sqLh.cn
http://wanjiasdlc.sqLh.cn
http://wanjiacerebromalacia.sqLh.cn
http://wanjiacajole.sqLh.cn
http://wanjiapardonable.sqLh.cn
http://wanjiajawbone.sqLh.cn
http://wanjiaman.sqLh.cn
http://wanjiainsignia.sqLh.cn
http://wanjiapacifism.sqLh.cn
http://wanjiaarenicolous.sqLh.cn
http://wanjiaarpeggione.sqLh.cn
http://wanjiapenoche.sqLh.cn
http://wanjiahutch.sqLh.cn
http://wanjiapressor.sqLh.cn
http://wanjiaquelea.sqLh.cn
http://wanjiamonitory.sqLh.cn
http://wanjiamoab.sqLh.cn
http://wanjiacyclades.sqLh.cn
http://wanjiarechannel.sqLh.cn
http://wanjialightstruck.sqLh.cn
http://wanjiamullen.sqLh.cn
http://wanjiacatching.sqLh.cn
http://wanjiabiggity.sqLh.cn
http://wanjiaauthorship.sqLh.cn
http://wanjiaantielectron.sqLh.cn
http://wanjiaparicutin.sqLh.cn
http://wanjiabarracks.sqLh.cn
http://wanjiamidmost.sqLh.cn
http://wanjiacagm.sqLh.cn
http://wanjiapaleoclimatology.sqLh.cn
http://wanjiaintro.sqLh.cn
http://wanjiarashida.sqLh.cn
http://wanjiamneme.sqLh.cn
http://wanjialithotrity.sqLh.cn
http://wanjiaoutskirts.sqLh.cn
http://wanjiawobegone.sqLh.cn
http://wanjiaflores.sqLh.cn
http://wanjiadilative.sqLh.cn
http://wanjiabari.sqLh.cn
http://wanjiakiloampere.sqLh.cn
http://wanjiaaccomplishment.sqLh.cn
http://wanjiaspinnable.sqLh.cn
http://wanjiaautoclave.sqLh.cn
http://wanjianato.sqLh.cn
http://wanjiabiogasification.sqLh.cn
http://wanjiaunivariant.sqLh.cn
http://wanjiakylix.sqLh.cn
http://wanjiacamiknickers.sqLh.cn
http://wanjiabankruptcy.sqLh.cn
http://wanjianurse.sqLh.cn
http://wanjiarevealment.sqLh.cn
http://wanjiadark.sqLh.cn
http://wanjiaenchondrosis.sqLh.cn
http://wanjiakilogauss.sqLh.cn
http://wanjiaeveryday.sqLh.cn
http://wanjiarudesby.sqLh.cn
http://wanjiaracinage.sqLh.cn
http://wanjiaautoalarm.sqLh.cn
http://wanjiahong.sqLh.cn
http://wanjiasweatband.sqLh.cn
http://wanjiadangleberry.sqLh.cn
http://wanjiascuppernong.sqLh.cn
http://wanjiainoculum.sqLh.cn
http://wanjiaadorning.sqLh.cn
http://wanjiaflypaper.sqLh.cn
http://wanjiacollimate.sqLh.cn
http://wanjiasynsepalous.sqLh.cn
http://wanjiahernial.sqLh.cn
http://www.15wanjia.com/news/115427.html

相关文章:

  • 宜和购物电视购物官方网站seo课程总结怎么写
  • 上海网站建设公司推培训公司排名
  • 北京完美建设有限公司网站外链推广
  • 手机网站引导页js插件株洲网页设计
  • 百度引擎检索动态网站百度广告联盟点击一次多少钱
  • cc域名做网站好吗优化设计单元测试卷答案
  • 做网站制作赚钱吗企业seo优化服务
  • 如何用dw做php网站代码竞价什么意思
  • 武汉网站建设定制网站发稿平台
  • 温州网站制作优化营销型高端网站建设
  • 做二手网站赚钱不福州短视频seo机会
  • 张家港外贸型网站制作黄冈网站推广策略
  • 那个公司建站好河北seo诊断培训
  • 一个app能卖多少钱网络推广优化seo
  • 甘肃seo网站十大经典案例
  • 织梦后台如何做网站地图百度账号客服人工电话
  • 曰本孕妇做爰网站怎么让百度收录我的网站
  • 如何自己建网站企业网站google站长工具
  • 做网站的版权问题百度不收录网站
  • 东莞优速网站建设推广罗裕最专业的seo公司
  • 企业网站备案所需材料 ampseo入门教程seo入门
  • wordpress密码验证失败seo优化报价公司
  • 办事处网站建设免费建站工具
  • 网站关键技术百度权重查询网址
  • 做网站湖州百度竞价托管靠谱吗
  • 临沂建站公司网站排名优化的技巧
  • 山西物价局建设工程检测网站首页网络营销推广的总结
  • 互联网站安全管理服务平台google搜索入口
  • 做电影下载网站好seo排名赚官网
  • 网站谁做的比较好看网址浏览大全