Granite Library
Safetensors
GGUF
English
frreiss lucianpopa commited on
Commit
81fa512
·
1 Parent(s): a906a1f

Update query_clarification/README.md (#13)

Browse files

- Update query_clarification/README.md (a2a4f3b8f4429e4c0da1588d859b8b27a7b1b666)


Co-authored-by: Lucian Popa <lucianpopa@users.noreply.huggingface.co>

Files changed (1) hide show
  1. query_clarification/README.md +86 -93
query_clarification/README.md CHANGED
@@ -6,24 +6,20 @@ pipeline_tag: text-generation
6
  library_name: peft
7
  library_name: transformers
8
  ---
9
- ---
10
 
11
  # Query Clarification Intrinsic
12
 
13
  ## Model Summary
14
 
15
- <!-- Provide a quick summary of what the model is/does. -->
16
-
17
- We are releasing a query clarification intrinsic, implemented as a family of adapters that are fine-tuned specifically for the following task:
18
 
19
- Given a user query in a multi-turn conversation context, generate clarification questions
20
- that help disambiguate and better understand the user's intent when the query is ambiguous
21
- or incomplete. The clarification questions should help refine the query to be more specific
22
- and actionable.
23
 
24
- While the intrinsic is general purpose, one of its main use cases is in RAG settings where generating clarifying questions can help retrieve more relevant documents and provide better answers. Outside of RAG, there are other conversational use cases that require query clarification, for example, in customer support scenarios, database query interfaces, or multi-step reasoning systems. The intrinsic uses only the current query and conversation context to generate targeted clarification questions. We are providing experimental results in a RAG setting as well as on a specialized enterprise setup, showing in both cases that the intrinsic performance is significantly higher than when prompting out-of-the-box models, including open-source models and frontier models.
25
 
26
- The adapters released here work with the IBM granite-4.0-micro model.
27
 
28
  - **Developer:** IBM Research
29
  - **Model type:** LoRA adapter for [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
@@ -32,129 +28,126 @@ The adapters released here work with the IBM granite-4.0-micro model.
32
 
33
  ## Intended use
34
 
35
- The intrinsic gives the ability to generate clarification questions for a user query in a multi-turn conversation. These clarification questions are generated when the user's query may be ambiguous, incomplete, or when additional context is needed to better understand the user's intent. The generated questions can help guide the user to provide more specific information or can be used internally to better understand which aspect of the query to focus on.
36
 
37
- The clarification questions can be useful in several scenarios:
38
- - Helping users refine their queries before retrieval in a RAG setting
39
- - Supporting interactive query refinement workflows
40
- - Improving answer quality by identifying ambiguities early
41
- - Enhancing user experience in conversational AI systems
42
 
43
- > [!TIP]
44
- > Note: While you can invoke the query clarification intrinsic directly, it is strongly recommended to call it through [granite-common](https://github.com/ibm-granite/granite-common), which wraps the model with a tailored I/O processor, enabling a friendlier development interface. The I/O processor takes care of several data transformation and validation tasks that would be otherwise required (including sending the appropriate instruction for the intrinsic) as well as validating the intrinsic's output. We next describe the input/output of the query clarification intrinsic when invoked through granite-common.
 
 
45
 
46
- **Intrinsic input**: The input to the query clarification intrinsic is an OpenAI-compatible chat completion request, containing a list of conversation turns that can alternate between the `user` and `assistant` role, and ending with a `user` turn. The last `user` turn in the list is assumed to be the query that may need clarification.
47
 
48
- **Intrinsic output**: The output of the query clarification intrinsic is the result of the original chat completion request formatted as a
49
- JSON object as follows:
50
  ```json
51
  {
52
- "clarification": <Clarification question(s) to help disambiguate the user's intent>
53
  }
54
  ```
 
55
 
56
- Please see the code snippets in the Quickstart Example section below for examples that illustrate the intrinsic's input/output.
57
 
58
- ## Quickstart Example
59
 
60
- The recommended way to call this intrinsic is through the [Mellea](https://mellea.ai) framework.
61
- Here is some example code for calling this intrinsic from Mellea:
62
- ```
63
- from mellea.backends.huggingface import LocalHFBackend
64
- from mellea.stdlib.base import ChatContext
65
- from mellea.stdlib.chat import Message
66
- from mellea.stdlib.intrinsics import rag
67
-
68
-
69
- backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
70
- context = (
71
- ChatContext()
72
- .add(Message("assistant", "How can I help you today?"))
73
- .add(Message("user", "I want to learn about cats."))
74
- .add(
75
- Message(
76
- "assistant",
77
- "I'd be happy to help! There's a lot to cover about cats. "
78
- "Are you interested in cat behavior, care, history, or something else?",
79
- )
80
- )
81
- )
82
- next_user_turn = "Tell me about them."
83
-
84
- print(f"Original user question: {next_user_turn}")
85
-
86
- result = rag.clarify_question(next_user_turn, context, backend)
87
- print(f"Clarification: {result}")
88
  ```
89
 
 
 
 
 
 
 
90
 
91
  ## Training Details
92
 
93
- The training data contains examples with varying degrees of query ambiguity and incompleteness. The intrinsic learns to recognize when a query lacks sufficient specificity and to generate targeted clarification questions that address the identified ambiguities.
94
 
95
  ### Training Data
96
 
97
- The training data is derived from conversational datasets and RAG scenarios where query ambiguity is common. The dataset includes examples with:
98
- - Ambiguous references or underspecified entities
99
- - Missing context or implicit assumptions
100
- - Multiple possible interpretations of the user's intent
101
- - Queries that could benefit from additional information
102
-
103
- These examples are paired with high-quality clarification questions that effectively disambiguate the queries. Additionally, we have used synthetically generated examples to maximize coverage of different ambiguity patterns and improve the intrinsic's ability to handle diverse query types.
104
 
105
- #### Model Variants
106
 
107
- The intrinsic is available as a LoRA adapter for the following base models:
108
- - IBM Granite 4.0 Micro
109
 
110
- #### System Prompt Variations
111
 
112
- During training, we tested the adapter with multiple system prompt variations to ensure robustness:
113
 
114
- Version 1: <|start_of_role|>system<|end_of_role|> You are a helpful assistant that generates clarification questions to better understand ambiguous or incomplete user queries.<|end_of_text|>
 
 
 
 
 
 
115
 
116
- Version 2: <|start_of_role|>system<|end_of_role|> Knowledge Cutoff Date: April 2024. Today's Date: May 20, 2025. You are Granite, developed by IBM. Generate clarification questions that help disambiguate the user's intent based on the conversation context.<|end_of_text|>
117
 
118
- Version 3: An empty system prompt (no instructions provided).
119
 
120
- This approach ensures that the adapters remain effective and reliable across varying system prompt formats commonly encountered in real-world RAG applications.
121
 
122
- #### Training Hyperparameters
123
 
124
- The adapter was fine-tuned using PEFT under the following regime: rank = 32, learning rate = 3e-6, number of epochs = 25, and linear learning rate scheduler.
 
 
 
125
 
 
126
 
127
- ## Evaluation
128
 
129
- We provide two types of evaluation: 1) evaluation specific to the task of query clarification, 2) end-to-end evaluation in a RAG setting, where we evaluate how query clarification impacts the quality of retrieved documents and final answer generation.
130
 
131
- ### Evaluation Specific for the Query Clarification Task
 
 
132
 
133
- Here we evaluate the quality of the generated clarification questions on an enterprise internal dataset. This dataset contains queries with varying degrees of ambiguity, paired with human-validated clarification questions. We evaluate the model-generated clarifications using both automatic metrics and an LLM judge (with Llama-3.3-70b as the model) with specific prompts to assess whether the generated questions effectively disambiguate the original query.
134
 
135
- The evaluation focuses on:
136
- - Relevance: Do the clarification questions address actual ambiguities in the query?
137
- - Quality: Are the questions clear, concise, and helpful?
138
- - Efficiency: Do the questions effectively narrow down the user's intent with minimal overhead?
 
139
 
140
- ### End-to-End Evaluation in RAG Settings
141
 
142
- We evaluate the query clarification intrinsic in a complete RAG pipeline where:
143
- 1. A user provides an initial query
144
- 2. Clarification questions are generated
145
- 3. The clarified query (or queries) are used for retrieval
146
- 4. The retrieved documents are used for answer generation
147
 
148
- We measure improvements in:
149
- - Retrieval relevance and recall metrics
150
- - Final answer quality and relevance to the user's actual intent
151
- - User satisfaction in interactive query refinement scenarios
152
 
 
153
 
154
- ## Contact
 
 
155
 
156
- [Lucian Popa](mailto:lpopa@us.ibm.com)
157
 
158
- ### Framework versions
 
 
 
 
159
 
160
- - PEFT 0.17.2
 
6
  library_name: peft
7
  library_name: transformers
8
  ---
 
9
 
10
  # Query Clarification Intrinsic
11
 
12
  ## Model Summary
13
 
14
+ We are releasing a query clarification intrinsic, implemented as a LoRA adapter fine-tuned specifically for the following task:
 
 
15
 
16
+ Given a multi-turn conversation between a user and an AI assistant (and optionally relevant content such as
17
+ RAG documents), detect whether the last user query is underspecified (no clear interpretation or multiple
18
+ valid interpretations) and, if so, formulate an appropriate clarification request back to the user.
 
19
 
20
+ The intrinsic is designed for conversational use cases where user queries may be ill-formed, unclear, or have multiple valid interpretations based on the underlying system or content. Use cases include RAG systems, routing, and tool invocation scenarios. We provide experimental results showing that the intrinsic achieves significantly higher classification accuracy than prompted out-of-the-box models, including frontier models such as gpt-4o.
21
 
22
+ The adapter released here works with the IBM granite-4.0-micro model.
23
 
24
  - **Developer:** IBM Research
25
  - **Model type:** LoRA adapter for [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
 
28
 
29
  ## Intended use
30
 
31
+ The intrinsic detects whether the last user query in a multi-turn conversation is underspecified and generates a clarification request if needed. A query may be underspecified due to:
32
 
33
+ - **Ambiguous references**: The query refers to entities or concepts that have multiple valid interpretations in the content (e.g., "What browser are you using?" when multiple browsers are documented)
34
+ - **Ill-formed questions**: The query is unclear or makes implicit references that cannot be resolved from context alone
35
+ - **Multiple valid choices**: The user's intent could map to several different actions, routes, or entities in the system
 
 
36
 
37
+ The intrinsic generates clarification requests using different patterns depending on the number of matching options:
38
+ - **Hedging with answers**: For a small number of options, provide partial answers for each interpretation
39
+ - **Hedging list**: For a medium number of options, list the possible interpretations and ask which one
40
+ - **Open domain**: For many possible matches, ask an open-ended clarifying question
41
 
42
+ **Intrinsic input**: The input is an OpenAI-compatible chat completion request containing conversation turns (alternating `user` and `assistant` roles) ending with a `user` turn, optionally with relevant content/documents.
43
 
44
+ **Intrinsic output**: The output is a JSON object as follows:
 
45
  ```json
46
  {
47
+ "clarification": <Clarification question or "CLEAR">
48
  }
49
  ```
50
+ The `clarification` field contains either a clarification question if the query is underspecified, or `CLEAR` if the query does not need clarification.
51
 
52
+ ### Example
53
 
54
+ **Input conversation:**
55
 
56
+ | Role | Message |
57
+ |------|---------|
58
+ | user | Is the language that descended from Common Brittonic still spoken today, or has it become extinct? |
59
+
60
+ **Relevant content (RAG documents):** Information about Celtic Britons, Common Brittonic language, Welsh, Breton, Cornish, and Cumbric languages.
61
+
62
+ **Output:**
63
+ ```json
64
+ {
65
+ "clarification": "Several languages descended from Common Brittonic are still spoken or have been revived, like Welsh—a living language in Wales—Breton, spoken in Brittany, or Cornish, which was extinct but has seen recent revitalization. Which one are you referring to?"
66
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ```
68
 
69
+ In this example, the intrinsic detects that the user's question is underspecified because multiple languages descended from Common Brittonic, and generates a clarification request using the "hedging with answers" pattern—providing partial answers for each interpretation before asking for clarification.
70
+
71
+ ## Usage Examples
72
+
73
+ The recommended way to call this intrinsic is through the [Mellea](https://mellea.ai) framework. For detailed examples on how to use this and other intrinsics, please refer to the [Mellea intrinsics examples](https://github.com/generative-computing/mellea/tree/main/docs/examples/intrinsics).
74
+
75
 
76
  ## Training Details
77
 
78
+ The training data contains both positive examples (underspecified queries with corresponding clarification requests) and negative examples (clear queries that should not trigger clarification). Hard negatives are included to help the model learn the boundary between clear and underspecified queries.
79
 
80
  ### Training Data
81
 
82
+ The training dataset consists of:
83
+ - Human-generated underspecified questions created by annotators over content from Gov and ClapNQ domains
84
+ - Multi-turn conversations with underspecified final turns
85
+ - Synthetically generated clarification requests using target patterns (hedging with answers, hedging list, open domain)
 
 
 
86
 
87
+ The training dataset is proprietary and was obtained in combination with a third-party company who contracted the human annotators.
88
 
89
+ ### Robustness to System Prompts
 
90
 
91
+ Different researchers or practitioners may use various system prompts tailored to their specific use cases. For the IBM granite versions of the adapter, to enhance robustness against these variations, we generated multiple versions of each training sample with different system prompts.
92
 
93
+ #### Training Hyperparameters
94
 
95
+ The adapter was fine-tuned using PEFT under the following regime:
96
+ - Learning rate: 1e-5
97
+ - Rank: 32
98
+ - LoRA alpha: 64
99
+ - Dropout: 0.05
100
+ - Epochs: 20 with early stopping
101
+ - Hard negatives ratio: 0.7
102
 
 
103
 
104
+ ## Evaluation
105
 
106
+ We evaluate the intrinsic on two dimensions: (1) classification accuracy in detecting underspecified vs. clear queries, and (2) quality of generated clarification requests.
107
 
108
+ ### Test Set
109
 
110
+ The evaluation uses a test set containing:
111
+ - 80 positive examples: conversations where the last user question is underspecified
112
+ - 150 random negatives: conversations where the last user question is clear
113
+ - 50 hard negatives: conversations intended to be underspecified but adjudicated as clear by humans
114
 
115
+ ### Classification Results
116
 
117
+ **Overall Accuracy:**
118
 
119
+ **Trained LoRA:**
120
 
121
+ | Model | Underspecified (80) | CLEAR - random (150) | CLEAR - hard (50) | Overall Accuracy |
122
+ |-------|---------------------|----------------------|-------------------|------------------|
123
+ | Granite-4.0-micro LoRA | 81.25% | 100% | 86% | **92.14%** |
124
 
125
+ **OOB models (prompted, zero-shot):**
126
 
127
+ | Model | Underspecified (80) | CLEAR - random (150) | CLEAR - hard (50) | Overall Accuracy |
128
+ |-------|---------------------|----------------------|-------------------|------------------|
129
+ | gpt-oss-20b | 85% | 78% | 62% | 77.14% |
130
+ | GPT 4o | 60% | 85.3% | 48% | 71.42% |
131
+ | Granite-4.0-micro | 97.5% | 5.3% | 0% | 30.71% |
132
 
133
+ The LoRA achieves significantly higher overall accuracy due to its ability to correctly identify clear queries, while prompted models tend to over-clarify.
134
 
135
+ ### Clarification Quality Results
 
 
 
 
136
 
137
+ For queries correctly identified as underspecified, we measure the quality of generated clarification requests using an LLM judge (Llama-3.3-70b). The numbers in parentheses indicate how many of the 80 underspecified records each model correctly identified and generated clarifications for—quality metrics are measured only on those data points.
 
 
 
138
 
139
+ **Trained LoRA:**
140
 
141
+ | Model | Precision | Recall | F1 |
142
+ |-------|-----------|--------|-----|
143
+ | Granite-4.0-micro LoRA (65/80) | 88.4% | 78.3% | 83.0% |
144
 
145
+ **OOB models (prompted, zero-shot):**
146
 
147
+ | Model | Precision | Recall | F1 |
148
+ |-------|-----------|--------|-----|
149
+ | GPT 4o (48/80) | 91.9% | 83.4% | 87.4% |
150
+ | gpt-oss-20b (68/80) | 86.9% | 66.9% | 75.6% |
151
+ | Granite-4.0-micro (78/80) | 74.9% | 58.0% | 65.4% |
152
 
153
+ The LoRA achieves clarification quality close to GPT-4o while maintaining much better classification accuracy and evaluating on more data points.