IMvision12 commited on
Commit
2d5f501
·
verified ·
1 Parent(s): 0cf251f

Add zeromodels Keras 3 conversion of microsoft/mpnet-base

Browse files
Files changed (4) hide show
  1. README.md +92 -0
  2. model.weights.h5 +3 -0
  3. tokenizer.json +0 -0
  4. zm_config.json +23 -0
README.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: fill-mask
3
+ license: mit
4
+ base_model: microsoft/mpnet-base
5
+ library_name: zeromodels
6
+ language:
7
+ - en
8
+ tags:
9
+ - keras
10
+ - zeromodels
11
+ - mpnet
12
+ - fill-mask
13
+ - text-encoder
14
+ - arxiv:2004.09297
15
+ - pytorch
16
+ - jax
17
+ - tf
18
+ ---
19
+
20
+ ## ***See [our collection](https://huggingface.co/collections/zeromodels/mpnet-6ab0702ad43a267bae54ded1) for all versions of MPNet.***
21
+
22
+ # Run MPNet with Keras 3: JAX, PyTorch, or TensorFlow
23
+
24
+ [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-MPNet-blue)](https://imvision12.github.io/ZeroModels/mpnet/) [![Collection](https://img.shields.io/badge/HF-MPNet%20collection-yellow)](https://huggingface.co/collections/zeromodels/mpnet-6ab0702ad43a267bae54ded1)
25
+
26
+ # zeromodels/mpnet_base
27
+
28
+ Paper: [MPNet: Masked and Permuted Pre-training for Language Understanding (arXiv:2004.09297)](https://arxiv.org/abs/2004.09297) · [HF Papers](https://huggingface.co/papers/2004.09297)
29
+
30
+ MPNet is a bidirectional encoder pre-trained with **masked and permuted** language modeling, unifying BERT's masked-LM objective with XLNet's permuted one. Unlike BERT it has no token-type embeddings, offsets position ids past the padding id, and adds a shared relative position bias to every attention layer.
31
+
32
+ For more details on the model, please go to the upstream [model card](https://huggingface.co/microsoft/mpnet-base).
33
+
34
+ Pure-**Keras 3** conversion of [`microsoft/mpnet-base`](https://huggingface.co/microsoft/mpnet-base) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
35
+
36
+ This is a **fill-mask / encoder** checkpoint (`MPNetMaskedLM`, 12 layers / 768 dim). Task heads load via `hf:` fine-tunes.
37
+
38
+ ## ✨ Quick start (fill-mask)
39
+
40
+ ```python
41
+ import os
42
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
43
+
44
+ from zeromodels.models.mpnet import MPNetMaskedLM, MPNetTokenizer
45
+
46
+ mlm = MPNetMaskedLM.from_weights("zeromodels/mpnet_base")
47
+ tokenizer = MPNetTokenizer.from_weights("zeromodels/mpnet_base")
48
+
49
+ inputs = tokenizer("the capital of France is <mask>.")
50
+ logits = mlm(inputs) # (1, L, vocab_size)
51
+ mask = int((inputs["input_ids"][0] == tokenizer.mask_token_id).argmax())
52
+ print(tokenizer.decode([int(logits[0, mask].argmax())]))
53
+ ```
54
+
55
+ Load any MPNet variant the same way with `from_weights("zeromodels/<variant>")`:
56
+
57
+ | Variant | Hub |
58
+ |---|---|
59
+ | `mpnet_base` | [`zeromodels/mpnet_base`](https://huggingface.co/zeromodels/mpnet_base) |
60
+
61
+ ## Available classes
62
+
63
+ Load any of these from this repo with `from_weights("zeromodels/mpnet_base")` (or on the fly via the `hf:` prefix). The pretrained backbone is shared; task heads not stored in this checkpoint start randomly initialized, ready for fine-tuning (or load a `hf:` fine-tune).
64
+
65
+ | Class | Task |
66
+ |---|---|
67
+ | `MPNetModel` | Encoder backbone |
68
+ | `MPNetMaskedLM` | Masked language modeling (fill-mask) |
69
+ | `MPNetSequenceClassify` | Sequence classification |
70
+ | `MPNetTokenClassify` | Token classification (NER / POS) |
71
+ | `MPNetQnA` | Extractive question answering |
72
+ | `MPNetMultipleChoice` | Multiple choice |
73
+
74
+ ```python
75
+ from zeromodels.models.mpnet import MPNetSequenceClassify
76
+ model = MPNetSequenceClassify.from_weights("zeromodels/mpnet_base")
77
+ ```
78
+
79
+ ## Tips
80
+
81
+ - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
82
+ - Prefer `MPNetTokenizer.from_weights(...)` so the WordPiece vocab matches.
83
+ - Use `<mask>` (not `[MASK]`); MPNet pairs RoBERTa-style special tokens with a WordPiece vocabulary.
84
+ - MPNet takes `input_ids` + `attention_mask` only — there are no `token_type_ids`.
85
+ - See [MPNet docs](https://imvision12.github.io/ZeroModels/mpnet/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
86
+ - Community / upstream safetensors still work via the `hf:` prefix, e.g. `MPNetMaskedLM.from_weights("hf:microsoft/mpnet-base")`.
87
+
88
+ ## Special Thanks
89
+
90
+ A huge thank you to the Microsoft MPNet authors for creating and releasing these models.
91
+
92
+ License: MIT.
model.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f0108355e7303311ab0a3c8372e815314b714004dbf34f5456fa89b52f6e1fa
3
+ size 534681124
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
zm_config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.3.0",
4
+ "model_module": "zeromodels.models.mpnet",
5
+ "model_class": "MPNetModel",
6
+ "variant": "mpnet_base",
7
+ "weights": "model.weights.h5",
8
+ "schema_version": 2,
9
+ "weight_dtype": "float32",
10
+ "model_type": "mpnet",
11
+ "text_config": {
12
+ "vocab_size": 30527,
13
+ "embed_dim": 768,
14
+ "num_layers": 12,
15
+ "num_heads": 12,
16
+ "mlp_dim": 3072,
17
+ "max_position_embeddings": 514,
18
+ "relative_attention_num_buckets": 32,
19
+ "hidden_act": "gelu",
20
+ "layer_norm_eps": 1e-05,
21
+ "pad_token_id": 1
22
+ }
23
+ }