Grammar-Constrained LLM Attribute Generation for Hallucination Reduction
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Generative language models, such as LLMs, tend to hallucinate, providing incorrect or irrelevant outputs due to incomplete training or fine-tuning, and existing solutions like prompt engineering and classifiers face limitations in correcting errors and scaling.
Innovation Solution
Classify the input to determine its category, obtain a grammar defining valid sequences of symbols for that category, and use a generative language model to generate a sequence of symbols that conform to the grammar, applying a mask to reduce probabilities of non-compliant tokens.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If prompt engineering is used to increase specificity of textual input, then hallucination is reduced, but the LLM may still not adhere to instructions when the textual description is particularly large
Solution Approach 1:
The patent introduces a grammar-based constraint system as an intermediary between the LLM and the generation process. The grammar defines valid sequences of symbols and acts as a mediator that guides the LLM to produce outputs conforming to desired terminology and structure, without requiring direct instruction following in the prompt
Solution Approach 2:
The patent modifies the probability parameters of token selection by applying masks that reduce or eliminate probabilities of tokens not compliant with the grammar. This changes the parameter space of valid outputs, constraining the LLM to generate only grammatically correct sequences
2Manufacturing precision
If post-generation modification of textual description is attempted, then terminology can be corrected, but tokens occurring after modified tokens could have been different had the modified tokens appeared in the original sequence
Solution Approach 1:
The patent applies grammar constraints during the generation process itself, before the sequence is complete. By constraining token selection at each step according to the grammar, the system ensures consistency throughout the entire sequence without requiring post-generation modification
Solution Approach 2:
The patent implements a feedback mechanism where the grammar rules continuously guide token selection during generation. The system checks each generated token against the grammar and adjusts subsequent token probabilities accordingly, maintaining consistency throughout the sequence
3Reliability
If a classifier is used to describe attributes, then scaling challenges arise when new attributes need to be added
Solution Approach 1:
The patent creates a universal grammar-based framework that can handle multiple attributes and categories through a single system. The grammar can be configured to define valid sequences for different categories (e.g., shoes, shirts) and their attributes, allowing the same LLM to handle diverse classification tasks without requiring separate classifiers for each attribute
Data Source
AI summary
One drawback of generative language models, e.g. large language models (LLMs), is their tendency to “hallucinate”. To address at least this technical problem of hallucination, in some examples, an input may be classified to determine a category associated with the input. In some examples, the input may be an image. A grammar may be obtained based on the determined category. The grammar may define valid sequences of symbols describing attributes of the category. A generative language model may be used to generate a sequence of symbols describing one or more attributes associated with the input. The sequence may be based on the input and conform to the grammar. In some examples, the generative language model may be an LLM.


