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 exampleintentioncan only be['retrieve', 'delete', 'modify']) or variable (for exampleconditionscan 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 entityintentionto beretrieve.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
2023-11-23T22:28:29Z
For your task you can uselangchain 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.
2024-07-20T21:58:21Z
Hi,did you ever figure it out,  I am having the same problem.
2024-07-21T10:59:42Z
All I tried failed, so I ended up using openAI, asking in the system prompt to reply with a JSON structure. It doesn’t work perfectly, but you can format the string into a valid JSON with some processing of the response.You’ve also got theJSON mode, but the response is much poorer – with my requirements-. You may also want to look intofunction calling.