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/