RisateScript是一种声明性的元语言,旨在简化大型语言模型(LLMS)的结构化和一致提示的创建。本文介绍了Relatescript的语法,突出了其关系和谓词逻辑的基础。通过关注关系,条件和上下文,Relatescript桥接了自然语言表现力与有效LLM相互作用所需的精度之间的差距。它促进了一种新颖的方法来促使工程技术,在该方法中,人类和LLM会协作开发结构化提示,可以轻松修改和重复使用以完成不同的任务,从而增强了LLM驱动的工作流的可靠性和自动化能力。
在大型语言模型(LLM)快速发展的领域中,相互作用的有效性在很大程度上取决于提示的质量。传统的命令式编程语言通常会施加与人类推理的细微差别和上下文敏感性形成鲜明对比的僵化结构。尽管自然语言为与LLM互动提供了无与伦比的灵活性,但它可能导致及时输出的歧义和不一致。为了应对这些挑战,我们介绍了Relatescript,这是一种专门为制定结构化提示而设计的声明性元语言。 RISATESCRIPT使用户能够以既可读又逻辑上精确的格式定义实体,关系和条件。 RisateScript并非旨在用单独的解析器作为传统的编程语言,而是作为利用LLMS固有理解功能的结构化输入格式。
RisateScript解决了对更系统和可靠的方法促进工程的日益增长的需求。随着LLM越来越复杂,阐明复杂指令并定义精确条件的能力对于利用其全部潜力至关重要。 RisateScript提供了一种可访问,直观的方式来描述实体之间的关系和依赖关系,使用户能够以与人类推理紧密相符的方式表达复杂的逻辑。借助为可读性设计的语法,Relatescript使用户能够生成一致的提示,从而特别适合构建可重复使用的提示模板,这些模板可以适用于不同的方案,从而提高了LLM交互的效率和可靠性。它还允许将人类领域知识的优势与逻辑形式的结构相结合。
Relatescript的语法强调自然语言结构,从而允许对实体,关系和条件的可读声明。它的主要结构包括:
define <Entity> as <Description>.
<Entity> is <Predicate>.
<Entity> has <Attribute> of <Value>.
relate <Entity1> and <Entity2> as <RelationType> [ if <Condition> ].
if <Condition>, then <Action>.
ensure <Goal>.
带有复合说明和多级逻辑的提示。
define City as "A collection of buildings and people".
Berlin is a City.
Berlin has Population of 3_500_000.
define Metropolis as "A city with more than 1_000_000 inhabitants".
if City has Population > 1_000_000,
then ensure City is a Metropolis.
预期行为:LLM应该认识到柏林是“大都市”,因为其人口大于100万。
更多样本
以下扩展的Backus-Naur形式(EBNF)定义了Relatescript的语法:
program ::= { statement } ;
statement ::= definition | predicate | attribute | relation | condition | goal ;
definition ::= " define " entity " as " string " . " ;
predicate ::= entity " is " predicate_value " . " ;
attribute ::= entity " has " attribute_name " of " attribute_value " . " ;
relation ::= " relate " entity " and " entity " as " relation_type [ " if " condition ] " . " ;
condition ::= " if " condition_expr " , then " action " . " ;
goal ::= " ensure " goal_expr " . " ;
condition_expr ::= entity predicate_operator predicate_value
| entity attribute_operator attribute_value
| entity relation_operator entity ;
goal_expr ::= entity relation_type entity ;
action ::= " ensure " goal_expr ;
entity ::= identifier ;
predicate_value ::= identifier ;
attribute_name ::= identifier ;
attribute_value ::= identifier | number ;
relation_type ::= string ;
predicate_operator ::= " is " | " is not " ;
attribute_operator ::= " has " | " does not have " ;
relation_operator ::= " relates to " | " does not relate to " ;
identifier ::= letter { letter | digit | " _ " } ;
letter ::= " a " | " b " | " ... " | " z " ;
string ::= ' " ' { character } ' " ' ;
number ::= digit { digit } ;
character ::= lowercase-char | uppercase-char | digit | special-char ;
lowercase-char ::= " a " | " b " | " ... " | " z " ;
uppercase-char ::= " A " | " B " | " ... " | " Z " ;
special-char ::= " - " | " _ " ;
digit ::= " 0 " | " 1 " | " ... " | " 9 " ;
主结构( program
) :程序(提示)由一系列statements
组成,每个语句定义了特定信息,关系或陈述。
语句:
definition
):定义具有名称和描述的实体。predicate
):将属性或状态分配给实体。attribute
):将实体与属性和值相关联。relation
):定义两个实体之间的关系,可选地使用一个条件。condition
):定义条件和由此产生的动作。goal
):描述要实现的目标。condition_expr
):检查实体之间的关系或属性。goal_expr
):描述要实现的目标。action
):与要实现的目标有关。entity
, predicate_value
, attribute_name
, attribute_value
和relation_type
是标识符(例如名称)或值(例如数字)表示的基本组件。predicate_operator
, attribute_operator
和relation_operator
定义关系或条件的类型,例如“ is”,“ has”,“与之相关”。identifier
代表名称,必须从字母开始。string
代表文本,并以引号标记封闭。 RisateScript提供了一个结构化的逻辑驱动框架,该框架无缝地补充了基于自然语言的提示方法。尽管自然语言在传达细微差别和歧义方面表现出色,尤其是对于创造性的任务,但RelatesCript提供了清晰,精确和逻辑的一致性,这是与LLMS复杂和多步交互的必不可少的品质。
RileatScript可以有效地与自然语言输入配对,以结合两种方法的优势:
例如,用户可能以自然语言提示开始,例如:
“帮助我建立销售模式。首先要对客户和产品做出基本假设。”
然后可以由Relatescript块支持此上下文:
define Product as "A product for sale".
Product is available.
Product has price of 100.
Product has category of "Electronics".
define Customer as "A person who wants to buy a product".
Customer has budget of 150.
relate Customer and Product as "buys" if Product is available and Customer has budget of 150.
ensure Customer buys Product.
这种组合允许LLMS在遵守逻辑结构和相关订阅的逻辑结构和精度的同时,利用自然语言的直观和上下文设置。
Rielatescript与LLM的高级提示技术保持一致,例如:
RISATESCRIPT非常适合需要:
但是,自然语言仍然优越:
最有效的Relatescript使用在于其混合应用,它充当自然语言输入的补充。这种方法使用户可以平衡创造力和逻辑一致性,从而使LLMS能够处理具有精度和适应性的更广泛的任务。我们主张迭代工作流程,其中Relatescript提示是根据LLM反馈不断完善的,从而导致越来越有效和可靠的相互作用。
几种语言和框架提供了关系,声明性或上下文敏感的功能。在这里,我们将Relatescript与类似系统进行比较。
Prolog是一种常用于AI中的逻辑编程语言。它使用事实和规则来得出新信息。
Datalog是Prolog的简化版本,用于数据库查询和逻辑推理。
SPARQL和RDF模型数据通常用于语义Web的主题 - 预处理 - 对象关系图。
描述逻辑是本体论中知识表示的形式语言。
规则引擎使用声明性规则在业务应用程序中进行自动决策。
if-then
逻辑,例如Relatescript的条件和目标。Rielatescript的结构是:
科学研究:
AI系统:
知识表示:在特定领域内建模实体,属性和关系。
决策系统:使用目标和条件动态调整程序行为。
清晰度和精度:Relatescript清楚地结构了,具有定义的规则和术语。这减少了自然语言中经常发现的歧义,并确保LLM正确解释了预期的含义。
明确的关系和条件:Relatescript的声明性结构特别适合明确制定连接和条件。这可以帮助LLM得出结论或协调顺序步骤。
减少的解释:由于Relatescript基于逻辑语法,因此LLM的“解释工作”通常更容易。它需要对语言本身的上下文理解较少,并且可以专注于指令。
可理解性和可访问性:对于许多用户来说,自然语言更直观,更易于使用,因为它不需要特定的结构或定义的语法。当LLM的指令由非程序员创建时,这是一个优势。
灵活性和表现力:自然语言更加灵活,并且可以传达复杂,细微的说明,这些说明很难在像Relatescript这样的高度结构化系统中表达。例子包括人类交流中常见的隐喻,模糊的术语或上下文描述。
LLMS的处理能力:像GPT-4这样的现代LLM旨在理解自然语言并在上下文上进行处理。他们通常已经能够解释复杂的说明而无需形式上的语言。在许多情况下,LLM足够准确地了解自然语言,因此Relatescript提供的优势更少。
此示例说明了如何使用Relatescript来建模物理现象,特别是量子力学中的光电效应。
define Planck_constant as "h = 6.62607015 × 10⁻³⁴ Js".
define Photon as "A quantum of light".
Photon has frequency of f.
Photon has energy of E.
Photon has count of N.
relate energy and frequency as "E = Planck_constant * f".
define Metal as "A metallic element".
Metal has work_function of Phi.
Metal has electron_energy of Ee.
define Electron as "An emitted electron".
Electron has kinetic_energy of Ek.
relate Photon and Metal as "interacts" if
(Photon.energy * Photon.count) >= Metal.work_function.
if Photon interacts with Metal,
then create Electron with kinetic_energy of max((Photon.energy * Photon.count) - Metal.work_function, 0).
预期行为:系统模拟光电与金属表面相互作用的光电效应。当入射光子的总能量超过金属的工作函数时,电子发射的动能等于入射光子能量与工作函数之间的差异。
这个示例展示了Relatescript以一种足够精确的计算目的表达复杂物理现象的潜力,并且足以可读。该语言弥合了数学形式主义与自然语言描述之间的差距,使其对于物理和其他科学领域的教育和实际应用都有价值。
resateScript通过:
此示例显示了Relatescript如何对复杂的AI系统及其交互作用进行建模。
define Agent as "A learning AI agent".
Agent has state of S.
Agent has action_space of A.
Agent has reward of R.
Agent has policy of π.
define Environment as "The agent's environment".
Environment has state_space of S.
Environment has transition_function of T.
Environment has reward_function of R.
relate Agent and Environment as "interacts" through "action".
relate Environment and Agent as "responds" with "state and reward".
if Agent takes Action in Environment,
then ensure Environment updates State according to transition_function and
ensure Agent receives Reward according to reward_function.
ensure Agent maximizes expected_future_reward.
预期行为:该系统模拟了加强学习者与环境的互动,包括国家过渡,行动和奖励。 Relatescript配方捕获了增强学习系统的基本组成部分和关系。
此示例演示了Relatescript如何用于构建和监测临床试验。
define Patient as "A participant in the clinical study".
Patient has id of unique_number.
Patient has age of years.
Patient has symptoms of [].
Patient has treatment_group of "A" or "B".
Patient has response_measure of value.
define Treatment as "A therapeutic intervention".
Treatment has type of "Experimental" or "Control".
Treatment has dosage of amount.
Treatment has duration of weeks.
define Outcome as "The treatment result".
Outcome has primary_endpoint of value.
Outcome has adverse_events of [].
Outcome has followup_status of state.
relate Patient and Treatment as "receives".
relate Patient and Outcome as "shows".
if Patient receives Treatment,
then ensure Outcome is monitored and
ensure adverse_events are reported within 24 hours.
# Statistical Analysis Rules
define SignificanceTest as "Statistical evaluation".
relate Treatment_A and Treatment_B as "compare" through SignificanceTest.
ensure p_value < 0.05 for "statistical significance".
预期行为:该系统通过跟踪患者,治疗和结果来管理临床试验。它确保对结果的适当监测和治疗效果的统计分析。 Relatescript公式提供了定义和执行临床试验方案的结构化方法。
根据历史数据和市场趋势来预测销售。
define Product as "A sellable item".
Product has name of "Smartphone".
Product has historical_sales of [100, 150, 200, 250, 300].
define Market_Trend as "An indicator of market conditions affecting sales".
Market_Trend has trend of "Increasing".
define Sales_Prediction as "An estimated future sales figure".
Sales_Prediction has value of 350 if Market_Trend has trend of "Increasing" and Product has historical_sales[-1] < 350.
relate Product and Sales_Prediction as "predicted_sales".
ensure Product predicted_sales Sales_Prediction.
预期行为:该系统应根据不断增长的市场趋势和最后记录的历史销售数字来预测“智能手机”的未来销售。
RisateScript为需要精确和逻辑一致性的任务提供了一个结构化的声明框架,使其成为知识表示,决策和AI系统等应用程序中的强大工具。它的语法强调可读性和易用性,使用户能够以与自然人类语言共鸣的方式传达复杂的条件和目标。
通过将RelatesCript与自然语言提示集成,用户可以利用两全其美的最好的,将自然语言的直觉,创造性能力与逻辑推理的严格性和可重复性相结合。这种混合方法扩大了Relatescript应用程序的范围,并将其定位为增强LLM驱动的工作流程,为更可靠,高效和与大语言模型的自动互动铺平道路。
未来的工作可能涉及测试现实世界中AI和知识管理系统中的语言。进一步的研究还将着重于完善语言的语法,探索其可扩展性并解决潜在的安全漏洞。
弗洛里安·菲舍尔(Florian Fischer)
https://github.com/fischerf/