-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix array generation stopping criteria #47
base: main
Are you sure you want to change the base?
fix array generation stopping criteria #47
Conversation
Hello, Cause today, when I parse some resume to get jsonfile, i only have 1 element in my array (95% of the time) where I should be have 2 or 3. |
Hello @thomasBontempsTecrisViattech |
Yes exactly the goal of my application. I got an PDF resume that I transform into an TXT into JSON. So to simplify, i use the TXT file in the prompt and the JSON schema. I put images to show you (schema, response, choices). When I precise the size of the array in the json schema file, I can sometimes have more possibilities but it is totaly random. |
@thomasBontempsTecrisViattech Yeah, it extracted Python as soft skills, I'm sure that is not the intended behavior? |
Ok thanks ! That's what I thought. |
happy to see there is a solution for the issue with generating arrays. thanks |
Hello, To improve arrays predictions :
You don't need to mention the JSON schema in the prompt. So you will have something like this :
`` And the function of the LLM class is the same, so :
`` I hope it will help you.
|
Hey @noobmldude |
ok looks like latest commits are from previous year. |
I merged it in this branch, where I added probabilities too https://github.com/wassname/prob_jsonformer |
Issue
According to Issue #46 array generation has some problems. Mainly it usually stops generating earlier than intended.
How it used to be done?
Once we enter an array generation we would first generate the first value in the array and immediately check whether to continue the generation of the array by asking the LLM to generate the next token. We would do this using the
.forward
method, we would sort the top 30 results from logits and check if we encounter a "," or "]". The "," would indicate we want to keep generating while the "]" would tell us that the array is done and to move one.The problem with this approach was that tokens such as
]);
,]@
etc. would often appear here and would terminate the array generation too early.The solution
I simplified the process by prompting the LLM using the
.generate
method and passing aLogitsWarper
that only allows the generation of "," and "]". This way we make the LLM choose whether to keep generating the array or end it. We then check the generated token and act accordingly. This ends up being a lot more reliable.LogitsWarper masks the output tokens
LLM decides what to do