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

企业网站建设的三个核心问题typecodes wordpress

企业网站建设的三个核心问题,typecodes wordpress,软文代写网,数据分析师就业前景分类目录#xff1a;《自然语言处理从入门到应用》总目录 语言模型以文本作为输入#xff0c;这段文本通常被称为提示#xff08;Prompt#xff09;。通常情况下#xff0c;这不仅仅是一个硬编码的字符串#xff0c;而是模板、示例和用户输入的组合。LangChain提供了多个…分类目录《自然语言处理从入门到应用》总目录 语言模型以文本作为输入这段文本通常被称为提示Prompt。通常情况下这不仅仅是一个硬编码的字符串而是模板、示例和用户输入的组合。LangChain提供了多个类和函数以便轻松构建和处理提示。 提示模板的概念 提示模板是指一种可复制的生成提示的方式。它包含一个文本字符串模板可以从最终用户处接收一组参数并生成提示。提示模板可能包含以下内容 对语言模型的指令少量示例以帮助语言模型生成更好的回复对语言模型的问题 以下代码片段是包含了一个提示模板的示例 from langchain import PromptTemplatetemplate 我希望你能充当新公司的命名顾问。 一个生产{product}的公司的好名字是什么 prompt PromptTemplate(input_variables[product],templatetemplate, ) prompt.format(product彩色袜子) # - 我希望你能充当新公司的命名顾问。 # - 一个生产彩色袜子的公司的好名字是什么创建提示模板 我们可以使用PromptTemplate类创建简单的硬编码提示。提示模板可以接受任意数量的输入变量并且可以进行格式化以生成提示。 from langchain import PromptTemplate# 没有输入变量的提示示例 no_input_prompt PromptTemplate(input_variables[], template给我讲个笑话。) no_input_prompt.format() # - 给我讲个笑话。# 一个输入变量的提示示例 one_input_prompt PromptTemplate(input_variables[adjective], template给我讲个{adjective}的笑话。) one_input_prompt.format(adjective有趣的) # - 给我讲个有趣的笑话。# 多个输入变量的示例提示 multiple_input_prompt PromptTemplate(input_variables[adjective, content], template给我讲一个{adjective}的关于{content}的笑话。 ) multiple_input_prompt.format(adjective有趣的, content小鸡) # - 给我讲一个有趣的关于小鸡的笑话。如果我们不想手动指定input_variables还可以使用from_template类方法创建PromptTemplate。LangChain将根据传递的template自动推断input_variables。 template 给我讲一个{adjective}的关于{content}的笑话。 prompt_template PromptTemplate.from_template(template) prompt_template.input_variables # - [adjective, content] prompt_template.format(adjective有趣的, content小鸡) # - 给我讲一个有趣的关于小鸡的笑话。我们可以创建自定义的提示模板以任何您想要的方式格式化提示。 模板格式 默认情况下PromptTemplate将提供的模板视为Python f-string。我们可以通过template_format参数指定其他模板格式 # 在运行此代码之前请确保已安装jinja2jinja2_template 告诉我一个{{ adjective }}的笑话关于{{ content }} prompt_template PromptTemplate.from_template(templatejinja2_template, template_formatjinja2)prompt_template.format(adjective有趣的, content鸡) # - 告诉我一个有趣的笑话关于鸡目前PromptTemplate仅支持jinja2和f-string模板格式。如果您希望使用其他模板格式我们可以在GitHub页面上提交需求。 验证模板 默认情况下PromptTemplate将通过检查input_variables是否与模板中定义的变量匹配来验证template字符串。您可以通过将validate_template设置为False来禁用此行为。 template 我正在学习LangChain因为{reason}。prompt_template PromptTemplate(templatetemplate, input_variables[reason, foo]) # 由于存在额外的变量而引发ValueError prompt_template PromptTemplate(templatetemplate, input_variables[reason, foo], validate_templateFalse) # 不会引发错误序列化模板 我们可以将PromptTemplate保存到本地文件系统中的文件中。LangChain将通过文件扩展名自动推断文件格式。目前LangChain支持将模板保存为YAML和JSON文件。 prompt_template.save(awesome_prompt.json) # 保存为JSON文件 from langchain.prompts import load_prompt loaded_prompt load_prompt(awesome_prompt.json)assert prompt_template loaded_promptLangChain还支持从LangChainHub加载提示模板其中包含一系列我们可以在项目中使用的有用提示。 from langchain.prompts import load_promptprompt load_prompt(lc://prompts/conversation/prompt.json) prompt.format(history, input1 1等于多少)向模板添加Few Shot示例 Few Shot示例是一组可以帮助语言模型生成更好响应的示例。要使用Few Shot示例生成提示可以使用FewShotPromptTemplate。此类接受PromptTemplate和Few Shot示例列表。然后它使用Few Shot示例格式化提示模板。 在下面示例中我们将创建一个生成单词反义词的提示。 from langchain import PromptTemplate, FewShotPromptTemplate# 首先创建Few Shot示例列表 examples [{word: happy, antonym: sad},{word: tall, antonym: short}, ]# 接下来我们指定用于格式化示例的模板。 # 我们使用PromptTemplate类来实现这个目的。 example_formatter_template Word: {word} Antonym: {antonym} example_prompt PromptTemplate(input_variables[word, antonym],templateexample_formatter_template, )# 最后创建FewShotPromptTemplate对象。 few_shot_prompt FewShotPromptTemplate(# 这些是我们要插入到提示中的示例。examplesexamples,# 这是我们在将示例插入到提示中时要使用的格式。example_promptexample_prompt,# 前缀是出现在提示中示例之前的一些文本。# 通常这包括一些说明。prefixGive the antonym of every input\n,# 后缀是出现在提示中示例之后的一些文本。# 通常这是用户输入的地方。suffixWord: {input}\nAntonym: ,# 输入变量是整个提示期望的变量。input_variables[input],# 示例分隔符是我们将前缀、示例和后缀连接在一起的字符串。example_separator\n, )# 现在我们可以使用format方法生成一个提示。 print(few_shot_prompt.format(inputbig)) # - Give the antonym of every input # - # - Word: happy # - Antonym: sad # - # - Word: tall # - Antonym: short # - # - Word: big # - Antonym:选择用于提示模板的示例 如果您有大量示例可以使用ExampleSelector选择一部分对语言模型来说最具信息量的示例。这将帮助您生成更有可能获得良好回应的提示。下面我们将使用LengthBasedExampleSelector它根据输入的长度选择示例。当我们担心构建的提示会超过上下文窗口的长度时这将非常有用。对于较长的输入它会选择较少的示例进行包含而对于较短的输入它会选择更多的示例。我们将继续使用前面部分的示例但这次我们将使用LengthBasedExampleSelector来选择示例。 from langchain.prompts.example_selector import LengthBasedExampleSelector# 这里是一些虚构任务的大量示例该任务是创建反义词。 examples [{word: happy, antonym: sad},{word: tall, antonym: short},{word: energetic, antonym: lethargic},{word: sunny, antonym: gloomy},{word: windy, antonym: calm}, ]# 我们将使用LengthBasedExampleSelector来选择示例。 example_selector LengthBasedExampleSelector(# 这些是可供选择的示例。examplesexamples, # 这是用于格式化示例的PromptTemplate。example_promptexample_prompt, # 这是格式化示例的最大长度。max_length25# 这是用于获取字符串长度的函数用于确定包含哪些示例。在这里被注释掉因为如果没有指定默认提供了该函数。# get_text_length: Callable[[str], int] lambda x: len(re.split(\n| , x)) )# 现在我们可以使用example_selector创建FewShotPromptTemplate。 dynamic_prompt FewShotPromptTemplate(# 我们提供一个ExampleSelector而不是示例。example_selectorexample_selector,example_promptexample_prompt,prefix给出每个输入的反义词,suffix单词{input}\n反义词,input_variables[input],example_separator\n\n, )# 现在我们可以使用format方法生成提示。 print(dynamic_prompt.format(inputbig)) # - 给出每个输入的反义词 # - # - 单词happy # - 反义词sad # - # - 单词tall # - 反义词short # - # - 单词energetic # - 反义词lethargic # - # - 单词sunny # - 反义词gloomy # - # - 单词windy # - 反义词平静 python print(dynamic_prompt.format(inputbig)) # - 给出每个输入的反义词 # - # - 单词happy # - 反义词sad # - # - 单词tall # - 反义词short # - # - 单词energetic # - 反义词lethargic # - # - 单词sunny # - 反义词gloomy # - # - 单词windy # - 反义词calm # - # - 单词big # - 反义词平静 相反如果我们提供一个非常长的输入LengthBasedExampleSelector会选择较少的示例包含在提示中。long_string big and huge and massive and large and gigantic and tall and much much much much much bigger than everything else print(dynamic_prompt.format(inputlong_string)) # - 给出每个输入的反义词 # - # - 单词happy # - 反义词sad # - # - 单词big and huge and massive and large and gigantic and tall and much much much much much bigger than everything else # - 反义词平静LangChain附带了一些示例选择器供我们使用有关如何使用示例选择器可以参考《自然语言处理从入门到应用——LangChain提示Prompts》系列的后续文章。除此之外我们还可以创建自定义示例选择器根据我们想要的任何条件选择示例。 参考文献 [1] LangChain ️ 中文网跟着LangChain一起学LLM/GPT开发https://www.langchain.com.cn/ [2] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架http://www.cnlangchain.com/
http://www.hkea.cn/news/14453809/

相关文章:

  • 吉林省网站建设行业需求分析公司网站建设汇报
  • 杭州认证网站建设网站描述设置
  • 网站信息可以边建设边组织wordpress 字体 插件下载
  • 做3ds磁铁卡网站wordpress腾讯地图插件
  • wordpress搭建外贸网站广东省建设厅的注册中心网站
  • 双语企业网站源码电影网站模板下载
  • 网站优化推广是什么wordpress背景图案轮流
  • 昆明免费网站建设软件研发和开发哪个工资高
  • 电商网站开发用什么语言表达室内设计师常用网站
  • 音乐网站的制作宁波建设网 公积金网点
  • 南京 网站开发做我女朋友的网站
  • 图书馆门户网站建设总结想自己做个公司网站不知道怎么做
  • 贵州省住房和城乡建设厅网站东京购物
  • 做网站哪里好做金融网站需要什么营业执照
  • 建设单位网站经费请示北京建设网网站
  • 免费营销软件网站长沙品牌设计公司排行榜
  • 门户网站的特点和优势常州网签备案查询
  • 凡科网建站入门教程网站建设推广怎么做
  • 陕西营销型手机网站建设广州建站免费模板
  • wordpress 全站pjax湖南住房和城乡建设厅网站首页
  • 池州做网站的公司wordpress柒主题
  • 网站建设列入什么会计科目广州专业做网站排名哪家好
  • 潜江市建设工程合同备案网站自己做的网站怎么置顶
  • 潍坊百度seoseo营销
  • 网站群建设工作培训会网站源码大全免费的
  • wordpress网站导入越秀网站建设推广
  • 青海网站建设公司多少钱临沂高端网站建设
  • 网站手机页面做多大wordpress加密数据库文件夹
  • 做网站有没有用网站建设 付款方式
  • 旅游网站建设的规模设想网站开发课程学习报告