Update README.md
Browse files
README.md
CHANGED
|
@@ -14,118 +14,216 @@ tags:
|
|
| 14 |
pipeline_tag: fill-mask
|
| 15 |
library_name: transformers
|
| 16 |
---
|
| 17 |
-
#
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
---
|
| 22 |
|
| 23 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
- **Model type:** `ModernBertForMaskedLM` (encoder-only, masked-language modeling head)
|
| 26 |
-
- **Domain:** **e-commerce**/**retail**/**shopping**
|
| 27 |
-
- **Language:** English
|
| 28 |
-
- **Context length:** 7,999–8,192 tokens (config max_position_embeddings=7999; ModernBERT supports up to 8192)
|
| 29 |
-
- **License:** Apache-2.0
|
| 30 |
---
|
| 31 |
|
| 32 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
- **Embeddings / feature extraction** for classification, clustering, retrieval re-ranking, and semantic search in retail catalogs and queries (via pooled encoder states). (ModernBERT is a drop-in BERT-style encoder.)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
### Out-of-scope / not recommended
|
| 42 |
-
- **Autoregressive text generation** or chat; this is not a decoder LLM. Use decoder or seq2seq models for long-form generation.
|
| 43 |
|
| 44 |
---
|
| 45 |
|
| 46 |
-
##
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
logits = model(**inputs).logits # use top-k on tok.mask_token_id
|
| 58 |
-
```
|
| 59 |
|
| 60 |
---
|
| 61 |
|
| 62 |
-
## Model
|
| 63 |
|
| 64 |
-
|
| 65 |
-
- **Backbone:** ModernBERT (`model_type: "modernbert"`, `architectures: ["ModernBertForMaskedLM"]`)
|
| 66 |
-
- **Layers / heads / width:** 19 encoder layers, 8 attention heads, hidden size 512; intermediate (MLP) size 768; GELU activations.
|
| 67 |
-
- **Attention:** Local window 128 with **global attention every 3 layers**; RoPE θ=160k (local & global).
|
| 68 |
-
- **Positional strategy:** `position_embedding_type: "sans_pos"`.
|
| 69 |
-
|
| 70 |
-
## Training data & procedure
|
| 71 |
|
| 72 |
---
|
| 73 |
|
| 74 |
-
##
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
-

|
| 91 |
|
| 92 |
---
|
| 93 |
|
|
|
|
| 94 |
|
| 95 |
-
## Technical notes for practitioners
|
| 96 |
|
| 97 |
-
|
| 98 |
-
- **Long sequences:** Leverage the extended context for product pages, multi-turn queries, or concatenated fields; ModernBERT uses efficient attention and RoPE for long inputs.
|
| 99 |
-
- **Libraries:** Tested with `transformers>=4.48.0`
|
| 100 |
|
| 101 |
-
---
|
| 102 |
|
| 103 |
-
## Model sources
|
| 104 |
|
| 105 |
-
- **Hugging Face:** `thebajajra/RexBERT-mini` — https://huggingface.co/thebajajra/RexBERT-mini
|
| 106 |
-
- **Background on ModernBERT:** https://huggingface.co/docs/transformers/en/model_doc/modernbert and overview: https://huggingface.co/docs/transformers/model_doc/modernbert
|
| 107 |
|
| 108 |
---
|
| 109 |
|
| 110 |
-
##
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
```
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
```
|
| 122 |
|
| 123 |
---
|
| 124 |
|
| 125 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
- **Author
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
- **Issues / questions:** Open an issue or discussion on the HF model page.
|
| 130 |
|
| 131 |
---
|
|
|
|
| 14 |
pipeline_tag: fill-mask
|
| 15 |
library_name: transformers
|
| 16 |
---
|
| 17 |
+
# RexBERT-mini
|
| 18 |
|
| 19 |
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
| 20 |
+
[](https://huggingface.co/collections/thebajajra/rexbert-68cc4b1b8a272f6beae5ebb8)
|
| 21 |
+
[](https://huggingface.co/datasets/thebajajra/Ecom-niverse)
|
| 22 |
+
[](https://github.com/bajajra/RexBERT)
|
| 23 |
+
|
| 24 |
+
> **TL;DR**: An encoder-only transformer (ModernBERT-style) for **e-commerce** applications, trained in three phases—**Pre-training**, **Context Extension**, and **Decay**—to power product search, attribute extraction, classification, and embeddings use cases. The model has been trained on 2.3T+ tokens along with 350B+ e-commerce-specific tokens
|
| 25 |
|
| 26 |
---
|
| 27 |
|
| 28 |
+
## Table of Contents
|
| 29 |
+
- [Quick Start](#quick-start)
|
| 30 |
+
- [Intended Uses & Limitations](#intended-uses--limitations)
|
| 31 |
+
- [Model Description](#model-description)
|
| 32 |
+
- [Training Recipe](#training-recipe)
|
| 33 |
+
- [Data Overview](#data-overview)
|
| 34 |
+
- [Evaluation](#evaluation)
|
| 35 |
+
- [Usage Examples](#usage-examples)
|
| 36 |
+
- [Masked language modeling](#1-masked-language-modeling)
|
| 37 |
+
- [Embeddings / feature extraction](#2-embeddings--feature-extraction)
|
| 38 |
+
- [Text classification fine-tune](#3-text-classification-fine-tune)
|
| 39 |
+
- [Model Architecture & Compatibility](#model-architecture--compatibility)
|
| 40 |
+
- [Efficiency & Deployment Tips](#efficiency--deployment-tips)
|
| 41 |
+
- [Responsible & Safe Use](#responsible--safe-use)
|
| 42 |
+
- [License](#license)
|
| 43 |
+
- [Maintainers & Contact](#maintainers--contact)
|
| 44 |
+
- [Citation](#citation)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
---
|
| 47 |
|
| 48 |
+
## Quick Start
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
import torch
|
| 52 |
+
from transformers import AutoTokenizer, AutoModel, AutoModelForMaskedLM, pipeline
|
| 53 |
+
|
| 54 |
+
MODEL_ID = "thebajajra/RexBERT-mini"
|
| 55 |
|
| 56 |
+
# Tokenizer
|
| 57 |
+
tok = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True)
|
|
|
|
| 58 |
|
| 59 |
+
# 1) Fill-Mask (if MLM head is present)
|
| 60 |
+
mlm = pipeline("fill-mask", model=MODEL_ID, tokenizer=tok)
|
| 61 |
+
print(mlm("These running shoes are great for [MASK] training."))
|
| 62 |
+
|
| 63 |
+
# 2) Feature extraction (CLS or mean-pooled embeddings)
|
| 64 |
+
enc = AutoModel.from_pretrained(MODEL_ID)
|
| 65 |
+
inputs = tok(["wireless mouse", "ergonomic mouse pad"], padding=True, truncation=True, return_tensors="pt")
|
| 66 |
+
with torch.no_grad():
|
| 67 |
+
out = enc(**inputs, output_hidden_states=True)
|
| 68 |
+
# Mean-pool last hidden state for sentence embeddings
|
| 69 |
+
emb = (out.last_hidden_state * inputs.attention_mask.unsqueeze(-1)).sum(dim=1) / inputs.attention_mask.sum(dim=1, keepdim=True)
|
| 70 |
+
```
|
| 71 |
|
|
|
|
|
|
|
| 72 |
|
| 73 |
---
|
| 74 |
|
| 75 |
+
## Intended Uses & Limitations
|
| 76 |
|
| 77 |
+
**Use cases**
|
| 78 |
+
- Product & query **retrieval/semantic search** (titles, descriptions, attributes)
|
| 79 |
+
- **Attribute extraction** / slot filling (brand, color, size, material)
|
| 80 |
+
- **Classification** (category assignment, unsafe/regulated item filtering, review sentiment)
|
| 81 |
+
- **Reranking** and **query understanding** (spelling/ASR normalization, acronym expansion)
|
| 82 |
|
| 83 |
+
**Out of scope**
|
| 84 |
+
- Long-form **generation** (use a decoder/seq-to-seq LM instead)
|
| 85 |
+
- High-stakes decisions without human review (pricing, compliance, safety flags)
|
| 86 |
|
| 87 |
+
**Target users**
|
| 88 |
+
- Search/recs engineers, e-commerce data teams, ML researchers working on domain-specific encoders
|
|
|
|
|
|
|
| 89 |
|
| 90 |
---
|
| 91 |
|
| 92 |
+
## Model Description
|
| 93 |
|
| 94 |
+
RexBERT-mini is an **encoder-only**, 68M parameter transformer trained with a masked-language-modeling objective and optimized for **e-commerce related text**. The three-phase training curriculum improves general language understanding, extends context handling, and then **specializes** on a very large corpus of commerce data to capture domain-specific terminology and entity distributions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
---
|
| 97 |
|
| 98 |
+
## Training Recipe
|
| 99 |
+
|
| 100 |
+
RexBERT-mini was trained in **three phases**:
|
| 101 |
|
| 102 |
+
1) **Pre-training**
|
| 103 |
+
General-purpose MLM pre-training on diverse English text for robust linguistic representations.
|
| 104 |
|
| 105 |
+
2) **Context Extension**
|
| 106 |
+
Continued training with **increased max sequence length** to better handle long product pages, concatenated attribute blocks, multi-turn queries, and facet strings. This preserves prior capabilities while expanding context handling.
|
| 107 |
|
| 108 |
+
3) **Decay on 350B+ e-commerce tokens**
|
| 109 |
+
Final specialization stage on **350B+ domain-specific tokens** (product catalogs, queries, reviews, taxonomy/attributes). Learning rate and sampling weights are annealed (decayed) to consolidate domain knowledge and stabilize performance on commerce tasks.
|
| 110 |
|
| 111 |
+
**Training details (fill in):**
|
| 112 |
+
- Optimizer / LR schedule: TODO
|
| 113 |
+
- Effective batch size / steps per phase: TODO
|
| 114 |
+
- Context lengths per phase (e.g., 512 → 1k/2k): TODO
|
| 115 |
+
- Tokenizer/vocab: TODO
|
| 116 |
+
- Hardware & wall-clock: TODO
|
| 117 |
+
- Checkpoint tags: TODO (e.g., `pretrain`, `ext`, `decay`)
|
| 118 |
|
| 119 |
+
---
|
| 120 |
|
| 121 |
+
## Data Overview
|
| 122 |
|
| 123 |
+
- **Domain mix:**
|
| 124 |
+
- **Data quality:**
|
| 125 |
|
| 126 |
|
|
|
|
| 127 |
|
| 128 |
---
|
| 129 |
|
| 130 |
+
## Evaluation
|
| 131 |
|
|
|
|
| 132 |
|
| 133 |
+
### Performance Highlights
|
|
|
|
|
|
|
| 134 |
|
|
|
|
| 135 |
|
|
|
|
| 136 |
|
|
|
|
|
|
|
| 137 |
|
| 138 |
---
|
| 139 |
|
| 140 |
+
## Usage Examples
|
| 141 |
|
| 142 |
+
### 1) Masked language modeling
|
| 143 |
+
```python
|
| 144 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer, pipeline
|
| 145 |
+
|
| 146 |
+
m = AutoModelForMaskedLM.from_pretrained("thebajajra/RexBERT-mini")
|
| 147 |
+
t = AutoTokenizer.from_pretrained("thebajajra/RexBERT-mini")
|
| 148 |
+
fill = pipeline("fill-mask", model=m, tokenizer=t)
|
| 149 |
+
|
| 150 |
+
fill("Best [MASK] headphones under $100.")
|
| 151 |
+
```
|
| 152 |
|
| 153 |
+
### 2) Embeddings / feature extraction
|
| 154 |
+
```python
|
| 155 |
+
import torch
|
| 156 |
+
from transformers import AutoTokenizer, AutoModel
|
| 157 |
+
|
| 158 |
+
tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-mini")
|
| 159 |
+
enc = AutoModel.from_pretrained("thebajajra/RexBERT-mini")
|
| 160 |
+
|
| 161 |
+
texts = ["nike air zoom pegasus 40", "running shoes pegasus zoom nike"]
|
| 162 |
+
batch = tok(texts, padding=True, truncation=True, return_tensors="pt")
|
| 163 |
+
|
| 164 |
+
with torch.no_grad():
|
| 165 |
+
out = enc(**batch)
|
| 166 |
+
# Mean-pool last hidden state
|
| 167 |
+
attn = batch["attention_mask"].unsqueeze(-1)
|
| 168 |
+
emb = (out.last_hidden_state * attn).sum(1) / attn.sum(1)
|
| 169 |
+
# Normalize for cosine similarity (recommended for retrieval)
|
| 170 |
+
emb = torch.nn.functional.normalize(emb, p=2, dim=1)
|
| 171 |
```
|
| 172 |
+
|
| 173 |
+
### 3) Text classification fine-tune
|
| 174 |
+
```python
|
| 175 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
|
| 176 |
+
|
| 177 |
+
tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-mini")
|
| 178 |
+
model = AutoModelForSequenceClassification.from_pretrained("thebajajra/RexBERT-mini", num_labels=NUM_LABELS)
|
| 179 |
+
|
| 180 |
+
# Prepare your Dataset objects: train_ds, val_ds (text→label)
|
| 181 |
+
args = TrainingArguments(
|
| 182 |
+
per_device_train_batch_size=32,
|
| 183 |
+
per_device_eval_batch_size=32,
|
| 184 |
+
learning_rate=3e-5,
|
| 185 |
+
num_train_epochs=3,
|
| 186 |
+
evaluation_strategy="steps",
|
| 187 |
+
fp16=True,
|
| 188 |
+
report_to="none",
|
| 189 |
+
load_best_model_at_end=True,
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
trainer = Trainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds, tokenizer=tok)
|
| 193 |
+
trainer.train()
|
| 194 |
```
|
| 195 |
|
| 196 |
---
|
| 197 |
|
| 198 |
+
## Model Architecture & Compatibility
|
| 199 |
+
|
| 200 |
+
- **Architecture:** Encoder-only, ModernBERT-style **mini** model.
|
| 201 |
+
- **Libraries:** Works with **🤗 Transformers**; supports **fill-mask** and **feature-extraction** pipelines.
|
| 202 |
+
- **Context length:** Increased during the **Context Extension** phase—ensure `max_position_embeddings` in `config.json` matches your desired max length.
|
| 203 |
+
- **Files:** `config.json`, tokenizer files, and (optionally) heads for MLM or classification.
|
| 204 |
+
- **Export:** Standard PyTorch weights; you can export ONNX / TorchScript for production if needed.
|
| 205 |
+
|
| 206 |
+
---
|
| 207 |
+
|
| 208 |
+
## Responsible & Safe Use
|
| 209 |
+
|
| 210 |
+
- **Biases:** Commerce data can encode brand, price, and region biases; audit downstream classifiers/retrievers for disparate error rates across categories/regions.
|
| 211 |
+
- **Sensitive content:** Add filters for adult/regulated items; document moderation thresholds if you release classifiers.
|
| 212 |
+
- **Privacy:** Do not expose PII; ensure training data complies with terms and applicable laws.
|
| 213 |
+
- **Misuse:** This model is **not** a substitute for legal/compliance review for listings.
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
+
## License
|
| 218 |
+
|
| 219 |
+
- **License:** `apache-2.0`.
|
| 220 |
+
---
|
| 221 |
+
|
| 222 |
+
## Maintainers & Contact
|
| 223 |
|
| 224 |
+
- **Author/maintainer:** [Rahul Bajaj](https://huggingface.co/thebajajra)
|
| 225 |
+
|
| 226 |
+
---
|
| 227 |
|
|
|
|
| 228 |
|
| 229 |
---
|