Instructions to use ibm-granite/granitelib-core-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-core-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
- PEFT
How to use ibm-granite/granitelib-core-r1.0 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Update READMEs (#37)
Browse files- Update root README.md (e382f994a53083340ac756818b9fd24869743e55)
- Update Context Attribution README (703afb713ac006a7a6f533cda65f9606e33f9836)
- Updated RC README.md (cbb9d94a3bb1c1436818e4aee7d4c4018f4dc1ad)
- Update UQ README (22fad6714b920494acee05b3e513b93a90468359)
- Delete uncertainty/granite-4.0-micro/README.md (a1b9328ec64cefccd01ca01569cc5b97e6f2bd45)
- Delete requirement-check/granite-4.0-micro/README.md (bb38dd1259206d21b6301bf49762d2a45713cf63)
- Delete context-attribution/granite-4.0-micro/README.md (40c1fdc8f6d4e01d667c56d63f86036cc3344fd2)
- Delete uncertainty/granite-4.0-micro/.gitattributes (c066afbf85ea5c67b4998ef2c53a5c9ced856464)
- Update requirement-check/README.md (25638fa8bed24323db7ab16d3a6362b8dc7e8261)
Co-authored-by: Inkit <ink-pad@users.noreply.huggingface.co>
- README.md +69 -6
- context-attribution/{granite-4.0-micro/README.md → README.md} +116 -46
- requirement-check/README.md +257 -0
- requirement-check/granite-4.0-micro/README.md +0 -267
- uncertainty/README.md +178 -0
- uncertainty/granite-4.0-micro/.gitattributes +0 -1
- uncertainty/granite-4.0-micro/README.md +0 -136
|
@@ -4,7 +4,11 @@ language:
|
|
| 4 |
- en
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
library_name: granite-library
|
| 7 |
-
base_model:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
tags:
|
| 9 |
- granite
|
| 10 |
- uncertainty
|
|
@@ -16,15 +20,74 @@ tags:
|
|
| 16 |
|
| 17 |
# Granite Core Library
|
| 18 |
|
| 19 |
-
The Granite Core Library includes three LoRA adapters
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
|
| 22 |
## Capabilities implemented as LoRA adapters
|
| 23 |
|
| 24 |
-
The three capabilities that have been implemented as LoRA adapters
|
| 25 |
|
| 26 |
-
**Context Attribution:** A LoRA adapter that predicts which sentences in the context (including documents and previous conversation turns) were most important for the base model to generate each sentence in its response. The adapter provides contributive attribution, identifying the context sentences that actually influenced the model's response, and ranks them by importance. This is a post-generation intrinsic designed to explain the base model's behavior. Details can be found in the [context-attribution readme](context-attribution/
|
| 27 |
|
| 28 |
-
**Requirement Check:** A LoRA adapter that judges whether an assistant's generation satisfies a set of user-specified requirements, outputting a binary yes/no assessment. It is designed for evaluating constraint satisfaction in instruction-following scenarios, including formatting, content, structural requirements, and quality assurance pipelines. Details can be found in the [requirement-check readme](requirement-check/
|
| 29 |
|
| 30 |
-
**Uncertainty:** A LoRA adapter that provides calibrated certainty scores for the base model's responses. Given a conversation ending with an assistant response, it calculates a certainty percentage reflecting how confident the model is about its answer. Certainty scores are calibrated such that among answers assigned a score of X%, approximately X% are correct. Details can be found in the [uncertainty readme](uncertainty/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- en
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
library_name: granite-library
|
| 7 |
+
base_model:
|
| 8 |
+
- ibm-granite/granite-4.0-micro
|
| 9 |
+
- ibm-granite/granite-4.1-3b
|
| 10 |
+
- ibm-granite/granite-4.1-8b
|
| 11 |
+
- ibm-granite/granite-4.1-30b
|
| 12 |
tags:
|
| 13 |
- granite
|
| 14 |
- uncertainty
|
|
|
|
| 20 |
|
| 21 |
# Granite Core Library
|
| 22 |
|
| 23 |
+
The Granite Core Library includes three families of LoRA adapters, each developed for a specific task that enhances the base model's capabilities for explainability, calibration, and constraint verification. We provide adapters for:
|
| 24 |
+
* [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
|
| 25 |
+
* [ibm-granite/granite-4.1-3b](https://huggingface.co/ibm-granite/granite-4.1-3b)
|
| 26 |
+
* [ibm-granite/granite-4.1-8b](https://huggingface.co/ibm-granite/granite-4.1-8b)
|
| 27 |
+
* [ibm-granite/granite-4.1-30b](https://huggingface.co/ibm-granite/granite-4.1-30b)
|
| 28 |
|
| 29 |
+
We give a brief overview of the functionality of each capability below; details can be found in each individual adapter readme.
|
| 30 |
|
| 31 |
## Capabilities implemented as LoRA adapters
|
| 32 |
|
| 33 |
+
The three capabilities that have been implemented as LoRA adapters and made available in this HF repository are:
|
| 34 |
|
| 35 |
+
**Context Attribution:** A LoRA adapter that predicts which sentences in the context (including documents and previous conversation turns) were most important for the base model to generate each sentence in its response. The adapter provides contributive attribution, identifying the context sentences that actually influenced the model's response, and ranks them by importance. This is a post-generation intrinsic designed to explain the base model's behavior. Details can be found in the [context-attribution readme](context-attribution/README.md).
|
| 36 |
|
| 37 |
+
**Requirement Check:** A LoRA adapter that judges whether an assistant's generation satisfies a set of user-specified requirements, outputting a binary yes/no assessment. It is designed for evaluating constraint satisfaction in instruction-following scenarios, including formatting, content, structural requirements, and quality assurance pipelines. Details can be found in the [requirement-check readme](requirement-check/README.md).
|
| 38 |
|
| 39 |
+
**Uncertainty:** A LoRA adapter that provides calibrated certainty scores for the base model's responses. Given a conversation ending with an assistant response, it calculates a certainty percentage reflecting how confident the model is about its answer. Certainty scores are calibrated such that among answers assigned a score of X%, approximately X% are correct. Details can be found in the [uncertainty readme](uncertainty/README.md).
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
## Recommended Use
|
| 44 |
+
|
| 45 |
+
The recommended way to call all adapters is through the [Mellea](https://mellea.ai) framework. For code snippets demonstrating how to use them please refer to the [Mellea adapter examples](https://github.com/generative-computing/mellea/tree/main/docs/examples/intrinsics) (note: within Mellea, adapters are referred to as "intrinsics").
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
## Model Signing
|
| 49 |
+
|
| 50 |
+
All adapter artifacts in this repository are signed to ensure integrity and provenance. Each adapter includes a `model.sig` signature file in its `lora/` directory that covers all artifacts in that directory (`adapter_config.json`, `adapter_model.safetensors`, `io.yaml`).
|
| 51 |
+
|
| 52 |
+
| Adapter | Signature File Path (example) | Signing Identity |
|
| 53 |
+
|-----------|-------------------------------|-----------------|
|
| 54 |
+
| Context Attribution | `context-attribution/granite-4.1-3b/lora/model.sig` | `Granite-sign@ibm.com` |
|
| 55 |
+
| Requirement Check | `requirement-check/granite-4.1-3b/lora/model.sig` | `Granite-sign@ibm.com` |
|
| 56 |
+
| Uncertainty | `uncertainty/granite-4.1-3b/lora/model.sig` | `Granite-sign@ibm.com` |
|
| 57 |
+
|
| 58 |
+
The same pattern applies to all model variants (`granite-4.0-micro`, `granite-4.1-3b`, `granite-4.1-8b`, `granite-4.1-30b`).
|
| 59 |
+
|
| 60 |
+
### Verifying Model Signatures
|
| 61 |
+
|
| 62 |
+
To verify the integrity of a downloaded adapter, use the [model-signing](https://github.com/sigstore/model-transparency) tool:
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
# Install the model signing verification tool
|
| 66 |
+
pip install model-signing
|
| 67 |
+
|
| 68 |
+
# Verify all artifacts in an adapter's lora/ directory
|
| 69 |
+
model_signing verify sigstore \
|
| 70 |
+
--signature <adapter>/<model-variant>/lora/model.sig \
|
| 71 |
+
--identity Granite-sign@ibm.com \
|
| 72 |
+
--identity_provider https://sigstore.verify.ibm.com/oauth2 \
|
| 73 |
+
<adapter>/<model-variant>/lora/
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
For example, to verify the context-attribution adapter for granite-4.1-3b:
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
model_signing verify sigstore \
|
| 80 |
+
--signature context-attribution/granite-4.1-3b/lora/model.sig \
|
| 81 |
+
--identity Granite-sign@ibm.com \
|
| 82 |
+
--identity_provider https://sigstore.verify.ibm.com/oauth2 \
|
| 83 |
+
context-attribution/granite-4.1-3b/lora/
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Each `model.sig` file contains a signature over all adapter artifacts in the corresponding `lora/` directory, signed with the identity `Granite-sign@ibm.com`. This allows users to confirm that the adapter has not been tampered with after release.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
## Resources
|
| 90 |
+
|
| 91 |
+
- Learn about the latest updates with Granite: https://www.ibm.com/granite
|
| 92 |
+
- Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
|
| 93 |
+
- Learn about the latest Granite learning resources: https://ibm.biz/granite-learning-resources
|
|
@@ -2,24 +2,28 @@
|
|
| 2 |
|
| 3 |
## Model Summary
|
| 4 |
|
| 5 |
-
**Context Attribution** is a purpose-built
|
| 6 |
|
| 7 |
-
The context attribution model takes the form of a [LoRA adapter](https://arxiv.org/abs/2106.09685). The adapter greatly improves
|
| 8 |
|
| 9 |
- **Developer:** IBM Research
|
| 10 |
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 11 |
- **GitHub Repository:** https://github.com/ibm-granite
|
| 12 |
-
- **Release Date:**
|
| 13 |
-
- **Model Type:** LoRA
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 15 |
- **Paper:** Context Attribution is trained to approximate the importance ranking of context sentences provided by the MExGen method in [[Monteiro Paes and Wei et al., ACL 2025] Multi-Level Explanations for Generative Language Models](https://aclanthology.org/2025.acl-long.1553/).
|
| 16 |
|
| 17 |
|
| 18 |
## Usage
|
| 19 |
|
| 20 |
-
**Intended use:** Context Attribution is a context attribution adapter intended for
|
| 21 |
|
| 22 |
-
The context attribution adapter is similar to the [citations adapter](https://huggingface.co/ibm-granite/granitelib-rag-r1.0/blob/main/citations/README.md) found in the [granitelib-rag-r1.0](https://huggingface.co/ibm-granite/granitelib-rag-r1.0) library, in that it uses a comparable input/output format and similiar training data. However, the two differ in the type of attribution they provide. Citation generation provides corroborative attribution, identifying document sentences that best support a response regardless of whether the model relied on them, making it model-agnostic. In contrast, the context attribution adapter provides contributive attribution, identifying the context sentences that actually influenced
|
| 23 |
|
| 24 |
**Input Format** The context attribution LoRA expects the input to be processed as follows: 1) The last assistant response (the response to be attributed) should be split into sentences and the sentences numbered with tags as follows: `"<r0> sentence 0 <r1> sentence 1 ... "`. 2) The context (documents and previous conversation turns) should also be split into sentences and tagged as `"<c0> sentence 0 <c1> sentence 1 ... "`. The numbering of context sentences starts with the first document (if present) and continues as a single sequence through all the documents and then previous conversation turns, in that order. This input processing is performed automatically if the context attribution adapter is called using IBM's [mellea](https://github.com/generative-computing/mellea) package, as the Quickstart Example below shows. Alternatively, the user can insert sentence tags manually or by other means (also shown in the Quickstart Example below).
|
| 25 |
|
|
@@ -27,7 +31,7 @@ The context attribution adapter is similar to the [citations adapter](https://hu
|
|
| 27 |
|
| 28 |
**Use Cases**
|
| 29 |
* Human understanding: Context attribution helps to explain a base LLM by showing which parts of the context were most important to it in generating a certain response. Such views into the LLM's behavior may help users calibrate their trust in using the LLM in a particular domain.
|
| 30 |
-
* RAG: The
|
| 31 |
* Context reliance assessment: Context attribution can also be used to assess whether an LLM makes use of its context at all for a specific response. Low attribution scores to all context sentences might mean one of several things: 1) The response sentence is strongly implied by previous response sentences and does not need to refer to context; 2) the response comes primarily from the LLM's parametric knowledge; 3) the response is hallucinated. As such, determining the main reason for context non-reliance would require further investigation.
|
| 32 |
|
| 33 |
|
|
@@ -51,36 +55,36 @@ messages = [
|
|
| 51 |
question = "What was the concept behind the formation of the Plastic Ono Band?"
|
| 52 |
messages.append({"role": "user", "content": question})
|
| 53 |
|
| 54 |
-
# Response pre-generated by granite-4.
|
| 55 |
-
response = "The Plastic Ono Band was formed by John Lennon and Yoko Ono in 1969 as a collaborative vehicle for their
|
| 56 |
```
|
| 57 |
|
| 58 |
**Usage with Mellea**
|
| 59 |
```python
|
| 60 |
import json # only for display
|
| 61 |
|
| 62 |
-
from mellea
|
| 63 |
from mellea.stdlib.components import Document, Message # constructing the conversation
|
| 64 |
from mellea.stdlib.components.intrinsic.core import find_context_attributions # intrinsic function for calling context attribution
|
| 65 |
-
from mellea.stdlib.context import ChatContext # constructing the conversation
|
| 66 |
|
| 67 |
-
backend =
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Previous conversation turns + current question
|
| 70 |
-
context = ChatContext()
|
| 71 |
for message in messages:
|
| 72 |
-
|
| 73 |
# Documents
|
| 74 |
documents_mellea = [Document(**document) for document in documents]
|
| 75 |
|
| 76 |
# Call context attribution intrinsic function
|
| 77 |
-
result = find_context_attributions(response, documents_mellea,
|
| 78 |
print(f"Result of context attribution intrinsic:\n{json.dumps(result, indent=2)}")
|
| 79 |
|
| 80 |
-
# Prints an array of JSON objects where each object shows a response sentence,
|
| 81 |
# a context sentence to which the response sentence is attributed (in order of decreasing importance),
|
| 82 |
# and other fields such as the document ID where the context sentence is located.
|
| 83 |
-
# (You may get slightly different orderings of context sentences
|
| 84 |
```
|
| 85 |
|
| 86 |
**Usage without Mellea**
|
|
@@ -89,9 +93,9 @@ import torch
|
|
| 89 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 90 |
from peft import PeftModel
|
| 91 |
|
| 92 |
-
BASE_NAME = "ibm-granite/granite-4.
|
| 93 |
ADAPTER_REPO = "ibm-granite/granitelib-core-r1.0"
|
| 94 |
-
ADAPTER_SUBFOLDER = "context-attribution/granite-4.
|
| 95 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 96 |
|
| 97 |
# Load context attribution model (base model + LoRA)
|
|
@@ -103,7 +107,7 @@ model_ca = PeftModel.from_pretrained(
|
|
| 103 |
)
|
| 104 |
|
| 105 |
# The context attribution adapter expects the last assistant response and context (documents
|
| 106 |
-
# + previous conversation turns) to be split into sentences and the sentences to be tagged with numbers.
|
| 107 |
# In this snippet, we assume that this input processing has been done as below.
|
| 108 |
documents_rewritten = [
|
| 109 |
{"doc_id": "0", "text": "<c0> The Plastic Ono Band is a band formed by John Lennon and Yoko Ono in 1969 as a vehicle for their collaborative and solo projects. <c1> Lennon and Ono had begun a personal and artistic relationship in 1968, collaborating on several experimental releases. <c2> Following their marriage in 1969, they decided that all of their future endeavours would be credited to a conceptual and collaborative vehicle, Plastic Ono Band. <c3> The band would go on to feature a rotating lineup of many musicians, including Eric Clapton, Klaus Voormann, Alan White, Billy Preston, Jim Keltner, Delaney & Bonnie and Friends, and Lennon's former Beatles bandmates George Harrison and Ringo Starr. <c4> Lennon and Ono left the UK to settle in New York City during the fall of 1971. <c5> In Greenwich Village, the couple became more politically active and began writing protest songs. <c6> These songs became the basis for their next album, Some Time in New York City. <c7> As backing, they enlisted the help of New York band Elephant's Memory, consisting of guitarist Wayne 'Tex' Gabriel, bassist Gary Van Scyoc, saxophonist Stan Bronstein, keyboardist Adam Ippolito, keyboardist John La Boosca, and drummer Richard Frank, Jr. <c8> Phil Spector produced, and Jim Keltner also played on the album. <c9> The album was released on 12 June 1972, credited to \"John & Yoko/Plastic Ono Band with Elephant's Memory plus Invisible Strings\". <c10> Some Time in New York City included a second disc, entitled Live Jam, which included the recordings from the 1969 Peace for Christmas concert and the 1971 performance with Frank Zappa. <c11> Ono and Lennon continued their work with Elephant's Memory throughout 1972, performing as the Plastic Ono Elephant's Memory Band (which also included Jim Keltner). <c12> On 30 August, they performed a pair of benefit concerts at Madison Square Garden. <c13> The benefit, entitled \"One to One\", was organised by Geraldo Rivera to raise money for children with mental challenges. <c14> By this time, La Boosca had departed the band, and the concert saw the addition of John Ward on bass. <c15> The concert was filmed and recorded, later released in February 1986 as the album Live In New York City. <c16> They also performed at the Jerry Lewis MDA Labor Day Telethon. <c17> The last collaboration of the Plastic Ono Elephant's Memory Band was Ono's double album Approximately Infinite Universe. <c18> It was recorded throughout the fall of 1972, and was released in January 1973."},
|
|
@@ -114,7 +118,7 @@ messages_rewritten = [
|
|
| 114 |
{"role": "user", "content": "<c70> Who were the members of The Metal Ono Band, which was formed by Yoko Ono in 1976 to explore her interest in heavy metal music?"},
|
| 115 |
{"role": "assistant", "content": "<c71> I'm sorry, but I don't have the data to answer that specific question."},
|
| 116 |
{"role": "user", "content": "<c72> What was the concept behind the formation of the Plastic Ono Band?"},
|
| 117 |
-
{"role": "assistant", "content": "<r0> The Plastic Ono Band was formed by John Lennon and Yoko Ono in 1969 as a collaborative vehicle for their
|
| 118 |
{"role": "user", "content": "You provided the last assistant response above based on context, which may include documents and/or previous conversation turns. Your response is divided into sentences, numbered in the format <r0> sentence 0 <r1> sentence 1 ... Sentences in the context are also numbered: <c0> sentence 0 <c1> sentence 1 ... For each response sentence, please list the context sentences that were most important for you to generate the response sentence. Provide your answer in JSON format, as an array of JSON objects, where each object has two members: \"r\" with the response sentence number as the value, and \"c\" with an array of context sentence numbers as the value. An example of such an array of objects is [{\"r\": 0, \"c\": [3, 1, 4]}, {\"r\": 1, \"c\": [1, 5]}]. List the context sentences in order from most important to least important. Ensure that you include an object for each response sentence, even if the corresponding array of context sentence numbers is empty. Answer with only the JSON and do not explain.\n"},
|
| 119 |
]
|
| 120 |
|
|
@@ -125,55 +129,121 @@ output_text = tokenizer.decode(output_tokens[0, inputs["input_ids"].shape[1]:],
|
|
| 125 |
|
| 126 |
print(output_text)
|
| 127 |
|
| 128 |
-
# [{"r": 0, "c": [0,
|
| 129 |
-
# This raw output from the adapter means that response
|
| 130 |
-
#
|
| 131 |
-
# (You may get slightly different orderings of context sentences
|
| 132 |
```
|
| 133 |
|
| 134 |
-
## Evaluation
|
| 135 |
|
| 136 |
-
The context attribution
|
| 137 |
|
| 138 |
The evaluation metric is the area under the perturbation curve (AUPC), a standard metric for evaluating the faithfulness of a feature-attribution-like explanation to the model being explained. Please see the [MExGen paper](https://aclanthology.org/2025.acl-long.1553/) for more details on AUPC. Here, the perturbation curves are first multiplied by a linearly decreasing weight function, which decreases from 1 at 0% perturbation to 0 at 20% perturbation, yielding the weighted area under the perturbation curve (WAUPC).
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
| method | MD2D-QUAC | ELI5 | CNN/DM | XSum | average |
|
| 141 |
|:---------------------------|------------:|-------:|---------:|-------:|----------:|
|
| 142 |
| LOO *(skyline)* | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
|
| 143 |
| LOO thresholded *(realistic skyline)* | 0.9780 | 0.9812 | 0.9976 | 0.9983 | 0.9888 |
|
| 144 |
-
| prompt 0-shot | 0.1476 | 0.1657 | 0.1629 | 0.2369 | 0.1783 |
|
| 145 |
-
| prompt 1-shot | 0.1982 | 0.2171 | 0.1693 | 0.2014 | 0.1965 |
|
| 146 |
| prompt GPT-OSS-120B 0-shot | 0.8619 | 0.8063 | 0.8735 | 0.6679 | 0.8024 |
|
| 147 |
| prompt GPT-OSS-120B 1-shot | 0.8779 | 0.8498 | 0.8996 | 0.8642 | 0.8729 |
|
| 148 |
| **context attribution LoRA** | **0.9360** | **0.9045** | **0.9158** | **0.9223** | **0.9197** |
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
## Training Details
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
-
**Training Data:** The
|
| 159 |
|
| 160 |
-
The MultiDoc2Dial and QUAC datasets consist of sets of grounding documents and multi-turn question-answering conversations based on the set of documents. For training the context attribution
|
| 161 |
|
| 162 |
### Adapter Configurations
|
| 163 |
|
| 164 |
-
|
|
| 165 |
-
|-----------|------|
|
| 166 |
-
| Base model | ibm-granite/granite-4.0-micro |
|
| 167 |
-
| LoRA
|
| 168 |
-
|
|
| 169 |
-
|
|
| 170 |
-
|
|
| 171 |
-
| Max completion tokens | 4096 |
|
| 172 |
-
| KV cache | Supported |
|
|
|
|
| 173 |
|
| 174 |
-
**Infrastructure:** The
|
| 175 |
|
| 176 |
-
**Ethical Considerations:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
## Resources
|
| 179 |
|
|
|
|
| 2 |
|
| 3 |
## Model Summary
|
| 4 |
|
| 5 |
+
**Context Attribution** is a LoRA purpose-built for a base model to predict the sentences in the context that were most important for the base model to generate each sentence in its response or output. We provide LoRA adapters for the following base models: Granite 4.0 Micro, Granite 4.1 3B, Granite 4.1 8B, Granite 4.1 30B. Here, context includes previous conversation turns as well as any documents provided to the base model. The context attribution LoRA thus helps to explain the base model's behavior, specifically how its probability of generating a certain response sentence is affected by different parts of the context.
|
| 6 |
|
| 7 |
+
The context attribution model takes the form of a [LoRA adapter](https://arxiv.org/abs/2106.09685). The adapter greatly improves the base model's ability to attribute to context (see Evaluation section below) while retaining other capabilities of the base model. The context attribution adapter identifies which context sentences actually influenced the base model’s response, while IBM Granite’s [citation generation adapter](https://huggingface.co/ibm-granite/granitelib-rag-r1.0/blob/main/citations/README.md) highlights sentences that support the response regardless of whether the model used them.
|
| 8 |
|
| 9 |
- **Developer:** IBM Research
|
| 10 |
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 11 |
- **GitHub Repository:** https://github.com/ibm-granite
|
| 12 |
+
- **Release Date:** May 5th, 2026
|
| 13 |
+
- **Model Type:** LoRA adapters for:
|
| 14 |
+
- [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
|
| 15 |
+
- [ibm-granite/granite-4.1-3b](https://huggingface.co/ibm-granite/granite-4.1-3b)
|
| 16 |
+
- [ibm-granite/granite-4.1-8b](https://huggingface.co/ibm-granite/granite-4.1-8b)
|
| 17 |
+
- [ibm-granite/granite-4.1-30b](https://huggingface.co/ibm-granite/granite-4.1-30b)
|
| 18 |
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 19 |
- **Paper:** Context Attribution is trained to approximate the importance ranking of context sentences provided by the MExGen method in [[Monteiro Paes and Wei et al., ACL 2025] Multi-Level Explanations for Generative Language Models](https://aclanthology.org/2025.acl-long.1553/).
|
| 20 |
|
| 21 |
|
| 22 |
## Usage
|
| 23 |
|
| 24 |
+
**Intended use:** Context Attribution is a context attribution adapter intended for a specific base model. It enables the base model to accurately identify which sentences in the context (including previous conversation turns and documents) were most important to the model when generating each sentence in its response. The adapter thus helps to explain the base model's behavior, specifically how its probability of generating a certain response sentence is affected by parts of the context. This adapter is designed to be used as part of the Granite inference pipeline. It is intended to be called after the base model generates a response to provide a post hoc explanation.
|
| 25 |
|
| 26 |
+
The context attribution adapter is similar to the [citations adapter](https://huggingface.co/ibm-granite/granitelib-rag-r1.0/blob/main/citations/README.md) found in the [granitelib-rag-r1.0](https://huggingface.co/ibm-granite/granitelib-rag-r1.0) library, in that it uses a comparable input/output format and similiar training data. However, the two differ in the type of attribution they provide. Citation generation provides corroborative attribution, identifying document sentences that best support a response regardless of whether the model relied on them, making it model-agnostic. In contrast, the context attribution adapter provides contributive attribution, identifying the context sentences that actually influenced the base model’s response. It also includes prior conversation turns (not just documents) and ranks context sentences by importance rather than listing them unordered.
|
| 27 |
|
| 28 |
**Input Format** The context attribution LoRA expects the input to be processed as follows: 1) The last assistant response (the response to be attributed) should be split into sentences and the sentences numbered with tags as follows: `"<r0> sentence 0 <r1> sentence 1 ... "`. 2) The context (documents and previous conversation turns) should also be split into sentences and tagged as `"<c0> sentence 0 <c1> sentence 1 ... "`. The numbering of context sentences starts with the first document (if present) and continues as a single sequence through all the documents and then previous conversation turns, in that order. This input processing is performed automatically if the context attribution adapter is called using IBM's [mellea](https://github.com/generative-computing/mellea) package, as the Quickstart Example below shows. Alternatively, the user can insert sentence tags manually or by other means (also shown in the Quickstart Example below).
|
| 29 |
|
|
|
|
| 31 |
|
| 32 |
**Use Cases**
|
| 33 |
* Human understanding: Context attribution helps to explain a base LLM by showing which parts of the context were most important to it in generating a certain response. Such views into the LLM's behavior may help users calibrate their trust in using the LLM in a particular domain.
|
| 34 |
+
* RAG: The Context Attribution adapter is trained on a retrieval-augmented generation (RAG) dataset, specifically on document-grounded multi-turn question answering. The Evaluation section below shows that it also performs well when the use case is document summarization. It is thus especially suitable for RAG scenarios where users may wish to attribute LLM responses to a sizable context.
|
| 35 |
* Context reliance assessment: Context attribution can also be used to assess whether an LLM makes use of its context at all for a specific response. Low attribution scores to all context sentences might mean one of several things: 1) The response sentence is strongly implied by previous response sentences and does not need to refer to context; 2) the response comes primarily from the LLM's parametric knowledge; 3) the response is hallucinated. As such, determining the main reason for context non-reliance would require further investigation.
|
| 36 |
|
| 37 |
|
|
|
|
| 55 |
question = "What was the concept behind the formation of the Plastic Ono Band?"
|
| 56 |
messages.append({"role": "user", "content": question})
|
| 57 |
|
| 58 |
+
# Response pre-generated by granite-4.1-3b, could also generate a fresh response
|
| 59 |
+
response = "The Plastic Ono Band was formed by John Lennon and Yoko Ono in 1969 as a conceptual and collaborative vehicle for their collaborative and solo projects. Following their marriage in 1969, they decided that all of their future endeavors would be credited to this vehicle. The band was intended to serve as a platform for their artistic and personal expressions, featuring a rotating lineup of musicians over the years."
|
| 60 |
```
|
| 61 |
|
| 62 |
**Usage with Mellea**
|
| 63 |
```python
|
| 64 |
import json # only for display
|
| 65 |
|
| 66 |
+
from mellea import model_ids, start_backend
|
| 67 |
from mellea.stdlib.components import Document, Message # constructing the conversation
|
| 68 |
from mellea.stdlib.components.intrinsic.core import find_context_attributions # intrinsic function for calling context attribution
|
|
|
|
| 69 |
|
| 70 |
+
ctx, backend = start_backend(
|
| 71 |
+
"hf", model_id=model_ids.IBM_GRANITE_4_1_3B, context_type="chat"
|
| 72 |
+
)
|
| 73 |
|
| 74 |
# Previous conversation turns + current question
|
|
|
|
| 75 |
for message in messages:
|
| 76 |
+
ctx = ctx.add(Message(message["role"], message["content"]))
|
| 77 |
# Documents
|
| 78 |
documents_mellea = [Document(**document) for document in documents]
|
| 79 |
|
| 80 |
# Call context attribution intrinsic function
|
| 81 |
+
result = find_context_attributions(response, documents_mellea, ctx, backend)
|
| 82 |
print(f"Result of context attribution intrinsic:\n{json.dumps(result, indent=2)}")
|
| 83 |
|
| 84 |
+
# Prints an array of JSON objects where each object shows a response sentence,
|
| 85 |
# a context sentence to which the response sentence is attributed (in order of decreasing importance),
|
| 86 |
# and other fields such as the document ID where the context sentence is located.
|
| 87 |
+
# (You may get slightly different orderings of context sentences, depending on your hardware or environment.)
|
| 88 |
```
|
| 89 |
|
| 90 |
**Usage without Mellea**
|
|
|
|
| 93 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 94 |
from peft import PeftModel
|
| 95 |
|
| 96 |
+
BASE_NAME = "ibm-granite/granite-4.1-3b"
|
| 97 |
ADAPTER_REPO = "ibm-granite/granitelib-core-r1.0"
|
| 98 |
+
ADAPTER_SUBFOLDER = "context-attribution/granite-4.1-3b/lora"
|
| 99 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 100 |
|
| 101 |
# Load context attribution model (base model + LoRA)
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
# The context attribution adapter expects the last assistant response and context (documents
|
| 110 |
+
# + previous conversation turns) to be split into sentences and the sentences to be tagged with numbers.
|
| 111 |
# In this snippet, we assume that this input processing has been done as below.
|
| 112 |
documents_rewritten = [
|
| 113 |
{"doc_id": "0", "text": "<c0> The Plastic Ono Band is a band formed by John Lennon and Yoko Ono in 1969 as a vehicle for their collaborative and solo projects. <c1> Lennon and Ono had begun a personal and artistic relationship in 1968, collaborating on several experimental releases. <c2> Following their marriage in 1969, they decided that all of their future endeavours would be credited to a conceptual and collaborative vehicle, Plastic Ono Band. <c3> The band would go on to feature a rotating lineup of many musicians, including Eric Clapton, Klaus Voormann, Alan White, Billy Preston, Jim Keltner, Delaney & Bonnie and Friends, and Lennon's former Beatles bandmates George Harrison and Ringo Starr. <c4> Lennon and Ono left the UK to settle in New York City during the fall of 1971. <c5> In Greenwich Village, the couple became more politically active and began writing protest songs. <c6> These songs became the basis for their next album, Some Time in New York City. <c7> As backing, they enlisted the help of New York band Elephant's Memory, consisting of guitarist Wayne 'Tex' Gabriel, bassist Gary Van Scyoc, saxophonist Stan Bronstein, keyboardist Adam Ippolito, keyboardist John La Boosca, and drummer Richard Frank, Jr. <c8> Phil Spector produced, and Jim Keltner also played on the album. <c9> The album was released on 12 June 1972, credited to \"John & Yoko/Plastic Ono Band with Elephant's Memory plus Invisible Strings\". <c10> Some Time in New York City included a second disc, entitled Live Jam, which included the recordings from the 1969 Peace for Christmas concert and the 1971 performance with Frank Zappa. <c11> Ono and Lennon continued their work with Elephant's Memory throughout 1972, performing as the Plastic Ono Elephant's Memory Band (which also included Jim Keltner). <c12> On 30 August, they performed a pair of benefit concerts at Madison Square Garden. <c13> The benefit, entitled \"One to One\", was organised by Geraldo Rivera to raise money for children with mental challenges. <c14> By this time, La Boosca had departed the band, and the concert saw the addition of John Ward on bass. <c15> The concert was filmed and recorded, later released in February 1986 as the album Live In New York City. <c16> They also performed at the Jerry Lewis MDA Labor Day Telethon. <c17> The last collaboration of the Plastic Ono Elephant's Memory Band was Ono's double album Approximately Infinite Universe. <c18> It was recorded throughout the fall of 1972, and was released in January 1973."},
|
|
|
|
| 118 |
{"role": "user", "content": "<c70> Who were the members of The Metal Ono Band, which was formed by Yoko Ono in 1976 to explore her interest in heavy metal music?"},
|
| 119 |
{"role": "assistant", "content": "<c71> I'm sorry, but I don't have the data to answer that specific question."},
|
| 120 |
{"role": "user", "content": "<c72> What was the concept behind the formation of the Plastic Ono Band?"},
|
| 121 |
+
{"role": "assistant", "content": "<r0> The Plastic Ono Band was formed by John Lennon and Yoko Ono in 1969 as a conceptual and collaborative vehicle for their collaborative and solo projects. <r1> Following their marriage in 1969, they decided that all of their future endeavors would be credited to this vehicle. <r2> The band was intended to serve as a platform for their artistic and personal expressions, featuring a rotating lineup of musicians over the years."},
|
| 122 |
{"role": "user", "content": "You provided the last assistant response above based on context, which may include documents and/or previous conversation turns. Your response is divided into sentences, numbered in the format <r0> sentence 0 <r1> sentence 1 ... Sentences in the context are also numbered: <c0> sentence 0 <c1> sentence 1 ... For each response sentence, please list the context sentences that were most important for you to generate the response sentence. Provide your answer in JSON format, as an array of JSON objects, where each object has two members: \"r\" with the response sentence number as the value, and \"c\" with an array of context sentence numbers as the value. An example of such an array of objects is [{\"r\": 0, \"c\": [3, 1, 4]}, {\"r\": 1, \"c\": [1, 5]}]. List the context sentences in order from most important to least important. Ensure that you include an object for each response sentence, even if the corresponding array of context sentence numbers is empty. Answer with only the JSON and do not explain.\n"},
|
| 123 |
]
|
| 124 |
|
|
|
|
| 129 |
|
| 130 |
print(output_text)
|
| 131 |
|
| 132 |
+
# [{"r": 0, "c": [0, 2, 71, 3, 7, 24, 34, 31, 22, 41]}, {"r": 1, "c": [2, 0, 3, 7, 24, 34, 31, 22, 41, 63]}, {"r": 2, "c": [3, 2, 7, 24, 34, 31, 22, 41, 63, 39]}]
|
| 133 |
+
# This raw output from the adapter means that response sentences 0, 1, and 2 are each attributed to many context sentences in decreasing order of importance.
|
| 134 |
+
# The most important context sentences for response sentences 0, 1, 2 are 0, 2, 3 respectively.
|
| 135 |
+
# (You may get slightly different orderings of context sentences, depending on your hardware or environment.)
|
| 136 |
```
|
| 137 |
|
| 138 |
+
## Evaluation
|
| 139 |
|
| 140 |
+
The context attribution adapters were evaluated on four datasets: MD2D-QUAC, ELI5, CNN/Daily Mail (CNN/DM), and XSum. The first two are document-grounded, multi-turn question answering datasets and the last two are summarization datasets. MD2D-QUAC evaluates the adpaters on a held-out test split of the dataset used for training (please see "Training Data" below for more details), ELI5 evaluates generalization to a different dataset within the same task, and CNN/DM and XSum evaluate generalization to a different task.
|
| 141 |
|
| 142 |
The evaluation metric is the area under the perturbation curve (AUPC), a standard metric for evaluating the faithfulness of a feature-attribution-like explanation to the model being explained. Please see the [MExGen paper](https://aclanthology.org/2025.acl-long.1553/) for more details on AUPC. Here, the perturbation curves are first multiplied by a linearly decreasing weight function, which decreases from 1 at 0% perturbation to 0 at 20% perturbation, yielding the weighted area under the perturbation curve (WAUPC).
|
| 143 |
|
| 144 |
+
Below we show tables of WAUPC values for each base model for which a context attribution LoRA is available. Since the context attribution task is model-dependent (i.e., to explain the base model's behavior), values may not be comparable across tables. Values are normalized and can be compared within a table as described below.
|
| 145 |
+
|
| 146 |
+
#### Granite 4.0 Micro
|
| 147 |
+
|
| 148 |
| method | MD2D-QUAC | ELI5 | CNN/DM | XSum | average |
|
| 149 |
|:---------------------------|------------:|-------:|---------:|-------:|----------:|
|
| 150 |
| LOO *(skyline)* | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
|
| 151 |
| LOO thresholded *(realistic skyline)* | 0.9780 | 0.9812 | 0.9976 | 0.9983 | 0.9888 |
|
| 152 |
+
| prompt granite-4.0-micro 0-shot | 0.1476 | 0.1657 | 0.1629 | 0.2369 | 0.1783 |
|
| 153 |
+
| prompt granite-4.0-micro 1-shot | 0.1982 | 0.2171 | 0.1693 | 0.2014 | 0.1965 |
|
| 154 |
| prompt GPT-OSS-120B 0-shot | 0.8619 | 0.8063 | 0.8735 | 0.6679 | 0.8024 |
|
| 155 |
| prompt GPT-OSS-120B 1-shot | 0.8779 | 0.8498 | 0.8996 | 0.8642 | 0.8729 |
|
| 156 |
| **context attribution LoRA** | **0.9360** | **0.9045** | **0.9158** | **0.9223** | **0.9197** |
|
| 157 |
|
| 158 |
+
#### Granite 4.1 3B
|
| 159 |
+
|
| 160 |
+
| method | MD2D-QUAC | ELI5 | CNN/DM | XSum | average |
|
| 161 |
+
|:---|---:|---:|---:|---:|---:|
|
| 162 |
+
| LOO *(skyline)* | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
|
| 163 |
+
| LOO thresholded *(realistic skyline)* | 0.9908 | 0.9988 | 1.0004 | 1.0007 | 0.9977 |
|
| 164 |
+
| prompt granite-4.1-3b 0-shot | 0.4058 | 0.3918 | 0.2773 | 0.2808 | 0.3389 |
|
| 165 |
+
| prompt granite-4.1-3b 2-shot | 0.5032 | 0.4931 | 0.3395 | 0.3597 | 0.4239 |
|
| 166 |
+
| prompt GPT-OSS-120B 0-shot | 0.9040 | 0.8615 | 0.8911 | 0.7155 | 0.8430 |
|
| 167 |
+
| prompt GPT-OSS-120B 2-shot | 0.8909 | 0.8754 | 0.9050 | 0.8775 | 0.8872 |
|
| 168 |
+
| **context attribution LoRA** | **0.9053** | **0.8996** | **0.9310** | **0.9421** | **0.9195** |
|
| 169 |
+
|
| 170 |
+
#### Granite 4.1 8B
|
| 171 |
+
|
| 172 |
+
| method | MD2D-QUAC | ELI5 | CNN/DM | XSum | average |
|
| 173 |
+
|:---|---:|---:|---:|---:|---:|
|
| 174 |
+
| LOO *(skyline)* | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
|
| 175 |
+
| LOO thresholded *(realistic skyline)* | 0.9854 | 0.9978 | 1.0000 | 0.9999 | 0.9958 |
|
| 176 |
+
| prompt granite-4.1-8b 0-shot | 0.3938 | 0.2528 | 0.2109 | 0.2179 | 0.2688 |
|
| 177 |
+
| prompt granite-4.1-8b 2-shot | 0.5186 | 0.4071 | 0.3238 | 0.2944 | 0.3860 |
|
| 178 |
+
| prompt GPT-OSS-120B 0-shot | 0.8681 | 0.8005 | 0.8762 | 0.7009 | 0.8114 |
|
| 179 |
+
| prompt GPT-OSS-120B 2-shot | 0.8648 | 0.8215 | 0.8938 | 0.8720 | 0.8631 |
|
| 180 |
+
| **context attribution LoRA** | **0.9408** | **0.9278** | **0.9756** | **0.9808** | **0.9563** |
|
| 181 |
+
|
| 182 |
+
#### Granite 4.1 30B
|
| 183 |
+
|
| 184 |
+
| method | MD2D-QUAC | ELI5 | CNN/DM | XSum | average |
|
| 185 |
+
|:---|---:|---:|---:|---:|---:|
|
| 186 |
+
| LOO *(skyline)* | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
|
| 187 |
+
| LOO thresholded *(realistic skyline)* | 0.9877 | 0.9994 | 1.0003 | 1.0001 | 0.9969 |
|
| 188 |
+
| prompt granite-4.1-30b 0-shot | 0.6953 | 0.5896 | 0.6709 | 0.6452 | 0.6502 |
|
| 189 |
+
| prompt granite-4.1-30b 3-shot | 0.8089 | 0.6312 | 0.7712 | 0.7607 | 0.7430 |
|
| 190 |
+
| prompt GPT-OSS-120B 0-shot | 0.9098 | 0.7956 | 0.8706 | 0.6993 | 0.8188 |
|
| 191 |
+
| prompt GPT-OSS-120B 1-shot | 0.8970 | 0.7925 | 0.8789 | 0.8478 | 0.8540 |
|
| 192 |
+
| **context attribution LoRA** | **0.9188** | **0.8647** | **0.9123** | **0.9163** | **0.9030** |
|
| 193 |
+
|
| 194 |
+
The first row of each table shows the WAUPC for the leave-one-out (LOO) variant of the [MExGen method](https://aclanthology.org/2025.acl-long.1553/), which the adapters aim to approximate. The second row corresponds to a thresholded version of LOO, which is the one that actually generates training data for the adapters. LOO and thresholded LOO thus represent "skyline" and "realistic skyline" methods that the adapters ideally would match. The WAUPC values in each table have been normalized by dividing by the WAUPC of LOO (for the particular base model). As seen in the last row of each table, the adapters do well in approximating LOO, attaining at least 90% of its WAUPC in all but one case and 90.3%-95.6% averaged across datasets.
|
| 195 |
+
|
| 196 |
+
The tables compare the context attribution adapters to baselines that prompt an LLM to perform the context attribution task. These include prompting the base model, with and without providing examples (0-shot/1-shot or more), and prompting GPT-OSS-120B, also with 0-shot or more. 1-shot, 2-shot, and 3-shot prompting were evaluated and the best-performing number of shots is shown for each prompted model. It is clear that the context attribution adapter improves the base model's ability to attribute its own responses to context. The adapter also outperforms GPT-OSS-120B, an LLM with around 4-40X the number of parameters (the LoRA adapter contributes a negligible number of parameters to the base model).
|
| 197 |
|
| 198 |
## Training Details
|
| 199 |
|
| 200 |
+
Context Attribution is a LoRA adapter trained to approximate the importance ranking of context sentences provided by the MExGen method in [[Monteiro Paes and Wei et al., ACL 2025] Multi-Level Explanations for Generative Language Models](https://aclanthology.org/2025.acl-long.1553/).
|
| 201 |
|
| 202 |
+
**Training Data:** The adapters were trained on a mixture of two datasets, [MultiDoc2Dial](https://huggingface.co/datasets/IBM/multidoc2dial) and [QUAC](https://huggingface.co/datasets/allenai/quac), which are both for document-grounded, multi-turn question answering. This mixture of datasets, referred to as **MD2D-QUAC**, was also used to train IBM Granite's [citation generation adapter](https://huggingface.co/ibm-granite/granite-lib-rag-r1.0/blob/main/citations/README.md). 4101 question-answer conversation rounds were used for training and 1024 for validation. These numbers of instances were deliberately chosen to be modest to demonstrate that a well-performing adapter can be trained using this limited amount of data.
|
| 203 |
|
| 204 |
+
The MultiDoc2Dial and QUAC datasets consist of sets of grounding documents and multi-turn question-answering conversations based on the set of documents. For training the context attribution adapters, each conversation round (consisting of one user question followed by an assistant response), together with any conversation rounds that precede it, was treated as a separate "instance". The context for each instance includes the documents for the conversation as well as all conversation rounds except the last round, which is treated as the current round for the instance. The base model was called to re-generate a response to the question in the current round (since the purpose of the adapter is to attribute the base model's responses). The leave-one-out (LOO) variant of [MExGen](https://aclanthology.org/2025.acl-long.1553/) was then used to attribute each response sentence to context sentences, yielding "gold" attribution scores. LOO is thus treated as the "skyline" method in the Evaluation section. The LOO attribution scores were thresholded to produce a controlled-length list of context sentences, specifically a list of context sentence numbers in decreasing order of importance. The context attribution adapters were trained to reproduce these lists for all response sentences, given the context, response, and an instruction as input.
|
| 205 |
|
| 206 |
### Adapter Configurations
|
| 207 |
|
| 208 |
+
| Property | Granite 4.0 Micro | Granite 4.1 3B | Granite 4.1 8B | Granite 4.1 30B |
|
| 209 |
+
|-----------|------|------|------|------|
|
| 210 |
+
| Base model | ibm-granite/granite-4.0-micro | ibm-granite/granite-4.1-3b | ibm-granite/granite-4.1-8b | ibm-granite/granite-4.1-30b |
|
| 211 |
+
| PEFT type | LoRA | LoRA | LoRA | LoRA |
|
| 212 |
+
| Rank (r) | 16 | 16 | 16 | 32 |
|
| 213 |
+
| Alpha | 32 | 32 | 32 | 64 |
|
| 214 |
+
| Target modules | q_proj, k_proj, v_proj | q_proj, k_proj, v_proj | q_proj, k_proj, v_proj | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 215 |
+
| Max completion tokens | 4096 | 4096 | 4096 | 4096 |
|
| 216 |
+
| KV cache | Supported | Supported | Supported | Supported |
|
| 217 |
+
<!-- | Output format | e.g. `[{"r": 0, "c": [3, 1, 4]}, ... ]` where `"c"` lists most important context sentences for response sentence `"r"`| -->
|
| 218 |
|
| 219 |
+
**Infrastructure:** The Context Attribution LoRA adapters were trained on a single NVIDIA H100-80GB GPU.
|
| 220 |
|
| 221 |
+
**Ethical Considerations:** Each context attribution adapter is designed specifically for its respective base model and was trained on its behavior. While it may be applied to other LLMs, it has not been validated for them. In addition, the context attributions may not always align with human judgments of which context sentences should matter.
|
| 222 |
+
|
| 223 |
+
## Citation
|
| 224 |
+
If you find these adapters useful, please cite the following work:
|
| 225 |
+
```
|
| 226 |
+
@inproceedings{monteiro-paes-wei-2025-mexgen,
|
| 227 |
+
title = "Multi-Level Explanations for Generative Language Models",
|
| 228 |
+
author = "Monteiro Paes, Lucas and
|
| 229 |
+
Wei, Dennis and
|
| 230 |
+
Do, Hyo Jin and
|
| 231 |
+
Strobelt, Hendrik and
|
| 232 |
+
Luss, Ronny and
|
| 233 |
+
Dhurandhar, Amit and
|
| 234 |
+
Nagireddy, Manish and
|
| 235 |
+
Natesan Ramamurthy, Karthikeyan and
|
| 236 |
+
Sattigeri, Prasanna and
|
| 237 |
+
Geyer, Werner and
|
| 238 |
+
Ghosh, Soumya",
|
| 239 |
+
booktitle = "Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
|
| 240 |
+
month = jul,
|
| 241 |
+
year = "2025",
|
| 242 |
+
address = "Vienna, Austria",
|
| 243 |
+
url = "https://aclanthology.org/2025.acl-long.1553/",
|
| 244 |
+
pages = "32291--32317",
|
| 245 |
+
}
|
| 246 |
+
```
|
| 247 |
|
| 248 |
## Resources
|
| 249 |
|
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
library_name:
|
| 7 |
+
- peft
|
| 8 |
+
- transformers
|
| 9 |
+
base_model:
|
| 10 |
+
- ibm-granite/granite-4.0-micro
|
| 11 |
+
- ibm-granite/granite-4.1-3b
|
| 12 |
+
- ibm-granite/granite-4.1-8b
|
| 13 |
+
- ibm-granite/granite-4.1-30b
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Requirement Checking
|
| 17 |
+
|
| 18 |
+
## Model Summary
|
| 19 |
+
|
| 20 |
+
**Requirement Checking** is a family of LoRA adapters fine-tuned for binary
|
| 21 |
+
requirement satisfaction classification. The model takes as input a user prompt,
|
| 22 |
+
an assistant response, and a set of user-specified requirements, and classifies
|
| 23 |
+
whether the assistant's response satisfies the given constraints. The model
|
| 24 |
+
outputs a JSON object `{"score": "yes"}` or `{"score": "no"}` indicating whether
|
| 25 |
+
the constraints are satisfied. We provide requirement checking capabilities
|
| 26 |
+
implemented as LoRA adapters trained over Granite-4.0-micro, Granite-4.1-3B, Granite-4.1-8B, and
|
| 27 |
+
Granite-4.1-30B.
|
| 28 |
+
|
| 29 |
+
- **Developer:** IBM Research
|
| 30 |
+
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 31 |
+
- **GitHub Repository:** https://github.com/ibm-granite
|
| 32 |
+
- **Last Updated:** May 5th, 2026
|
| 33 |
+
- **Model type:** LoRA/aLoRA adapters for:
|
| 34 |
+
- [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
|
| 35 |
+
- [ibm-granite/granite-4.1-3b](https://huggingface.co/ibm-granite/granite-4.1-3b)
|
| 36 |
+
- [ibm-granite/granite-4.1-8b](https://huggingface.co/ibm-granite/granite-4.1-8b)
|
| 37 |
+
- [ibm-granite/granite-4.1-30b](https://huggingface.co/ibm-granite/granite-4.1-30b)
|
| 38 |
+
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 39 |
+
|
| 40 |
+
## Intended Use
|
| 41 |
+
|
| 42 |
+
The Requirement Checking adapter is designed for evaluating whether LLM-generated
|
| 43 |
+
responses satisfy user-specified constraints. Key use cases include:
|
| 44 |
+
|
| 45 |
+
- **Instruction-following evaluation**: Assessing whether a model's output
|
| 46 |
+
adheres to specific formatting, content, or structural requirements provided
|
| 47 |
+
in the prompt.
|
| 48 |
+
- **Constraint satisfaction checking**: Verifying that generated text meets
|
| 49 |
+
multiple simultaneous constraints (e.g., length limits, style requirements,
|
| 50 |
+
content inclusion/exclusion).
|
| 51 |
+
- **Quality assurance pipelines**: Automated checking of LLM outputs against
|
| 52 |
+
predefined acceptance criteria.
|
| 53 |
+
|
| 54 |
+
**Adapter input**: The input to the requirement checking adapter is an
|
| 55 |
+
OpenAI-compatible chat completion request containing a user message, an assistant
|
| 56 |
+
response, and a follow-up user turn with the requirements to evaluate wrapped in
|
| 57 |
+
a `<requirements>` tag.
|
| 58 |
+
|
| 59 |
+
**Adapter output**: `{"score": "yes"}` if the constraints are satisfied, `{"score": "no"}` otherwise.
|
| 60 |
+
|
| 61 |
+
**Scoring:** When called via Mellea, the binary output is converted to a float between 0.0 and 1.0 using the model's token-level probability of "yes". This provides a continuous confidence score rather than a hard binary decision. The threshold for converting this score to a binary outcome is left to the user and may need to be tuned for your use-case.
|
| 62 |
+
|
| 63 |
+
## Usage Examples
|
| 64 |
+
|
| 65 |
+
### via Mellea
|
| 66 |
+
|
| 67 |
+
The recommended way to call this adapter is through the [Mellea](https://mellea.ai) framework:
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from mellea import model_ids, start_backend
|
| 71 |
+
from mellea.stdlib.components import Message
|
| 72 |
+
from mellea.stdlib.components.intrinsic import core
|
| 73 |
+
|
| 74 |
+
ctx, backend = start_backend(
|
| 75 |
+
"hf", model_id=model_ids.IBM_GRANITE_4_1_3B, context_type="chat"
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
ctx = (
|
| 79 |
+
ctx.add(Message("user", "Invite for an IBM office party."))
|
| 80 |
+
.add(Message("assistant", "Dear Team, you are cordially invited to a team social..."))
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
result = core.requirement_check(ctx, backend, "Use a professional tone.")
|
| 84 |
+
print(f"Requirements satisfied: {result}") # float between 0.0 and 1.0
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
For more comprehensive examples and detailed documentation, refer to the [Mellea intrinsics examples](https://github.com/generative-computing/mellea/tree/main/docs/examples/intrinsics).
|
| 88 |
+
|
| 89 |
+
### via HF+PEFT
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
import json
|
| 93 |
+
import torch
|
| 94 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 95 |
+
from peft import PeftModel
|
| 96 |
+
|
| 97 |
+
base_model_id = "ibm-granite/granite-4.1-3b"
|
| 98 |
+
adapter_repo = "ibm-granite/granitelib-core-r1.0"
|
| 99 |
+
adapter_subfolder = "requirement-check/granite-4.1-3b/lora"
|
| 100 |
+
|
| 101 |
+
# Load base model and LoRA adapter
|
| 102 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 103 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 104 |
+
base_model_id, torch_dtype=torch.bfloat16, device_map="auto"
|
| 105 |
+
)
|
| 106 |
+
model = PeftModel.from_pretrained(base_model, adapter_repo, subfolder=adapter_subfolder)
|
| 107 |
+
model.eval()
|
| 108 |
+
|
| 109 |
+
# Define the user prompt, assistant response, and constraints to check
|
| 110 |
+
user_text = "Invite for an IBM office party."
|
| 111 |
+
response_text = """
|
| 112 |
+
Dear Team,
|
| 113 |
+
|
| 114 |
+
To celebrate our recent successes and take a well-deserved moment to recharge,
|
| 115 |
+
you are cordially invited to a team social. Please join us for an evening of
|
| 116 |
+
live music, appetizers, and drinks as we recognize our collective wins.
|
| 117 |
+
|
| 118 |
+
Event Details
|
| 119 |
+
* **Date:** Saturday, April 25, 2026
|
| 120 |
+
* **Time:** 6:00 PM
|
| 121 |
+
* **Location:** Ryan's Bar, Chelsea, NY
|
| 122 |
+
* **Highlights:** Live entertainment and refreshments
|
| 123 |
+
|
| 124 |
+
RSVP
|
| 125 |
+
To ensure we have an accurate headcount for catering, please confirm your
|
| 126 |
+
attendance by **Friday, April 10, 2026**.
|
| 127 |
+
|
| 128 |
+
We look forward to seeing everyone there and celebrating our hard work together.
|
| 129 |
+
|
| 130 |
+
**Best regards,**
|
| 131 |
+
[Your Name/Management Team]
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
constraints = "Use a professional tone."
|
| 135 |
+
|
| 136 |
+
# Build the evaluation prompt
|
| 137 |
+
evaluation_prompt = (
|
| 138 |
+
"Please verify if the assistant's generation satisfies the user's "
|
| 139 |
+
"requirements or not and reply with a binary label accordingly. "
|
| 140 |
+
'Respond with a json {"score": "yes"} if the constraints are '
|
| 141 |
+
'satisfied or respond with {"score": "no"} if the constraints are not '
|
| 142 |
+
"satisfied."
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
messages = [
|
| 146 |
+
{"role": "user", "content": user_text},
|
| 147 |
+
{"role": "assistant", "content": response_text},
|
| 148 |
+
{"role": "user", "content": f"<requirements> {constraints}\n{evaluation_prompt}"},
|
| 149 |
+
]
|
| 150 |
+
|
| 151 |
+
prompt = tokenizer.apply_chat_template(
|
| 152 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
# Generate
|
| 156 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 157 |
+
input_len = inputs["input_ids"].shape[1]
|
| 158 |
+
|
| 159 |
+
stop_token_id = tokenizer.encode("}", add_special_tokens=False)[0]
|
| 160 |
+
|
| 161 |
+
with torch.no_grad():
|
| 162 |
+
output = model.generate(
|
| 163 |
+
**inputs,
|
| 164 |
+
max_new_tokens=20,
|
| 165 |
+
do_sample=False,
|
| 166 |
+
eos_token_id=[tokenizer.eos_token_id, stop_token_id],
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
response = tokenizer.decode(output[0][input_len:], skip_special_tokens=True).strip()
|
| 170 |
+
|
| 171 |
+
brace_idx = response.find("}")
|
| 172 |
+
if brace_idx != -1:
|
| 173 |
+
response = response[:brace_idx + 1]
|
| 174 |
+
|
| 175 |
+
print(f"Response: {response}") # {"score": "yes"}
|
| 176 |
+
|
| 177 |
+
result = json.loads(response)
|
| 178 |
+
print(f"Constraints satisfied: {result['score']}") # yes
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
## Evaluation
|
| 182 |
+
|
| 183 |
+
We evaluated the adapters on binary requirement satisfaction classification
|
| 184 |
+
using four benchmarks: [HelpSteer3](https://huggingface.co/datasets/nvidia/HelpSteer3),
|
| 185 |
+
[IFEval Multi-Constraint](https://arxiv.org/abs/2311.07911), and
|
| 186 |
+
[InfoBench](https://arxiv.org/abs/2401.03601) (GPT-4-annotated and
|
| 187 |
+
human-annotated splits).
|
| 188 |
+
|
| 189 |
+
### Results
|
| 190 |
+
|
| 191 |
+
The table below reports Balanced Accuracy across all benchmarks for prompting
|
| 192 |
+
baselines and trained adapters (LoRA and aLoRA) at each model size.
|
| 193 |
+
|
| 194 |
+
| Model | HelpSteer3 | IFEval | InfoBench-GPT4 | InfoBench-Human |
|
| 195 |
+
|---|---|---|---|---|
|
| 196 |
+
| Granite-4.1-3B (prompting) | 0.5090 | 0.5118 | 0.6237 | 0.5866 |
|
| 197 |
+
| Granite-4.1-8B (prompting) | 0.5162 | 0.5689 | 0.6564 | 0.6018 |
|
| 198 |
+
| Granite-4.1-30B (prompting) | 0.5234 | 0.6237 | 0.6863 | 0.6236 |
|
| 199 |
+
| Granite-4.0-micro LoRA | 0.7434 | 0.8403 | 0.6950 | 0.6799 |
|
| 200 |
+
| Granite-4.1-3B LoRA | 0.6726 | 0.8153 | 0.6960 | 0.6728 |
|
| 201 |
+
| Granite-4.1-3B aLoRA | 0.6957 | 0.8425 | 0.7150 | 0.6475 |
|
| 202 |
+
| Granite-4.1-8B LoRA | 0.7051 | 0.8360 | 0.7373 | 0.6546 |
|
| 203 |
+
| Granite-4.1-8B aLoRA | 0.6941 | 0.8554 | 0.7119 | 0.6761 |
|
| 204 |
+
| Granite-4.1-30B LoRA | 0.7119 | 0.8406 | 0.7512 | 0.7038 |
|
| 205 |
+
| Granite-4.1-30B aLoRA | 0.7178 | 0.8492 | 0.7432 | 0.7052 |
|
| 206 |
+
|
| 207 |
+
The evaluations on HelpSteer3 and IFEval above are on the validation set and a heldout set, respectively.
|
| 208 |
+
|
| 209 |
+
## Training Details
|
| 210 |
+
|
| 211 |
+
### Training Data
|
| 212 |
+
|
| 213 |
+
The Requirement Checking adapter is fine-tuned using a combination of
|
| 214 |
+
instruction-following evaluation data. Training data includes samples with
|
| 215 |
+
explicit user requirements and constraints paired with assistant responses,
|
| 216 |
+
annotated for whether the constraints are satisfied.
|
| 217 |
+
|
| 218 |
+
The two sources of training data are:
|
| 219 |
+
|
| 220 |
+
1. [IF-RLVR training data](https://huggingface.co/datasets/allenai/IF_multi_constraints_upto5),
|
| 221 |
+
with up to 5 constraints per instruction. Each prompt (with constraints) was
|
| 222 |
+
passed through [Mixtral 8x22b Instruct](https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1).
|
| 223 |
+
Then, the [prompt, constraints, response] are all passed through a
|
| 224 |
+
[programmatic evaluation pipeline](https://github.com/allenai/IFBench?tab=readme-ov-file)
|
| 225 |
+
which provides yes/no labels corresponding to whether the constraints were
|
| 226 |
+
followed or not.
|
| 227 |
+
2. [Helpsteer3-Preference](https://huggingface.co/datasets/nvidia/HelpSteer3).
|
| 228 |
+
The original dataset consists of [prompt, response1, response2, feedback].
|
| 229 |
+
The `feedback` column contains individual rankings (a score from 1-5) of each
|
| 230 |
+
response from multiple annotators. We map scores 4-5 to a label of yes and
|
| 231 |
+
scores 1-3 to a label of no, take the average of the annotators' scores and
|
| 232 |
+
map each of the two responses to a binary yes/no label accordingly.
|
| 233 |
+
|
| 234 |
+
### Training Hyperparameters
|
| 235 |
+
|
| 236 |
+
The adapters were fine-tuned using PEFT under the following regime: rank = 64
|
| 237 |
+
(LoRA) / 16 (aLoRA), alpha = 64, learning rates between 5e-5 and 5e-4 (tuned
|
| 238 |
+
per base model).
|
| 239 |
+
|
| 240 |
+
### Adapter Details
|
| 241 |
+
|
| 242 |
+
| Property | Granite-4.0-micro | Granite-4.1-3B | Granite-4.1-8B | Granite-4.1-30B |
|
| 243 |
+
|---|---|---|---|---|
|
| 244 |
+
| **PEFT Type** | LoRA | LoRA/aLoRA | LoRA/aLoRA | LoRA/aLoRA |
|
| 245 |
+
| **Rank (r) - LoRA** | 64 | 64 | 64 | 64 |
|
| 246 |
+
| **Rank (r) - aLoRA** | — | 16 | 16 | 16 |
|
| 247 |
+
| **Alpha** | 64 | 64 | 64 | 64 |
|
| 248 |
+
| **Target Modules** | q_proj, k_proj, v_proj, o_proj, input_linear, output_linear | q_proj, k_proj, v_proj, o_proj | q_proj, k_proj, v_proj, o_proj | q_proj, k_proj, v_proj, o_proj |
|
| 249 |
+
| **Invocation Token (aLoRA)** | — | `<requirements>` | `<requirements>` | `<requirements>` |
|
| 250 |
+
|
| 251 |
+
**Infrastructure:** Training was completed using H100 GPUs.
|
| 252 |
+
|
| 253 |
+
**Ethical Considerations:** The requirement checking adapter outputs are not guaranteed to be factually accurate or complete. All outputs should be independently validated before use in decision-making or downstream applications. The model has been trained and evaluated on English data only. The model must only be used in the prescribed evaluation mode, outputting JSON responses (`{"score": "yes"/"no"}`) based on the specified prompt template.
|
| 254 |
+
|
| 255 |
+
**Resources**
|
| 256 |
+
- Learn about the latest updates with Granite: https://www.ibm.com/granite
|
| 257 |
+
- Get started with tutorials and best practices: https://www.ibm.com/granite/docs/
|
|
@@ -1,267 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
pipeline_tag: text-generation
|
| 6 |
-
library_name: transformers
|
| 7 |
-
base_model: ibm-granite/granite-4.0-micro
|
| 8 |
-
tags:
|
| 9 |
-
- granite
|
| 10 |
-
- guardian
|
| 11 |
-
- requirement-checking
|
| 12 |
-
- instruction-following
|
| 13 |
-
- lora
|
| 14 |
-
- peft
|
| 15 |
-
---
|
| 16 |
-
# Requirement Checker (LoRA)
|
| 17 |
-
|
| 18 |
-
**Model Summary:** Requirement Checker is a lightweight LoRA adapter that brings requirement checking capabilities to the [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro) base model. The adapter is trained to judge whether an assistant's generation satisfies a set of user-specified requirements, outputting a binary yes/no assessment. The model outputs a JSON object `{"score": "yes"}` or `{"score": "no"}` indicating whether the given constraints are satisfied.
|
| 19 |
-
|
| 20 |
-
- **Developers:** IBM Research
|
| 21 |
-
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 22 |
-
- **Github Repository:** [ibm-granite](https://github.com/ibm-granite/)
|
| 23 |
-
- **Release Date:** March 18th, 2026
|
| 24 |
-
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 25 |
-
- **Paper:** [Granite Guardian](https://arxiv.org/abs/2412.07724)
|
| 26 |
-
|
| 27 |
-
## Usage
|
| 28 |
-
|
| 29 |
-
**Intended Use:** The Requirement Checker adapter is designed for evaluating whether LLM-generated responses satisfy user-specified constraints. Key use cases include:
|
| 30 |
-
|
| 31 |
-
### Use Case
|
| 32 |
-
- **Instruction-following evaluation**: Assessing whether a model's output adheres to specific formatting, content, or structural requirements provided in the prompt.
|
| 33 |
-
- **Constraint satisfaction checking**: Verifying that generated text meets multiple simultaneous constraints (e.g., length limits, style requirements, content inclusion/exclusion).
|
| 34 |
-
- **Quality assurance pipelines**: Automated checking of LLM outputs against predefined acceptance criteria.
|
| 35 |
-
|
| 36 |
-
### Installation
|
| 37 |
-
|
| 38 |
-
```bash
|
| 39 |
-
pip install transformers peft torch
|
| 40 |
-
```
|
| 41 |
-
|
| 42 |
-
### Quickstart Example (LoRA)
|
| 43 |
-
|
| 44 |
-
```python
|
| 45 |
-
import json
|
| 46 |
-
import torch
|
| 47 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 48 |
-
from peft import PeftModel
|
| 49 |
-
|
| 50 |
-
base_model_id = "ibm-granite/granite-4.0-micro"
|
| 51 |
-
adapter_repo = "ibm-granite/granitelib-core-r1.0"
|
| 52 |
-
adapter_subfolder = "requirement-check/granite-4.0-micro/lora"
|
| 53 |
-
|
| 54 |
-
# Load base model and LoRA adapter
|
| 55 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 56 |
-
base_model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
-
base_model_id, torch_dtype=torch.bfloat16, device_map="auto"
|
| 58 |
-
)
|
| 59 |
-
model = PeftModel.from_pretrained(base_model, adapter_repo, subfolder=adapter_subfolder)
|
| 60 |
-
model.eval()
|
| 61 |
-
|
| 62 |
-
# Define the user prompt, assistant response, and constraints to check
|
| 63 |
-
user_text = "Invite for an IBM office party."
|
| 64 |
-
response_text = """
|
| 65 |
-
Dear Team,
|
| 66 |
-
|
| 67 |
-
To celebrate our recent successes and take a well-deserved moment to recharge,
|
| 68 |
-
you are cordially invited to a team social. Please join us for an evening of
|
| 69 |
-
live music, appetizers, and drinks as we recognize our collective wins.
|
| 70 |
-
|
| 71 |
-
Event Details
|
| 72 |
-
* **Date:** Saturday, April 25, 2026
|
| 73 |
-
* **Time:** 6:00 PM
|
| 74 |
-
* **Location:** Ryan’s Bar, Chelsea, NY
|
| 75 |
-
* **Highlights:** Live entertainment and refreshments
|
| 76 |
-
|
| 77 |
-
RSVP
|
| 78 |
-
To ensure we have an accurate headcount for catering, please confirm your
|
| 79 |
-
attendance by **Friday, April 10, 2026**.
|
| 80 |
-
|
| 81 |
-
We look forward to seeing everyone there and celebrating our hard work together.
|
| 82 |
-
|
| 83 |
-
**Best regards,**
|
| 84 |
-
[Your Name/Management Team]
|
| 85 |
-
"""
|
| 86 |
-
|
| 87 |
-
constraints = "Use a professional tone."
|
| 88 |
-
|
| 89 |
-
# Build the evaluation prompt
|
| 90 |
-
evaluation_prompt = (
|
| 91 |
-
"Please verify if the assistant's generation satisfies the user's "
|
| 92 |
-
"requirements or not and reply with a binary label accordingly. "
|
| 93 |
-
'Respond with a json {"score": "yes"} if the constraints are '
|
| 94 |
-
'satisfied or respond with {"score": "no"} if the constraints are not '
|
| 95 |
-
"satisfied."
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
messages = [
|
| 99 |
-
{"role": "user", "content": user_text},
|
| 100 |
-
{"role": "assistant", "content": response_text},
|
| 101 |
-
{"role": "user", "content": f"<requirements> {constraints}\n{evaluation_prompt}"},
|
| 102 |
-
]
|
| 103 |
-
|
| 104 |
-
prompt = tokenizer.apply_chat_template(
|
| 105 |
-
messages, tokenize=False, add_generation_prompt=True
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
# Generate
|
| 109 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 110 |
-
input_len = inputs["input_ids"].shape[1]
|
| 111 |
-
|
| 112 |
-
stop_token_id = tokenizer.encode("}", add_special_tokens=False)[0]
|
| 113 |
-
|
| 114 |
-
with torch.no_grad():
|
| 115 |
-
output = model.generate(
|
| 116 |
-
**inputs,
|
| 117 |
-
max_new_tokens=20,
|
| 118 |
-
do_sample=False,
|
| 119 |
-
eos_token_id=[tokenizer.eos_token_id, stop_token_id],
|
| 120 |
-
)
|
| 121 |
-
|
| 122 |
-
response = tokenizer.decode(output[0][input_len:], skip_special_tokens=True).strip()
|
| 123 |
-
|
| 124 |
-
brace_idx = response.find("}")
|
| 125 |
-
if brace_idx != -1:
|
| 126 |
-
response = response[:brace_idx + 1]
|
| 127 |
-
|
| 128 |
-
print(f"Response: {response}") # {"score": "yes"}
|
| 129 |
-
|
| 130 |
-
result = json.loads(response)
|
| 131 |
-
print(f"Constraints satisfied: {result['score']}") # yes
|
| 132 |
-
```
|
| 133 |
-
|
| 134 |
-
### Prompt Template
|
| 135 |
-
|
| 136 |
-
The requirement checker uses a structured prompt format where user/assistant messages are followed by a requirement evaluation turn. The `<requirements>` tag marks the constraints to be evaluated:
|
| 137 |
-
|
| 138 |
-
```
|
| 139 |
-
<user message>
|
| 140 |
-
<assistant response>
|
| 141 |
-
<requirements> <constraints>
|
| 142 |
-
<evaluation prompt>
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
Typical usage will check the last assistant generation and the following text can be used:
|
| 146 |
-
|
| 147 |
-
```python
|
| 148 |
-
evaluation_prompt = (
|
| 149 |
-
"Please verify if the assistant's generation satisfies the user's "
|
| 150 |
-
"requirements or not and reply with a binary label accordingly. "
|
| 151 |
-
'Respond with a json {"score": "yes"} if the constraints are '
|
| 152 |
-
'satisfied or respond with {"score": "no"} if the constraints are not '
|
| 153 |
-
"satisfied."
|
| 154 |
-
)
|
| 155 |
-
```
|
| 156 |
-
|
| 157 |
-
## Evaluations
|
| 158 |
-
|
| 159 |
-
Binary classification performance on instruction-following benchmarks: [HelpSteer3](https://huggingface.co/datasets/nvidia/HelpSteer3), [IFEval Multi-Constraint](https://arxiv.org/abs/2311.07911), and [InfoBench](https://arxiv.org/abs/2401.03601) (GPT-4-annotated and human-annotated splits).
|
| 160 |
-
|
| 161 |
-
<table>
|
| 162 |
-
<caption style="text-align:center"><b>Requirement Checking Benchmarks</b></caption>
|
| 163 |
-
<thead>
|
| 164 |
-
<tr>
|
| 165 |
-
<th style="text-align:left; background-color: #001d6c; color: white;">Benchmark</th>
|
| 166 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">AUC</th>
|
| 167 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">Accuracy</th>
|
| 168 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">Bal. Acc.</th>
|
| 169 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">F1</th>
|
| 170 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">Precision</th>
|
| 171 |
-
<th style="text-align:center; background-color: #001d6c; color: white;">Recall</th>
|
| 172 |
-
</tr></thead>
|
| 173 |
-
<tbody>
|
| 174 |
-
<tr>
|
| 175 |
-
<td style="text-align:left; background-color: #e8f0fe; color: #2D2D2D;">HelpSteer3</td>
|
| 176 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8260 </td>
|
| 177 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7463 </td>
|
| 178 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7434 </td>
|
| 179 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7686 </td>
|
| 180 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7598 </td>
|
| 181 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7776 </td>
|
| 182 |
-
</tr>
|
| 183 |
-
<tr>
|
| 184 |
-
<td style="text-align:left; background-color: #e8f0fe; color: #2D2D2D;">IFEval Multi-Constraint</td>
|
| 185 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.9186 </td>
|
| 186 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8459 </td>
|
| 187 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8403 </td>
|
| 188 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8092 </td>
|
| 189 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8071 </td>
|
| 190 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8114 </td>
|
| 191 |
-
</tr>
|
| 192 |
-
<tr>
|
| 193 |
-
<td style="text-align:left; background-color: #e8f0fe; color: #2D2D2D;">InfoBench (GPT-4 Annotated)</td>
|
| 194 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7660 </td>
|
| 195 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7304 </td>
|
| 196 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.6950 </td>
|
| 197 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8207 </td>
|
| 198 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.9260 </td>
|
| 199 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7394 </td>
|
| 200 |
-
</tr>
|
| 201 |
-
<tr>
|
| 202 |
-
<td style="text-align:left; background-color: #e8f0fe; color: #2D2D2D;">InfoBench (Human Annotated)</td>
|
| 203 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7311 </td>
|
| 204 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7523 </td>
|
| 205 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.6799 </td>
|
| 206 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8034 </td>
|
| 207 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.8918 </td>
|
| 208 |
-
<td style="text-align:center; background-color: #e8f0fe; color: #2D2D2D;"> 0.7409 </td>
|
| 209 |
-
</tr>
|
| 210 |
-
</tbody>
|
| 211 |
-
</table>
|
| 212 |
-
|
| 213 |
-
The evaluations on Helpsteer3 and IFEval above are on the validation set and a heldout set, respectively.
|
| 214 |
-
|
| 215 |
-
## Training Data
|
| 216 |
-
|
| 217 |
-
The Requirement Checker adapter is fine-tuned on top of `ibm-granite/granite-4.0-micro` using a combination of instruction-following evaluation data. Training data includes samples with explicit user requirements and constraints paired with assistant responses, annotated for whether the constraints are satisfied.
|
| 218 |
-
|
| 219 |
-
The two sources of training data are:
|
| 220 |
-
|
| 221 |
-
1. [IF-RLVR training data](https://huggingface.co/datasets/allenai/IF_multi_constraints_upto5), with up to 5 constraints per instruction. Each prompt (with constraints) were passed through [Mixtral 8x22b Instruct](https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1). Then, the [prompt, constraints, response] are all passed through a [programmatic evaluation pipeline](https://github.com/allenai/IFBench?tab=readme-ov-file) which provides yes/no labels corresponding to whether the constraints were followed or not.
|
| 222 |
-
2. [Helpsteer3-Preference](https://huggingface.co/datasets/nvidia/HelpSteer3). The original dataset consists of [prompt, response1, response2, feedback]. The `feedback` column contains individual rankings (a score from 1-5) of each response from multiple annotators. We map scores 4-5 to a label of yes and scores 1-3 to a label of no, take the average of the annotators's scores and map each of the two responses to a binary yes/no label accordingly.
|
| 223 |
-
|
| 224 |
-
### Adapter Configuration
|
| 225 |
-
|
| 226 |
-
| Property | LoRA |
|
| 227 |
-
|---|---|
|
| 228 |
-
| **Base Model** | ibm-granite/granite-4.0-micro |
|
| 229 |
-
| **PEFT Type** | LORA |
|
| 230 |
-
| **Rank (r)** | 64 |
|
| 231 |
-
| **Alpha** | 64 |
|
| 232 |
-
| **Target Modules** | q_proj, k_proj, v_proj, o_proj, input_linear, output_linear |
|
| 233 |
-
| **vLLM Support** | Yes |
|
| 234 |
-
|
| 235 |
-
### Evaluation
|
| 236 |
-
The evaluations on Helpsteer3 and IFEval above are on the validation set and a heldout set, respectively.
|
| 237 |
-
|
| 238 |
-
### Infrastructure
|
| 239 |
-
|
| 240 |
-
Training was completed using 8 H100 GPUs. Evaluation (and inference) requires 1 H100 GPU.
|
| 241 |
-
|
| 242 |
-
## Ethical Considerations / Limitations
|
| 243 |
-
|
| 244 |
-
- The model must only be used in the prescribed evaluation mode, outputting JSON responses (`{"score": "yes"/"no"}`) based on the specified prompt template. Any deviation from this intended use may lead to unexpected outputs.
|
| 245 |
-
- The model is designed for evaluating constraint satisfaction in instruction-following scenarios.
|
| 246 |
-
- The model is only trained and tested on English data.
|
| 247 |
-
- The LoRA adapter is compatible with both vLLM (for efficient batched inference) and HuggingFace Transformers + PEFT.
|
| 248 |
-
|
| 249 |
-
## Citation
|
| 250 |
-
|
| 251 |
-
```bibtex
|
| 252 |
-
@misc{padhi2024graniteguardian,
|
| 253 |
-
title={Granite Guardian},
|
| 254 |
-
author={Inkit Padhi and Manish Nagireddy and Giandomenico Cornacchia and Subhajit Chaudhury and Tejaswini Pedapati and Pierre Dognin and Keerthiram Murugesan and Erik Miehling and Mart\'{i}n Santill\'{a}n Cooper and Kieran Fraser and Giulio Zizzo and Muhammad Zaid Hameed and Mark Purcell and Michael Desmond and Qian Pan and Zahra Ashktorab and Inge Vejsbjerg and Elizabeth M. Daly and Michael Hind and Werner Geyer and Ambrish Rawat and Kush R. Varshney and Prasanna Sattigeri},
|
| 255 |
-
year={2024},
|
| 256 |
-
eprint={2412.07724},
|
| 257 |
-
archivePrefix={arXiv},
|
| 258 |
-
primaryClass={cs.CL},
|
| 259 |
-
url={https://arxiv.org/abs/2412.07724},
|
| 260 |
-
}
|
| 261 |
-
```
|
| 262 |
-
|
| 263 |
-
## Resources
|
| 264 |
-
|
| 265 |
-
- ⭐️ Learn about the latest updates with Granite: https://www.ibm.com/granite
|
| 266 |
-
- 📄 Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
|
| 267 |
-
- 💡 Learn about the latest Granite learning resources: https://ibm.biz/granite-learning-resources
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
library_name:
|
| 7 |
+
- peft
|
| 8 |
+
- transformers
|
| 9 |
+
base_model:
|
| 10 |
+
- ibm-granite/granite-4.0-micro
|
| 11 |
+
- ibm-granite/granite-4.1-3b
|
| 12 |
+
- ibm-granite/granite-4.1-8b
|
| 13 |
+
- ibm-granite/granite-4.1-30b
|
| 14 |
+
tags:
|
| 15 |
+
- granite
|
| 16 |
+
- guardian
|
| 17 |
+
- uncertainty-quantification
|
| 18 |
+
- lora
|
| 19 |
+
- peft
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# Uncertainty Quantification
|
| 23 |
+
|
| 24 |
+
## Model Summary
|
| 25 |
+
|
| 26 |
+
**Uncertainty** is a family of LoRA/aLoRA adapters that provide calibrated certainty scores for Granite 4.1 models. The adapter responds with a certainty score from 0 to 9, which maps to a calibrated likelihood via `confidence = 0.1 * score + 0.05`, yielding 10 possible values (5%, 15%, 25%, ..., 95%). This percentage is *calibrated* in the following sense: given a set of answers assigned a certainty score of X%, approximately X% of these answers should be correct. We provide uncertainty adapters for Granite-4.0-micro, Granite-4.1-3B, Granite-4.1-8B, and Granite-4.1-30B.
|
| 27 |
+
|
| 28 |
+
- **Developer:** IBM Research
|
| 29 |
+
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 30 |
+
- **GitHub Repository:** https://github.com/ibm-granite
|
| 31 |
+
- **Last Updated:** May 5th, 2026
|
| 32 |
+
- **Model type:** LoRA/aLoRA adapters for:
|
| 33 |
+
- [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
|
| 34 |
+
- [ibm-granite/granite-4.1-3b](https://huggingface.co/ibm-granite/granite-4.1-3b)
|
| 35 |
+
- [ibm-granite/granite-4.1-8b](https://huggingface.co/ibm-granite/granite-4.1-8b)
|
| 36 |
+
- [ibm-granite/granite-4.1-30b](https://huggingface.co/ibm-granite/granite-4.1-30b)
|
| 37 |
+
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 38 |
+
- **Paper:** [[Shen et al. ICML 2024] Thermometer: Towards Universal Calibration for Large Language Models](https://arxiv.org/abs/2403.08819)
|
| 39 |
+
|
| 40 |
+
## Intended Use
|
| 41 |
+
|
| 42 |
+
Uncertainty is a LoRA adapter that enables Granite 4.1 base models to express calibrated self-assessments of their own answer correctness. The adapter is designed to be used as part of the Granite inference pipeline, activated via the `<certainty>` invocation token after the model generates a response.
|
| 43 |
+
|
| 44 |
+
**Adapter input:** An OpenAI-compatible chat completion request containing the user query and the model's response, followed by the `<certainty>` invocation token.
|
| 45 |
+
|
| 46 |
+
**Adapter output:** A JSON object `{"score": "X"}` where X is 0-9, mapping to calibrated confidence via `0.1 * score + 0.05`.
|
| 47 |
+
|
| 48 |
+
**Scoring:** When called via Mellea, the discrete 0–9 output is converted to a calibrated certainty float using the token-level probabilities over all 10 score categories, weighted by their mapped values (5%, 15%, …, 95%). This yields a continuous confidence estimate rather than a coarse 10-bin discretization. The threshold for "confident enough" is left to the user and may need to be tuned for your use-case.
|
| 49 |
+
|
| 50 |
+
### Use Cases
|
| 51 |
+
* **Human usage:** Certainty scores give human users an indication of when to trust answers from the model.
|
| 52 |
+
* **Model routing/guards:** If the model has low certainty (below a chosen threshold), route the request to a larger model or decline to show the response.
|
| 53 |
+
* **RAG:** Certainty scores can be applied to answers created using RAG, predicting overall correctness based on both the documents and the model's own knowledge.
|
| 54 |
+
|
| 55 |
+
## Usage Examples
|
| 56 |
+
|
| 57 |
+
### via Mellea
|
| 58 |
+
|
| 59 |
+
The recommended way to call this adapter is through the [Mellea](https://mellea.ai) framework:
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from mellea import model_ids, start_backend
|
| 63 |
+
from mellea.stdlib import functional as mfuncs
|
| 64 |
+
from mellea.stdlib.components.intrinsic import core
|
| 65 |
+
|
| 66 |
+
ctx, backend = start_backend(
|
| 67 |
+
"hf", model_id=model_ids.IBM_GRANITE_4_1_3B, context_type="chat"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
response, ctx = mfuncs.chat("What is IBM Research?", ctx, backend)
|
| 71 |
+
print(f"Response: {response.content}")
|
| 72 |
+
|
| 73 |
+
result = core.check_certainty(ctx, backend)
|
| 74 |
+
print(f"Certainty score: {result}")
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### via HF+PEFT
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import re
|
| 81 |
+
import torch
|
| 82 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 83 |
+
from peft import PeftModel
|
| 84 |
+
|
| 85 |
+
BASE_NAME = "ibm-granite/granite-4.1-3b"
|
| 86 |
+
LORA_REPO = "ibm-granite/granitelib-core-r1.0"
|
| 87 |
+
LORA_SUBFOLDER = "uncertainty/granite-4.1-3b/lora"
|
| 88 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 89 |
+
|
| 90 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_NAME, padding_side="left")
|
| 91 |
+
model_base = AutoModelForCausalLM.from_pretrained(BASE_NAME, device_map="auto", torch_dtype=torch.bfloat16)
|
| 92 |
+
model_uq = PeftModel.from_pretrained(
|
| 93 |
+
AutoModelForCausalLM.from_pretrained(BASE_NAME, device_map="auto", torch_dtype=torch.bfloat16),
|
| 94 |
+
LORA_REPO,
|
| 95 |
+
subfolder=LORA_SUBFOLDER,
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
question = "What is IBM Research?"
|
| 99 |
+
|
| 100 |
+
# Step 1: Generate answer with base model
|
| 101 |
+
messages = [{"role": "user", "content": question}]
|
| 102 |
+
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 103 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(device)
|
| 104 |
+
output = model_base.generate(**inputs, max_new_tokens=600, do_sample=False)
|
| 105 |
+
answer = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 106 |
+
|
| 107 |
+
# Step 2: Generate certainty score with LoRA adapter
|
| 108 |
+
uq_messages = [
|
| 109 |
+
{"role": "user", "content": question},
|
| 110 |
+
{"role": "assistant", "content": answer},
|
| 111 |
+
{"role": "user", "content": "<certainty>"},
|
| 112 |
+
]
|
| 113 |
+
uq_text = tokenizer.apply_chat_template(uq_messages, tokenize=False, add_generation_prompt=True)
|
| 114 |
+
inputs = tokenizer(uq_text, return_tensors="pt").to(device)
|
| 115 |
+
output = model_uq.generate(**inputs, max_new_tokens=15, do_sample=False)
|
| 116 |
+
uq_response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 117 |
+
|
| 118 |
+
# Parse score and map to confidence
|
| 119 |
+
match = re.search(r'\{[^}]*"score"\s*:\s*"?(\d)"?[^}]*\}', uq_response)
|
| 120 |
+
if match:
|
| 121 |
+
score = int(match.group(1))
|
| 122 |
+
confidence = 0.1 * score + 0.05
|
| 123 |
+
print(f"Score: {score}, Certainty: {confidence*100:.0f}%")
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
For more comprehensive examples, refer to the [Mellea intrinsics examples](https://github.com/generative-computing/mellea/tree/main/docs/examples/intrinsics).
|
| 127 |
+
|
| 128 |
+
## Evaluation
|
| 129 |
+
|
| 130 |
+
The adapters were evaluated on the [MMLU](https://huggingface.co/datasets/cais/mmlu) dataset (57 subsets, 14,042 total samples, not used in training). We report [Expected Calibration Error (ECE)](https://towardsdatascience.com/expected-calibration-error-ece-a-step-by-step-visual-explanation-with-python-code-c3e9aa12937d), Brier Score, AUROC, and Sharpness. Lower ECE and Brier scores indicate better calibration; higher AUROC indicates better discrimination between correct and incorrect answers.
|
| 131 |
+
|
| 132 |
+
### Results
|
| 133 |
+
|
| 134 |
+
| Model | Method | ECE | Brier Score | AUROC | Sharpness |
|
| 135 |
+
|---|---|---|---|---|---|
|
| 136 |
+
| Granite-4.0-micro | Base (seq prob) | 0.1606 | 0.2535 | 0.6748 | 0.2888 |
|
| 137 |
+
| | LoRA | 0.0565 | 0.2131 | 0.6903 | 0.1607 |
|
| 138 |
+
| Granite-4.1-3B | Base (seq prob) | 0.2879 | 0.3011 | 0.6291 | 0.0648 |
|
| 139 |
+
| | LoRA | 0.0998 | 0.1845 | 0.7870 | 0.1971 |
|
| 140 |
+
| | aLoRA | 0.0986 | 0.1877 | 0.7713 | 0.2027 |
|
| 141 |
+
| Granite-4.1-8B | Base (seq prob) | 0.1123 | 0.1932 | 0.6439 | 0.0438 |
|
| 142 |
+
| | LoRA | 0.0455 | 0.1487 | 0.7912 | 0.1898 |
|
| 143 |
+
| | aLoRA | 0.0381 | 0.1515 | 0.7778 | 0.1924 |
|
| 144 |
+
| Granite-4.1-30B | Base (seq prob) | 0.0921 | 0.1559 | 0.6507 | 0.0358 |
|
| 145 |
+
| | LoRA | 0.1006 | 0.1287 | 0.8116 | 0.1900 |
|
| 146 |
+
| | aLoRA | 0.1002 | 0.1317 | 0.8017 | 0.1927 |
|
| 147 |
+
|
| 148 |
+
The LoRA/aLoRA adapters consistently improve calibration (lower Brier scores) and discrimination (higher AUROC) across all model sizes, with zero-shot MMLU performance preserved.
|
| 149 |
+
|
| 150 |
+
## Training Details
|
| 151 |
+
|
| 152 |
+
The uncertainty adapters are finetuned to provide certainty scores mimicking the output of a calibrator trained via the Thermometer method ([Shen et al. ICML 2024](https://arxiv.org/abs/2403.08819)).
|
| 153 |
+
|
| 154 |
+
**Training Data:** Each adapter was trained on ~240K question-answer pairs generated by its respective base model, where each pair is annotated with a certainty score (0-9) derived from a calibrated thermometer model. The following datasets were used for calibration and/or fine-tuning:
|
| 155 |
+
|
| 156 |
+
* [BigBench](https://huggingface.co/datasets/tasksource/bigbench), [MRQA](https://huggingface.co/datasets/mrqa-workshop/mrqa), [newsqa](https://huggingface.co/datasets/lucadiliello/newsqa), [trivia_qa](https://huggingface.co/datasets/mandarjoshi/trivia_qa), [search_qa](https://huggingface.co/datasets/lucadiliello/searchqa), [openbookqa](https://huggingface.co/datasets/allenai/openbookqa), [web_questions](https://huggingface.co/datasets/Stanford/web_questions), [cosmos_qa](https://huggingface.co/datasets/allenai/cosmos_qa), [kilt_tasks](https://huggingface.co/datasets/facebook/kilt_tasks), [smiles-qa](https://huggingface.co/datasets/alxfgh/ChEMBL_Drug_Instruction_Tuning), [orca-math](https://huggingface.co/datasets/microsoft/orca-math-word-problems-200k), [ARC-Easy](https://huggingface.co/datasets/allenai/ai2_arc), [commonsense_qa](https://huggingface.co/datasets/tau/commonsense_qa), [social_i_qa](https://huggingface.co/datasets/allenai/social_i_qa), [super_glue](https://huggingface.co/datasets/aps/super_glue), [figqa](https://huggingface.co/datasets/nightingal3/fig-qa), [riddle_sense](https://huggingface.co/datasets/INK-USC/riddle_sense), [ag_news](https://huggingface.co/datasets/fancyzhx/ag_news), [medmcqa](https://huggingface.co/datasets/openlifescienceai/medmcqa), [dream](https://huggingface.co/datasets/dataset-org/dream), [codah](https://huggingface.co/datasets/jaredfern/codah), [piqa](https://huggingface.co/datasets/ybisk/piqa)
|
| 157 |
+
|
| 158 |
+
### Adapter Details
|
| 159 |
+
|
| 160 |
+
| Property | Granite-4.0-micro | Granite-4.1-3B | Granite-4.1-8B | Granite-4.1-30B |
|
| 161 |
+
|---|---|---|---|---|
|
| 162 |
+
| **PEFT Type** | LoRA | LoRA/aLoRA | LoRA/aLoRA | LoRA/aLoRA |
|
| 163 |
+
| **Rank (r)** | 32 | 32 | 32 | 32 |
|
| 164 |
+
| **Alpha** | 64 | 64 | 64 | 64 |
|
| 165 |
+
| **Target Modules** | q_proj, k_proj, v_proj, o_proj, input_linear, output_linear | q_proj, k_proj, v_proj, o_proj | q_proj, k_proj, v_proj, o_proj | q_proj, k_proj, v_proj, o_proj |
|
| 166 |
+
| **Invocation token (aLoRA)** | — | `<certainty>` | `<certainty>` | `<certainty>` |
|
| 167 |
+
| **Output format** | `{"score": "X"}` (X: 0-9) | `{"score": "X"}` (X: 0-9) | `{"score": "X"}` (X: 0-9) | `{"score": "X"}` (X: 0-9) |
|
| 168 |
+
| **Confidence mapping** | `0.1 * score + 0.05` | `0.1 * score + 0.05` | `0.1 * score + 0.05` | `0.1 * score + 0.05` |
|
| 169 |
+
| **Max completion tokens** | 15 | 15 | 15 | 15 |
|
| 170 |
+
|
| 171 |
+
**Infrastructure:** Training was completed using H100 GPUs.
|
| 172 |
+
|
| 173 |
+
**Ethical Considerations:** Certainty is inherently an intrinsic property of a model and its abilities. The Uncertainty adapter is not intended to predict the certainty of responses generated by any other models besides its corresponding base model. Certainty scores are *distributional* quantities and will do well on realistic questions in aggregate, but may have surprising scores on individual red-teamed examples. Certainty scores may be biased towards moderate values because: (1) calibrated models are less likely to output very high or very low confidence, (2) smaller models cannot perfectly self-assess, and (3) generalization to novel question difficulties requires hedging.
|
| 174 |
+
|
| 175 |
+
**Resources:**
|
| 176 |
+
- Learn about the latest updates with Granite: https://www.ibm.com/granite
|
| 177 |
+
- Get started with tutorials: https://www.ibm.com/granite/docs/
|
| 178 |
+
- Granite learning resources: https://ibm.biz/granite-learning-resources
|
|
@@ -1 +0,0 @@
|
|
| 1 |
-
*.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
@@ -1,136 +0,0 @@
|
|
| 1 |
-
# Micro Uncertainty
|
| 2 |
-
|
| 3 |
-
**Model Summary:** Uncertainty adapter provides calibrated certainty scores for [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro). The model responds with a certainty score from 0 to 9, which maps to a calibrated likelihood via `confidence = 0.1 * score + 0.05`, yielding 10 possible values (5%, 15%, 25%, ..., 95%). This percentage is *calibrated* in the following sense: given a set of answers assigned a certainty score of X%, approximately X% of these answers should be correct. See the evaluation section below for out-of-distribution verification of this behavior.
|
| 4 |
-
|
| 5 |
-
- **Developer:** IBM Research
|
| 6 |
-
- **HF Collection:** [Granite Libraries](https://huggingface.co/collections/ibm-granite/granite-libraries)
|
| 7 |
-
- **GitHub Repository:** https://github.com/ibm-granite
|
| 8 |
-
- **Release Date:** March 18th, 2026
|
| 9 |
-
- **Model Type:** LoRA adapter for [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro)
|
| 10 |
-
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 11 |
-
- **Paper:** Granite 4.0 Micro Uncertainty adapter is finetuned to provide certainty scores mimicking the output of a calibrator trained via the method in [[Shen et al. ICML 2024] Thermometer: Towards Universal Calibration for Large Language Models](https://arxiv.org/abs/2403.08819)
|
| 12 |
-
|
| 13 |
-
## Usage
|
| 14 |
-
|
| 15 |
-
**Intended use:** Uncertainty is a LoRA adapter the enables the Granite 4.0 Micro base model to express calibrated self-assessments of its own answer correctness. This adapter is designed to be used as part of the Granite inference pipeline, activated via the `<certainty>` invocation token after the model generates a response.
|
| 16 |
-
|
| 17 |
-
### Use Cases
|
| 18 |
-
* Human usage: Certainty scores give human users an indication of when to trust answers from the model (which should be augmented by their own knowledge).
|
| 19 |
-
* Model routing/guards: If the model has low certainty (below a chosen threshold), it may be worth sending the request to a larger, more capable model or simply choosing not to show the response to the user.
|
| 20 |
-
* RAG: Uncertainty is calibrated on diverse question-answering datasets, hence it can be applied to giving certainty scores for answers created using RAG. This certainty will be a prediction of overall correctness based on both the documents given and the model's own knowledge.
|
| 21 |
-
|
| 22 |
-
### Quickstart Example (LoRA)
|
| 23 |
-
|
| 24 |
-
```python
|
| 25 |
-
import torch
|
| 26 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 27 |
-
from peft import PeftModel
|
| 28 |
-
|
| 29 |
-
BASE_NAME = "ibm-granite/granite-4.0-micro"
|
| 30 |
-
LORA_REPO = "ibm-granite/granitelib-core-r1.0"
|
| 31 |
-
LORA_SUBFOLDER = "uncertainty/granite-4.0-micro/lora"
|
| 32 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 33 |
-
|
| 34 |
-
# Load model
|
| 35 |
-
tokenizer = AutoTokenizer.from_pretrained(BASE_NAME, padding_side="left", trust_remote_code=True)
|
| 36 |
-
model_base = AutoModelForCausalLM.from_pretrained(BASE_NAME, device_map="auto", torch_dtype=torch.bfloat16)
|
| 37 |
-
model_uq = PeftModel.from_pretrained(
|
| 38 |
-
AutoModelForCausalLM.from_pretrained(BASE_NAME, device_map="auto", torch_dtype=torch.bfloat16),
|
| 39 |
-
LORA_REPO,
|
| 40 |
-
subfolder=LORA_SUBFOLDER,
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
question = "What is IBM Research?"
|
| 44 |
-
print("Question:", question)
|
| 45 |
-
|
| 46 |
-
# Step 1: Generate answer with base model
|
| 47 |
-
messages = [
|
| 48 |
-
{"role": "user", "content": question},
|
| 49 |
-
]
|
| 50 |
-
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 51 |
-
inputs = tokenizer(input_text, return_tensors="pt").to(device)
|
| 52 |
-
output = model_base.generate(**inputs, max_new_tokens=600, do_sample=False)
|
| 53 |
-
answer = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 54 |
-
print("Answer:", answer)
|
| 55 |
-
|
| 56 |
-
# Step 2: Generate certainty score with LoRA adapter
|
| 57 |
-
uq_messages = [
|
| 58 |
-
{"role": "user", "content": question},
|
| 59 |
-
{"role": "assistant", "content": answer},
|
| 60 |
-
{"role": "user", "content": "<certainty>"},
|
| 61 |
-
]
|
| 62 |
-
uq_text = tokenizer.apply_chat_template(uq_messages, tokenize=False, add_generation_prompt=True)
|
| 63 |
-
inputs = tokenizer(uq_text, return_tensors="pt").to(device)
|
| 64 |
-
output = model_uq.generate(**inputs, max_new_tokens=15, do_sample=False)
|
| 65 |
-
uq_response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 66 |
-
print("Raw response:", uq_response)
|
| 67 |
-
|
| 68 |
-
# Parse score and map to confidence
|
| 69 |
-
import re
|
| 70 |
-
match = re.search(r'\{[^}]*"score"\s*:\s*"?(\d)"?[^}]*\}', uq_response)
|
| 71 |
-
if match:
|
| 72 |
-
score = int(match.group(1))
|
| 73 |
-
confidence = 0.1 * score + 0.05
|
| 74 |
-
print(f"Score: {score}, Certainty: {confidence*100:.0f}%")
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
## Evaluation
|
| 78 |
-
|
| 79 |
-
The adapter was evaluated on the [MMLU](https://huggingface.co/datasets/cais/mmlu) dataset (57 subsets, 14,042 total samples, not used in training). Shown are the [Expected Calibration Error (ECE)](https://towardsdatascience.com/expected-calibration-error-ece-a-step-by-step-visual-explanation-with-python-code-c3e9aa12937d) for each task, for the base model (granite-4.0-micro, using sequence probability as confidence) and the LoRA . The LoRA adapter achieves a weighted ECE of 0.0565, a 65% improvement over the base model's sequence-probability baseline of 0.1606. Additionally, the zero-shot performance on the MMLU tasks does not degrade, averaging at 63.2%.
|
| 80 |
-
|
| 81 |
-
| Metric | Base Model | LoRA |
|
| 82 |
-
|--------|:----------:|:----:|
|
| 83 |
-
| ECE | 0.1606 | 0.0565 |
|
| 84 |
-
| Brier Score | 0.2535 | 0.2131 |
|
| 85 |
-
| AUROC | 0.6748 | 0.6903 |
|
| 86 |
-
| Sharpness | 0.2888 | 0.1607 |
|
| 87 |
-
|
| 88 |
-
### Adapter Configurations
|
| 89 |
-
|
| 90 |
-
| Parameter | LoRA |
|
| 91 |
-
|-----------|------|
|
| 92 |
-
| Base model | ibm-granite/granite-4.0-micro |
|
| 93 |
-
| LoRA rank (r) | 32 |
|
| 94 |
-
| LoRA alpha | 64 |
|
| 95 |
-
| Target modules | q_proj, k_proj, v_proj, o_proj, input_linear, output_linear |
|
| 96 |
-
| Invocation token | `<certainty>` |
|
| 97 |
-
| Output format | `{"score": "X"}` where X is 0-9 |
|
| 98 |
-
| Confidence mapping | `0.1 * score + 0.05` (5% to 95%) |
|
| 99 |
-
| Max completion tokens | 15 |
|
| 100 |
-
| KV cache | Supported |
|
| 101 |
-
|
| 102 |
-
## Training Details
|
| 103 |
-
|
| 104 |
-
Granite 4.0 Micro Uncertainty LoRA adapter is finetuned to provide certainty scores mimicking the output of a calibrator trained via the method in [[Shen et al. ICML 2024] Thermometer: Towards Universal Calibration for Large Language Models](https://arxiv.org/abs/2403.08819).
|
| 105 |
-
|
| 106 |
-
**Training Data:** The adapter was trained on a dataset of ~199K question-answer pairs generated by the base model (granite-4.0-micro), where each pair is annotated with a certainty score (0-9) derived from a calibrated thermometer model. The following datasets were used for calibration and/or fine-tuning.
|
| 107 |
-
|
| 108 |
-
* [BigBench](https://huggingface.co/datasets/tasksource/bigbench)
|
| 109 |
-
* [MRQA](https://huggingface.co/datasets/mrqa-workshop/mrqa)
|
| 110 |
-
* [newsqa](https://huggingface.co/datasets/lucadiliello/newsqa)
|
| 111 |
-
* [trivia_qa](https://huggingface.co/datasets/mandarjoshi/trivia_qa)
|
| 112 |
-
* [search_qa](https://huggingface.co/datasets/lucadiliello/searchqa)
|
| 113 |
-
* [openbookqa](https://huggingface.co/datasets/allenai/openbookqa)
|
| 114 |
-
* [web_questions](https://huggingface.co/datasets/Stanford/web_questions)
|
| 115 |
-
* [smiles-qa](https://huggingface.co/datasets/alxfgh/ChEMBL_Drug_Instruction_Tuning)
|
| 116 |
-
* [orca-math](https://huggingface.co/datasets/microsoft/orca-math-word-problems-200k)
|
| 117 |
-
* [ARC-Easy](https://huggingface.co/datasets/allenai/ai2_arc)
|
| 118 |
-
* [commonsense_qa](https://huggingface.co/datasets/tau/commonsense_qa)
|
| 119 |
-
* [social_i_qa](https://huggingface.co/datasets/allenai/social_i_qa)
|
| 120 |
-
* [super_glue](https://huggingface.co/datasets/aps/super_glue)
|
| 121 |
-
* [figqa](https://huggingface.co/datasets/nightingal3/fig-qa)
|
| 122 |
-
* [riddle_sense](https://huggingface.co/datasets/INK-USC/riddle_sense)
|
| 123 |
-
* [ag_news](https://huggingface.co/datasets/fancyzhx/ag_news)
|
| 124 |
-
* [medmcqa](https://huggingface.co/datasets/openlifescienceai/medmcqa)
|
| 125 |
-
* [dream](https://huggingface.co/datasets/dataset-org/dream)
|
| 126 |
-
* [codah](https://huggingface.co/datasets/jaredfern/codah)
|
| 127 |
-
* [piqa](https://huggingface.co/datasets/ybisk/piqa)
|
| 128 |
-
|
| 129 |
-
**Infrastructure:** Training was completed using 8 H100 GPUs. Evaluation (and inference) requires 1 H100 GPU.
|
| 130 |
-
|
| 131 |
-
**Ethical Considerations:** Certainty is inherently an intrinsic property of a model and its abilities. The Uncertainty adapter is not intended to predict the certainty of responses generated by any other models besides itself or [ibm-granite/granite-4.0-micro](https://huggingface.co/ibm-granite/granite-4.0-micro). Additionally, certainty scores are *distributional* quantities, and so will do well on realistic questions in aggregate, but in principle may have surprising scores on individual red-teamed examples. Certainty scores, at times, may be biased towards moderate certainty scores for the following reasons. Firstly, as humans, we tend to be overconfident in our evaluation of what we know and don't know - in contrast, a calibrated model is less likely to output very high or very low confidence scores, as these imply certainty of correctness or incorrectness. Secondly, remember that the model is evaluating itself - correctness/incorrectness that may be obvious to larger models may be less obvious to a smaller model. Finally, teaching a model every fact it knows and doesn't know is not possible, hence it must generalize to questions of wildly varying difficulty. Intuitively, it does this by extrapolating based on related questions it has been evaluated on in training -- this is an inherently inexact process and leads to some hedging.
|
| 132 |
-
|
| 133 |
-
**Resources:**
|
| 134 |
-
- ⭐️ Learn about the latest updates with Granite: https://www.ibm.com/granite
|
| 135 |
-
- 📄 Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
|
| 136 |
-
- 💡 Learn about the latest Granite learning resources: https://ibm.biz/granite-learning-resources
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|