snchimata commited on
Commit
3877868
·
verified ·
1 Parent(s): e49976e

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: ibm-granite/granite-embedding-reranker-english-r2
4
+ library_name: peft
5
+ tags:
6
+ - cross-encoder
7
+ - lora
8
+ - peft
9
+ - context-compression
10
+ - text-compression
11
+ - english
12
+ - relevance-scoring
13
+ pipeline_tag: text-classification
14
+ ---
15
+
16
+ # tokenfold-select
17
+
18
+ A LoRA adapter for `ibm-granite/granite-embedding-reranker-english-r2`.
19
+ It ranks text spans by their relevance to a query, encoding each `(query, span)` pair jointly and
20
+ returning one logit. Higher logits indicate stronger evidence that the span should be kept.
21
+
22
+ This is a **ranking model, not a standalone compressor**. Use it with an allocator that separately
23
+ preserves required content and enforces the token budget. Do not use its scores as a safety filter.
24
+
25
+ ## Intended use
26
+
27
+ Use the model to rank pre-segmented passages, log lines, code blocks, or other text spans before
28
+ assembling a smaller context. Scores are most useful for ordering spans from the same document;
29
+ they are not calibrated probabilities or a substitute for hard retention rules.
30
+
31
+ ## How to use
32
+
33
+ ```python
34
+ from pathlib import Path
35
+
36
+ import torch
37
+ from huggingface_hub import snapshot_download
38
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
39
+ from peft import PeftModel
40
+
41
+ base_id = "ibm-granite/granite-embedding-reranker-english-r2"
42
+ repo_dir = Path(snapshot_download("OWNER/tokenfold-select")) # replace with this repository ID
43
+ adapter_dir = repo_dir / "adapter"
44
+ tok = AutoTokenizer.from_pretrained(adapter_dir)
45
+ base = AutoModelForSequenceClassification.from_pretrained(base_id, dtype=torch.float32)
46
+ model = PeftModel.from_pretrained(base, adapter_dir).eval()
47
+
48
+ def score(query: str, spans: list[str]) -> list[float]:
49
+ if not spans:
50
+ return []
51
+ enc = tok([query] * len(spans), spans, padding=True, truncation=True,
52
+ max_length=8192, return_tensors="pt")
53
+ with torch.no_grad():
54
+ out = model(input_ids=enc["input_ids"], attention_mask=enc["attention_mask"])
55
+ return out.logits.view(-1).float().tolist()
56
+ ```
57
+
58
+ The repository contains a PEFT adapter, not the base-model weights. Loading therefore also
59
+ downloads `ibm-granite/granite-embedding-reranker-english-r2`.
60
+
61
+ ## Training data
62
+
63
+ 97,449 source/query fixtures spanning code, logs, diffs, JSON and tool calls, agentic tool
64
+ use, and long-context QA. Sources include project-authored synthetic examples, SWE-bench Verified,
65
+ publicly available tool-output benchmark samples, and samples derived from HotpotQA, NarrativeQA,
66
+ SQuAD, TriviaQA, and MS MARCO. Each fixture pairs a source document, a query, a gold answer span,
67
+ and optional required spans that the downstream allocator must preserve regardless of model score.
68
+
69
+ ## Training procedure
70
+
71
+ LoRA (`r=8, alpha=16, dropout=0.05, target_modules="all-linear"`) via `peft`, applied for two epochs
72
+ to `ibm-granite/granite-embedding-reranker-english-r2` with `BCEWithLogitsLoss` and class-weighted positives. The released adapter was
73
+ trained on the full corpus; the results below come from separately trained held-out evaluation
74
+ runs.
75
+
76
+ ## Evaluation
77
+
78
+ Mean task success over three stratified repeated-subsampling runs (about 73,000 training and 24,000
79
+ held-out fixtures per run). Each run fine-tuned a fresh adapter, evaluated every method on the same
80
+ held-out fixtures, and used the same required-span and token-budget allocator. Task success means
81
+ that the literal gold-answer span survived compression.
82
+
83
+ | target token ratio | this model | Kompress-v2 (native) | Kompress-v2 relevance scorer | BM25 |
84
+ | --- | --- | --- | --- | --- |
85
+ | 0.5 | **0.863** | 0.665 | 0.805 | 0.794 |
86
+ | 0.25 | **0.703** | 0.472 | 0.615 | 0.607 |
87
+ | 0.1 | **0.399** | 0.304 | 0.377 | 0.377 |
88
+
89
+ At matched forced budgets, this model outperformed each baseline listed above at all three ratios.
90
+
91
+
92
+ Kompress-v2 and BM25 are named here as benchmark baselines the model is compared against, not as
93
+ an influence on this model's design.
94
+
95
+ ## Limitations
96
+
97
+ - Training labels are weak per-unit signals (does this span contain the gold answer?), not judged
98
+ per-token labels — treat results as directional.
99
+ - Task success measures literal answer-span retention, not downstream answer quality.
100
+ - Fixtures are English-centric despite the multilingual base model.
101
+ - Inputs longer than 8,192 tokens are truncated.
102
+ - Logits are uncalibrated and should be used for ranking, not as probabilities.
103
+ - The model cannot guarantee preservation of required or safety-critical text; the downstream
104
+ allocator must enforce those guarantees.
105
+
106
+ ## License
107
+
108
+ The adapter is released under Apache 2.0. The base model is also Apache 2.0; source datasets remain
109
+ subject to their own terms.
adapter/README.md ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: ibm-granite/granite-embedding-reranker-english-r2
3
+ library_name: peft
4
+ tags:
5
+ - base_model:adapter:ibm-granite/granite-embedding-reranker-english-r2
6
+ - lora
7
+ - transformers
8
+ ---
9
+
10
+ # Model Card for Model ID
11
+
12
+ <!-- Provide a quick summary of what the model is/does. -->
13
+
14
+
15
+
16
+ ## Model Details
17
+
18
+ ### Model Description
19
+
20
+ <!-- Provide a longer summary of what this model is. -->
21
+
22
+
23
+
24
+ - **Developed by:** [More Information Needed]
25
+ - **Funded by [optional]:** [More Information Needed]
26
+ - **Shared by [optional]:** [More Information Needed]
27
+ - **Model type:** [More Information Needed]
28
+ - **Language(s) (NLP):** [More Information Needed]
29
+ - **License:** [More Information Needed]
30
+ - **Finetuned from model [optional]:** [More Information Needed]
31
+
32
+ ### Model Sources [optional]
33
+
34
+ <!-- Provide the basic links for the model. -->
35
+
36
+ - **Repository:** [More Information Needed]
37
+ - **Paper [optional]:** [More Information Needed]
38
+ - **Demo [optional]:** [More Information Needed]
39
+
40
+ ## Uses
41
+
42
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
43
+
44
+ ### Direct Use
45
+
46
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
47
+
48
+ [More Information Needed]
49
+
50
+ ### Downstream Use [optional]
51
+
52
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
53
+
54
+ [More Information Needed]
55
+
56
+ ### Out-of-Scope Use
57
+
58
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
59
+
60
+ [More Information Needed]
61
+
62
+ ## Bias, Risks, and Limitations
63
+
64
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
65
+
66
+ [More Information Needed]
67
+
68
+ ### Recommendations
69
+
70
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
71
+
72
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
73
+
74
+ ## How to Get Started with the Model
75
+
76
+ Use the code below to get started with the model.
77
+
78
+ [More Information Needed]
79
+
80
+ ## Training Details
81
+
82
+ ### Training Data
83
+
84
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
85
+
86
+ [More Information Needed]
87
+
88
+ ### Training Procedure
89
+
90
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
91
+
92
+ #### Preprocessing [optional]
93
+
94
+ [More Information Needed]
95
+
96
+
97
+ #### Training Hyperparameters
98
+
99
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
100
+
101
+ #### Speeds, Sizes, Times [optional]
102
+
103
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
104
+
105
+ [More Information Needed]
106
+
107
+ ## Evaluation
108
+
109
+ <!-- This section describes the evaluation protocols and provides the results. -->
110
+
111
+ ### Testing Data, Factors & Metrics
112
+
113
+ #### Testing Data
114
+
115
+ <!-- This should link to a Dataset Card if possible. -->
116
+
117
+ [More Information Needed]
118
+
119
+ #### Factors
120
+
121
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
122
+
123
+ [More Information Needed]
124
+
125
+ #### Metrics
126
+
127
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
128
+
129
+ [More Information Needed]
130
+
131
+ ### Results
132
+
133
+ [More Information Needed]
134
+
135
+ #### Summary
136
+
137
+
138
+
139
+ ## Model Examination [optional]
140
+
141
+ <!-- Relevant interpretability work for the model goes here -->
142
+
143
+ [More Information Needed]
144
+
145
+ ## Environmental Impact
146
+
147
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
148
+
149
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
150
+
151
+ - **Hardware Type:** [More Information Needed]
152
+ - **Hours used:** [More Information Needed]
153
+ - **Cloud Provider:** [More Information Needed]
154
+ - **Compute Region:** [More Information Needed]
155
+ - **Carbon Emitted:** [More Information Needed]
156
+
157
+ ## Technical Specifications [optional]
158
+
159
+ ### Model Architecture and Objective
160
+
161
+ [More Information Needed]
162
+
163
+ ### Compute Infrastructure
164
+
165
+ [More Information Needed]
166
+
167
+ #### Hardware
168
+
169
+ [More Information Needed]
170
+
171
+ #### Software
172
+
173
+ [More Information Needed]
174
+
175
+ ## Citation [optional]
176
+
177
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
178
+
179
+ **BibTeX:**
180
+
181
+ [More Information Needed]
182
+
183
+ **APA:**
184
+
185
+ [More Information Needed]
186
+
187
+ ## Glossary [optional]
188
+
189
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
190
+
191
+ [More Information Needed]
192
+
193
+ ## More Information [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Authors [optional]
198
+
199
+ [More Information Needed]
200
+
201
+ ## Model Card Contact
202
+
203
+ [More Information Needed]
204
+ ### Framework versions
205
+
206
+ - PEFT 0.19.1
adapter/adapter_config.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "ModernBertForSequenceClassification",
7
+ "parent_library": "transformers.models.modernbert.modeling_modernbert"
8
+ },
9
+ "base_model_name_or_path": "ibm-granite/granite-embedding-reranker-english-r2",
10
+ "bias": "none",
11
+ "corda_config": null,
12
+ "ensure_weight_tying": false,
13
+ "eva_config": null,
14
+ "exclude_modules": null,
15
+ "fan_in_fan_out": false,
16
+ "inference_mode": true,
17
+ "init_lora_weights": true,
18
+ "layer_replication": null,
19
+ "layers_pattern": null,
20
+ "layers_to_transform": null,
21
+ "loftq_config": {},
22
+ "lora_alpha": 16,
23
+ "lora_bias": false,
24
+ "lora_dropout": 0.05,
25
+ "lora_ga_config": null,
26
+ "megatron_config": null,
27
+ "megatron_core": "megatron.core",
28
+ "modules_to_save": [
29
+ "head",
30
+ "classifier"
31
+ ],
32
+ "peft_type": "LORA",
33
+ "peft_version": "0.19.1",
34
+ "qalora_group_size": 16,
35
+ "r": 8,
36
+ "rank_pattern": {},
37
+ "revision": null,
38
+ "target_modules": [
39
+ "dense",
40
+ "Wi",
41
+ "Wo",
42
+ "classifier",
43
+ "Wqkv"
44
+ ],
45
+ "target_parameters": null,
46
+ "task_type": null,
47
+ "trainable_token_indices": null,
48
+ "use_bdlora": null,
49
+ "use_dora": false,
50
+ "use_qalora": false,
51
+ "use_rslora": false
52
+ }
adapter/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b407ee63caf3ad133b1bf351f45346dba9b8852c7fd899e7683246d574e16b9
3
+ size 9145724
adapter/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
adapter/tokenizer_config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": true,
4
+ "cls_token": "[CLS]",
5
+ "is_local": false,
6
+ "mask_token": "[MASK]",
7
+ "max_length": 1124,
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 1124,
13
+ "pad_to_multiple_of": null,
14
+ "pad_token": "[PAD]",
15
+ "pad_token_type_id": 0,
16
+ "padding_side": "right",
17
+ "sep_token": "[SEP]",
18
+ "stride": 0,
19
+ "tokenizer_class": "TokenizersBackend",
20
+ "truncation_side": "right",
21
+ "truncation_strategy": "longest_first",
22
+ "unk_token": "[UNK]"
23
+ }