Star

linkSemstrings

The core idea behind MT-LLM is that if the program has been written in a readable manner, with type-safety, an LLM would be able to understand the task required to be performed using meaning embedded within the code.

However, there are instanced where this is not the case for all instances. Hence, a new meaning insertion code abstraction called "semstrings" has been introduced in MT-LLM.

linkWhere code is not meaningful enough!

Lets look into an instance where the existing code constructs are not sufficient to describe the meaning of the code for an LLM.

apple.jac
1linkimport:py from mtllm.llms, OpenAI;

2link

3linkglob llm = OpenAI();

4link

5linkobj item {

6link has name : str,

7link category : str = '';

8link}

9link

10linkobj shop {

11link has item_dir:dict[str,item];

12link

13link can categorize(name:str) -> str by llm();

14link}

15link

16linkwith entry {

17link shop_inv = shop();

18link apple = item(name=apple);

19link apple.category = categorize(apple.name);

20link shop_inv.item_dir[apple.name] = apple.category;

21link}

This is a partial code that can be used as a shopkeeping app where each item name is tagged with its category. However, in this example, you can observe in line 16 that the item name is passed in as 'apple' which can be ambiguous for an LLM as apple can mean the fruit, as well as a tech product. To resolve this problem we can use much more descriptive variable names. For instance, instead of item we can use tech_item. How ever, adding more descriptive names for objects, variables and functions will hinder the reusability of object fields as the reference names are too long.

linkSemstrings to uplift 'meaning'

As the existing code abstractions does not fully allow the programmer to express their meaning we have added an extra feature you can use to embed meaning directly as text, into your code. We call these text annotations as semstrings.

Lets see how we can add semstring to the existing program above.

apple.jac
1linkimport:py from mtllm.llms, OpenAI;

2link

3linkglob llm = OpenAI();

4link

5linkobj 'An edible product'

6linkitem {

7link has name : str,

8link category : str = '';

9link}

10link

11linkobj 'Food store inventory'

12linkshop {

13link has item_dir:'Inventory of shop':dict[str,item];

14link

15link can 'categorize the edible as fruit, vegetables, sweets etc'

16link categorize(name: str) -> 'Item category': str by llm();

17link}

18link

19linkwith entry {

20link shop_inv = shop();

21link apple = item(name=apple);

22link apple.category = categorize(apple.name);

23link shop_inv.item_dir["ID_876837"] = apple;

24link}

In this example we add semstrings that add semantic meaning to existing code constructs such as variables, objects and functions. The semstring of each item is linked with its signature which are called when generating the prompt for the LLM. These small descriptions adds more context for the LLM to give a much more accurate response.

linkHow to add semstrings?

The below examples show different instances where semstrings can be inserted.

linkVariables / Object Fields Declaration

1linkglob name: 'semstring': str = 'sample value'

linkFunction / Method Declaration

1linkcan 'semstring'

2linkfunction_name(arg_1: 'semstring': type ...) {

3link #function body

4link}

linkObject / Class Declaration

1linkobj 'semstring' object_name {

2link # Object fields

3link # Object methods

4link}

linkWith by llm()

1linkcan 'semstring_for_action'

2linkfunction_name (arg_1:'semstring_input': type ...)

3link-> 'semstring_output': type

4linkby llm();

SemstringsWhere code is not meaningful enough!Semstrings to uplift 'meaning'How to add semstrings?Variables / Object Fields DeclarationFunction / Method DeclarationObject / Class DeclarationWith by llm()

Home

Quick Startchevron_right
Building Blockschevron_right
Tutorialschevron_right
API Referencechevron_right
Tips and Trickschevron_right

FAQs