Instructions to use zeromodels/modernbert_large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/modernbert_large with KerasFormers:
# 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
- Keras
How to use zeromodels/modernbert_large with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/modernbert_large") - Notebooks
- Google Colab
- Kaggle
Update model card (BERT-style tags + license)
Browse files
README.md
CHANGED
|
@@ -1,29 +1,71 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
license: apache-2.0
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: fill-mask
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: answerdotai/ModernBERT-large
|
| 5 |
+
library_name: kerasformers
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- kerasformers
|
| 9 |
+
- modernbert
|
| 10 |
+
- fill-mask
|
| 11 |
+
- text-encoder
|
| 12 |
+
- arxiv:2412.13663
|
| 13 |
+
- pytorch
|
| 14 |
+
- jax
|
| 15 |
+
- tf
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Run ModernBERT with Keras 3: JAX, PyTorch, or TensorFlow
|
| 19 |
+
|
| 20 |
+
[](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/modernbert/)
|
| 21 |
+
|
| 22 |
+
# kerasformers/modernbert_large
|
| 23 |
+
|
| 24 |
+
Paper: [Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder (arXiv:2412.13663)](https://arxiv.org/abs/2412.13663) · [HF Papers](https://huggingface.co/papers/2412.13663)
|
| 25 |
+
|
| 26 |
+
ModernBERT is Answer.AI / LightOn's modernized bidirectional transformer text encoder: rotary position embeddings, attention that alternates between a global (full) layer and local sliding-window layers, GeGLU feed-forwards, and pre-LayerNorm, with an 8192-token context. Byte-level BPE tokenizer; mask token `[MASK]`. No token-type ids.
|
| 27 |
+
|
| 28 |
+
For more details on the model, please go to the upstream [model card](https://huggingface.co/answerdotai/ModernBERT-large).
|
| 29 |
+
|
| 30 |
+
Pure-**Keras 3** conversion of [`answerdotai/ModernBERT-large`](https://huggingface.co/answerdotai/ModernBERT-large) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 31 |
+
|
| 32 |
+
This is a **fill-mask / encoder** checkpoint (`ModernBertMaskedLM`, modernbert_large). Task heads (sequence / token classify, QA, multiple choice) load via `hf:` fine-tunes.
|
| 33 |
+
|
| 34 |
+
## ✨ Quick start (fill-mask)
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
import os
|
| 38 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 39 |
+
|
| 40 |
+
from kerasformers.models.modernbert import ModernBertMaskedLM, ModernBertTokenizer
|
| 41 |
+
|
| 42 |
+
mlm = ModernBertMaskedLM.from_weights("kerasformers/modernbert_large")
|
| 43 |
+
tokenizer = ModernBertTokenizer.from_weights("kerasformers/modernbert_large")
|
| 44 |
+
|
| 45 |
+
inputs = tokenizer("The capital of France is [MASK].")
|
| 46 |
+
logits = mlm(inputs) # (1, L, vocab_size)
|
| 47 |
+
mask = int((inputs["input_ids"][0] == tokenizer.mask_token_id).argmax())
|
| 48 |
+
print(tokenizer.decode([int(logits[0, mask].argmax())]))
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Load any ModernBERT variant the same way with `from_weights("kerasformers/<variant>")`:
|
| 52 |
+
|
| 53 |
+
| Variant | Hub | layers | embed_dim |
|
| 54 |
+
|---|---|---|---|
|
| 55 |
+
| `modernbert_base` | [`kerasformers/modernbert_base`](https://huggingface.co/kerasformers/modernbert_base) | 22 | 768 |
|
| 56 |
+
| `modernbert_large` | [`kerasformers/modernbert_large`](https://huggingface.co/kerasformers/modernbert_large) | 28 | 1024 |
|
| 57 |
+
|
| 58 |
+
## Tips
|
| 59 |
+
|
| 60 |
+
- Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
|
| 61 |
+
- Prefer `ModernBertTokenizer.from_weights(...)` so tokenization matches.
|
| 62 |
+
- Use `[MASK]` (not `<mask>`).
|
| 63 |
+
- ModernBERT has no token-type ids; the tokenizer emits only `input_ids` / `attention_mask`.
|
| 64 |
+
- See [ModernBERT docs](https://imvision12.github.io/KerasFormers/modernbert/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
|
| 65 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `ModernBertMaskedLM.from_weights("hf:answerdotai/ModernBERT-large")`.
|
| 66 |
+
|
| 67 |
+
## Special Thanks
|
| 68 |
+
|
| 69 |
+
A huge thank you to the Answer.AI and LightOn authors for creating and releasing ModernBERT.
|
| 70 |
+
|
| 71 |
+
License: Apache 2.0.
|