Granite Library
Safetensors
GGUF
English
frreiss commited on
Commit
20ae30f
·
verified ·
1 Parent(s): 9e187fd

Query clarification migration (#9)

Browse files

- feat: add query clarification intrinsic, migrate from old repo (848be843a39ccbf34969550c63a8299782305e40)
- feat: add query clarification model for Ollama (60df3556fda54957cdeb422121858ab9c91f99b7)
- feat: add query_clarification IO yaml file (a288529f5283d3923bd6b973475133abaaf32b04)

query_clarification/README.md ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ 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)
30
+ - **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
31
+
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
query_clarification/granite-4.0-micro/lora/adapter_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "ibm-granite/granite-4.0-micro",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "eva_config": null,
10
+ "exclude_modules": null,
11
+ "fan_in_fan_out": false,
12
+ "inference_mode": true,
13
+ "init_lora_weights": true,
14
+ "layer_replication": null,
15
+ "layers_pattern": null,
16
+ "layers_to_transform": null,
17
+ "loftq_config": {},
18
+ "lora_alpha": 64,
19
+ "lora_bias": false,
20
+ "lora_dropout": 0.05,
21
+ "megatron_config": null,
22
+ "megatron_core": "megatron.core",
23
+ "modules_to_save": null,
24
+ "peft_type": "LORA",
25
+ "peft_version": "0.17.2.dev0@ec5a1b2ce62b14925239f62582eb3db5d9174af2",
26
+ "qalora_group_size": 16,
27
+ "r": 32,
28
+ "rank_pattern": {},
29
+ "revision": null,
30
+ "target_modules": [
31
+ "input_linear",
32
+ "output_linear",
33
+ "k_proj",
34
+ "q_proj",
35
+ "o_proj",
36
+ "v_proj"
37
+ ],
38
+ "target_parameters": null,
39
+ "task_type": "CAUSAL_LM",
40
+ "trainable_token_indices": null,
41
+ "use_dora": false,
42
+ "use_qalora": false,
43
+ "use_rslora": false
44
+ }
query_clarification/granite-4.0-micro/lora/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8bf22d4fe51f403feac79cc081fa1297e365591b48e5cd48b782153a0d054cf5
3
+ size 235995984
query_clarification/granite-4.0-micro/lora/io.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Model name string, or null to use whatever is provided in the chat completion request
2
+ model: ~
3
+ # JSON schema of the model's output
4
+ response_format: |
5
+ {
6
+ "properties": {
7
+ "clarification": {
8
+ "title": "clarification",
9
+ "type": "string"
10
+ }
11
+ },
12
+ "required": [
13
+ "clarification"
14
+ ],
15
+ "title": "QueryClarificationOutput",
16
+ "type": "object"
17
+ }
18
+ transformations: ~
19
+ instruction: ~
20
+ parameters:
21
+ max_completion_tokens: 1024
22
+ sentence_boundaries: false
query_clarification/granite4_micro/lora/Lora-q8_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0715cd4409af83a965f873df34351e0ec1b8aedf347926ec8f259728dd454624
3
+ size 288
query_clarification/granite4_micro/lora/Modelfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM granite4:micro
2
+ ADAPTER Lora-q8_0.gguf
query_clarification/granite4_micro/lora/io.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model: null
2
+ response_format: null
3
+ transformations: null
4
+ instruction: null
5
+ parameters:
6
+ response_format:
7
+ type: json_schema
8
+ json_schema:
9
+ schema:
10
+ properties:
11
+ clarification:
12
+ title: clarification
13
+ type: string
14
+ required:
15
+ - clarification
16
+ title: QueryClarificationOutput
17
+ type: object
18
+ strict: true
19
+ max_tokens: 1024
20
+ sentence_boundaries: false
21
+ docs_as_message: roles