Text to structure: a way to standardize outputs

Total newbie here.
My goal is to convert an input text to a standardized structure that would allow me, later on, to process tabulated data in JSON format.

For example,

  • Input: “Give me a list of all clients having purchased milk”

  • Output: {"intention": "retrieve", "object": "client", "conditions":['purchase', 'milk']}

  • Input: “Please, machine, do me a favor and delete users not having logged in after 2022”

  • Output {"intention": "delete", "object": "user", "conditions":['logged-in', '2022-12-31']}

The output JSON structure has fixed keys (intention, object, conditions) and values can be either discrete (for example intention can only be ['retrieve', 'delete', 'modify']) or variable (for example conditions can contain any piece of data.

My approach would be to use named entity recognition (NER) to identify the relevant entities and their properties, and syntactic parsing to determine the structure of the user’s prompt. For example, the “Give me a list” would result in the entity intention to be retrieve.

After reading, watching, and practicing, I think I’m now totally lost and not even sure the NER approach is advisable in this context.

Any help would be much appreciated :hugs:

For your task you can use langchain output parsers. You’d have to setup a local or huggingfacehub pipeline for accessing your model from huggingface. I am not sure if HuggingFace has a similar library.
Biggest issue you would go into is langchain works best with chatgpt and some of the simpler text to text models available like Falcon-7b or google t5 are bad at structuring result to json(would love to know if someone can recommend a simple pretrained language model that can structure output to json).
Hope this help! Noticed your issue didn’t get any activity for a long time.