Instructions to use ibm-granite/granitelib-rag-r1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Granite Library
How to use ibm-granite/granitelib-rag-r1.0 with Granite Library:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
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>
- 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 |
-
|
| 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
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
and actionable.
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
The
|
| 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
|
| 36 |
|
| 37 |
-
The
|
| 38 |
-
-
|
| 39 |
-
-
|
| 40 |
-
- Improving answer quality by identifying ambiguities early
|
| 41 |
-
- Enhancing user experience in conversational AI systems
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
**Intrinsic input**: The input
|
| 47 |
|
| 48 |
-
**Intrinsic output**: The output
|
| 49 |
-
JSON object as follows:
|
| 50 |
```json
|
| 51 |
{
|
| 52 |
-
"clarification": <Clarification question
|
| 53 |
}
|
| 54 |
```
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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
|
| 94 |
|
| 95 |
### Training Data
|
| 96 |
|
| 97 |
-
The training
|
| 98 |
-
-
|
| 99 |
-
-
|
| 100 |
-
-
|
| 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 |
-
|
| 106 |
|
| 107 |
-
|
| 108 |
-
- IBM Granite 4.0 Micro
|
| 109 |
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
-
###
|
| 123 |
|
| 124 |
-
The
|
|
|
|
|
|
|
|
|
|
| 125 |
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
|
| 135 |
-
|
| 136 |
-
-
|
| 137 |
-
-
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
-
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
-
|
|
|
|
| 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.
|