Downloads · 30 days
246
2% of all-time downloads
thebajajra/RexBERT-base
RexBERT-base is a fill-mask model from thebajajra. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as apache-2.0.
[](https://www.apache.org/licenses/LICENSE-2.0) [](https://huggingface.co/collections/thebajajra/rexbert-68cc4b1b8a272f6beae5ebb8) [](https://huggingface.co/datasets/thebajajra/Ecom-niverse)
Downloads · 30 days
246
2% of all-time downloads
All-time downloads
13.2K
Public
Parameters
150M
1.2 GB on disk
Likes
11
Public
Click a slice to open those files.
.bin599 MB · 50%
From the Hugging Face model README
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
import torch
from transformers import AutoTokenizer, AutoModel, AutoModelForMaskedLM, pipeline
MODEL_ID = "thebajajra/RexBERT-base"
# Tokenizer
tok = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True)
# 1) Fill-Mask (if MLM head is present)
mlm = pipeline("fill-mask", model=MODEL_ID, tokenizer=tok)
print(mlm("These running shoes are great for [MASK] training."))
# 2) Feature extraction (CLS or mean-pooled embeddings)
enc = AutoModel.from_pretrained(MODEL_ID)
inputs = tok(["wireless mouse", "ergonomic mouse pad"], padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
out = enc(**inputs, output_hidden_states=True)
# Mean-pool last hidden state for sentence embeddings
emb = (out.last_hidden_state * inputs.attention_mask.unsqueeze(-1)).sum(dim=1) / inputs.attention_mask.sum(dim=1, keepdim=True)
Use cases
Out of scope
Target users
RexBERT-base is an encoder-only, 150M 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.
RexBERT-base was trained in three phases:
Pre-training
General-purpose MLM pre-training on diverse English text for robust linguistic representations.
Context Extension
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.
Decay on 350B+ e-commerce tokens
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.
Training details (fill in):
pretrain, ext, decay)We identified 9 E-commerce overlapping domains which have significant amount of relevant tokens but required filteration. Below is the domain list and their filtered size
| Domain | Size (GBs) |
|---|---|
| Hobby | 114 |
| News | 66 |
| Health | 66 |
| Entertainment | 64 |
| Travel | 52 |
| Food | 22 |
| Automotive | 19 |
| Sports | 12 |
| Music and Dance | 7 |
Additionally, there are 6 more domains which had almost complete overlap and were picked directly out of FineFineWeb.
| Domain | Size (GBs) |
|---|---|
| Fashion | 37 |
| Beauty | 37 |
| Celebrity | 28 |
| Movie | 26 |
| Photo | 15 |
| Painting | 2 |
By focusing on these domains, we narrow the search space to parts of the web data where shopping-related text is likely to appear. However, even within a chosen domain, not every item is actually about buying or selling, many may be informational articles, news, or unrelated discussions. Thus, a more fine-grained filtering within each domain is required to extract only the e-commerce-specific lines. We accomplish this by training lightweight classifiers per domain to distinguish e-commerce context vs. non-e-commerce content.

With 2–3x fewer parameters, RexBERT surpasses the performance of the ModernBERT series.

RexBERT models outperform all the models in their parameter/size category.
from transformers import AutoModelForMaskedLM, AutoTokenizer, pipeline
m = AutoModelForMaskedLM.from_pretrained("thebajajra/RexBERT-base")
t = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
fill = pipeline("fill-mask", model=m, tokenizer=t)
fill("Best [MASK] headphones under $100.")
import torch
from transformers import AutoTokenizer, AutoModel
tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
enc = AutoModel.from_pretrained("thebajajra/RexBERT-base")
texts = ["nike air zoom pegasus 40", "running shoes pegasus zoom nike"]
batch = tok(texts, padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
out = enc(**batch)
# Mean-pool last hidden state
attn = batch["attention_mask"].unsqueeze(-1)
emb = (out.last_hidden_state * attn).sum(1) / attn.sum(1)
# Normalize for cosine similarity (recommended for retrieval)
emb = torch.nn.functional.normalize(emb, p=2, dim=1)
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
model = AutoModelForSequenceClassification.from_pretrained("thebajajra/RexBERT-base", num_labels=NUM_LABELS)
# Prepare your Dataset objects: train_ds, val_ds (text→label)
args = TrainingArguments(
per_device_train_batch_size=32,
per_device_eval_batch_size=32,
learning_rate=3e-5,
num_train_epochs=3,
evaluation_strategy="steps",
fp16=True,
report_to="none",
load_best_model_at_end=True,
)
trainer = Trainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds, tokenizer=tok)
trainer.train()
max_position_embeddings in config.json matches your desired max length.config.json, tokenizer files, and (optionally) heads for MLM or classification.apache-2.0.