IMvision12 commited on
Commit
58e061e
·
verified ·
1 Parent(s): afc2327

Update model card (BERT-style tags + license)

Browse files
Files changed (1) hide show
  1. README.md +71 -29
README.md CHANGED
@@ -1,29 +1,71 @@
1
- ---
2
- library_name: kerasformers
3
- license: apache-2.0
4
- pipeline_tag: fill-mask
5
- tags:
6
- - keras
7
- - modernbert
8
- base_model: answerdotai/ModernBERT-large
9
- ---
10
-
11
- # modernbert_large
12
-
13
- ModernBERT converted to [kerasformers](https://github.com/IMvision12/KerasFormers)
14
- (pure Keras 3, runnable on JAX / PyTorch / TensorFlow). Converted from [`answerdotai/ModernBERT-large`](https://huggingface.co/answerdotai/ModernBERT-large).
15
-
16
- ```python
17
- from kerasformers.models.modernbert import ModernBertModel, ModernBertTokenizer
18
-
19
- model = ModernBertModel.from_weights("kerasformers/modernbert_large")
20
- tokenizer = ModernBertTokenizer.from_weights("kerasformers/modernbert_large")
21
- out = model(tokenizer("Hello, world."))["last_hidden_state"]
22
- ```
23
-
24
- | layers | embed_dim | heads | mlp_dim |
25
- |---|---|---|---|
26
- | 28 | 1024 | 16 | 2624 |
27
-
28
- The single `model.weights.h5` is the full masked-LM checkpoint; the encoder,
29
- masked-LM, and task-head classes each load their own subset.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-ModernBERT-blue)](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.