Views
No views yet
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
1import torch
2from transformers import AutoTokenizer, AutoModel, AutoModelForMaskedLM, pipeline
3
4MODEL_ID = "thebajajra/RexBERT-base"
5
6# Tokenizer
7tok = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True)
8
9# 1) Fill-Mask (if MLM head is present)
10mlm = pipeline("fill-mask", model=MODEL_ID, tokenizer=tok)
11print(mlm("These running shoes are great for [MASK] training."))
12
13# 2) Feature extraction (CLS or mean-pooled embeddings)
14enc = AutoModel.from_pretrained(MODEL_ID)
15inputs = tok(["wireless mouse", "ergonomic mouse pad"], padding=True, truncation=True, return_tensors="pt")
16with torch.no_grad():
17 out = enc(**inputs, output_hidden_states=True)
18# Mean-pool last hidden state for sentence embeddings
19emb = (out.last_hidden_state * inputs.attention_mask.unsqueeze(-1)).sum(dim=1) / inputs.attention_mask.sum(dim=1, keepdim=True)pretrain, ext, decay)| Domain | Size (GBs) |
|---|---|
| Hobby | 114 |
| News | 66 |
| Health | 66 |
| Entertainment | 64 |
| Travel | 52 |
| Food | 22 |
| Automotive | 19 |
| Sports | 12 |
| Music and Dance | 7 |
| Domain | Size (GBs) |
|---|---|
| Fashion | 37 |
| Beauty | 37 |
| Celebrity | 28 |
| Movie | 26 |
| Photo | 15 |
| Painting | 2 |

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

RexBERT models outperform all the models in their parameter/size category.
1from transformers import AutoModelForMaskedLM, AutoTokenizer, pipeline
2
3m = AutoModelForMaskedLM.from_pretrained("thebajajra/RexBERT-base")
4t = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
5fill = pipeline("fill-mask", model=m, tokenizer=t)
6
7fill("Best [MASK] headphones under $100.")1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
5enc = AutoModel.from_pretrained("thebajajra/RexBERT-base")
6
7texts = ["nike air zoom pegasus 40", "running shoes pegasus zoom nike"]
8batch = tok(texts, padding=True, truncation=True, return_tensors="pt")
9
10with torch.no_grad():
11 out = enc(**batch)
12# Mean-pool last hidden state
13attn = batch["attention_mask"].unsqueeze(-1)
14emb = (out.last_hidden_state * attn).sum(1) / attn.sum(1)
15# Normalize for cosine similarity (recommended for retrieval)
16emb = torch.nn.functional.normalize(emb, p=2, dim=1)1from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
2
3tok = AutoTokenizer.from_pretrained("thebajajra/RexBERT-base")
4model = AutoModelForSequenceClassification.from_pretrained("thebajajra/RexBERT-base", num_labels=NUM_LABELS)
5
6# Prepare your Dataset objects: train_ds, val_ds (text→label)
7args = TrainingArguments(
8 per_device_train_batch_size=32,
9 per_device_eval_batch_size=32,
10 learning_rate=3e-5,
11 num_train_epochs=3,
12 evaluation_strategy="steps",
13 fp16=True,
14 report_to="none",
15 load_best_model_at_end=True,
16)
17
18trainer = Trainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds, tokenizer=tok)
19trainer.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.