mahwizzzz commited on
Commit
24c100d
·
verified ·
1 Parent(s): 9ae456b

Add Transformers AutoModelForMaskedLM remote code

Browse files
Files changed (1) hide show
  1. README.md +11 -25
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- library_name: pytorch
3
  license: apache-2.0
4
  pipeline_tag: fill-mask
5
  language:
@@ -72,38 +72,24 @@ Encoder-only MLM: pre-norm, RoPE, GeGLU, full attention, tied embeddings.
72
  | intermediate | 2048 |
73
  | vocab | 32,000 |
74
 
75
- This is a custom `PakEncoderForMLM` checkpoint (`model.safetensors` + `config.json`). It is **not** a drop-in `AutoModel` BERT.
76
 
77
  ## How to load
78
 
79
  ```python
80
- import json
81
- from pathlib import Path
82
- import torch
83
- from huggingface_hub import hf_hub_download
84
- from safetensors.torch import load_file
85
-
86
- # Install the Pakistan NLP Suite package, then:
87
- from paknlp_registry.encoder.config import EncoderConfig, SamplingConfig, MaskingConfig, TrainConfig
88
- from paknlp_registry.encoder.model import PakEncoderForMLM
89
 
90
  repo = "ProximaAI/PakMosaic-Small"
91
- cfg_path = hf_hub_download(repo, "config.json")
92
- raw = json.loads(Path(cfg_path).read_text(encoding="utf-8"))
93
- raw.pop("algebraic_parameters", None)
94
- if isinstance(raw.get("sampling"), dict):
95
- raw["sampling"] = SamplingConfig(**raw["sampling"])
96
- if isinstance(raw.get("masking"), dict):
97
- raw["masking"] = MaskingConfig(**raw["masking"])
98
- if isinstance(raw.get("train"), dict):
99
- raw["train"] = TrainConfig(**raw["train"])
100
- model = PakEncoderForMLM(EncoderConfig(**raw))
101
- weights = load_file(hf_hub_download(repo, "model.safetensors"))
102
- model.load_state_dict(weights)
103
- model.eval()
104
  ```
105
 
106
- Tokenizer artifact: `hf_byte_bpe_32k_identity` (hash `0f55e47920211588e6985172cd71338c8aff6226fe912c9668055b44bacc7ce7`). Frozen Urdu fertility 1.250 vs XLM-R 1.382 is a **tokenizer** metric, not model SOTA.
 
 
107
 
108
  ## Data
109
 
 
1
  ---
2
+ library_name: transformers
3
  license: apache-2.0
4
  pipeline_tag: fill-mask
5
  language:
 
72
  | intermediate | 2048 |
73
  | vocab | 32,000 |
74
 
75
+ This is a **custom PakMosaic encoder**, not BERT. Hugging Face Transformers loads it with `trust_remote_code=True` (RoPE + GeGLU + pre-norm live in this repo).
76
 
77
  ## How to load
78
 
79
  ```python
80
+ from transformers import AutoModelForMaskedLM, AutoTokenizer, pipeline
 
 
 
 
 
 
 
 
81
 
82
  repo = "ProximaAI/PakMosaic-Small"
83
+ tok = AutoTokenizer.from_pretrained(repo)
84
+ model = AutoModelForMaskedLM.from_pretrained(repo, trust_remote_code=True)
85
+
86
+ fill = pipeline("fill-mask", model=model, tokenizer=tok)
87
+ print(fill("یہ ایک <mask> ہے۔"))
 
 
 
 
 
 
 
 
88
  ```
89
 
90
+ `AutoModel` also works (`trust_remote_code=True`) and returns encoder hidden states.
91
+
92
+ Tokenizer: PakMosaic-Tokenizer-32k / `hf_byte_bpe_32k_identity` (hash `0f55e47920211588e6985172cd71338c8aff6226fe912c9668055b44bacc7ce7`). Frozen Urdu fertility 1.250 vs XLM-R 1.382 is a **tokenizer** metric, not model SOTA.
93
 
94
  ## Data
95