Upload modal_notebook_options.md with huggingface_hub
Browse files- modal_notebook_options.md +23 -7
modal_notebook_options.md
CHANGED
|
@@ -93,15 +93,31 @@ print("pushed to https://huggingface.co/CodeIsAbstract/sanskrit-sandhi-boundary-
|
|
| 93 |
|
| 94 |
## Cell 5 (optional) — quick sanity check on a phrase
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
```python
|
| 97 |
import os, torch
|
| 98 |
-
from
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
```
|
| 106 |
|
| 107 |
---
|
|
|
|
| 93 |
|
| 94 |
## Cell 5 (optional) — quick sanity check on a phrase
|
| 95 |
|
| 96 |
+
`decode_best.py` needs the full local Sanskrit stack (sanskrit_parser, vidyut,
|
| 97 |
+
SanskritTokenizer) that only exists on your Mac — don't import it here.
|
| 98 |
+
This lightweight check only needs what Cell 2 already downloaded:
|
| 99 |
+
|
| 100 |
```python
|
| 101 |
import os, torch
|
| 102 |
+
from model import HybridTimeScaleConfig
|
| 103 |
+
from train_split_model import BinaryBoundaryModel, char_to_idx, PAD_ID
|
| 104 |
+
from safetensors.torch import load_file
|
| 105 |
+
|
| 106 |
+
ckpt = "checkpoints/delayed_model_save_fixed_delay2"
|
| 107 |
+
cfg = HybridTimeScaleConfig.from_pretrained(ckpt) # config.json written by the trainer
|
| 108 |
+
model = BinaryBoundaryModel(cfg)
|
| 109 |
+
model.load_state_dict(load_file(os.path.join(ckpt, "model.safetensors")), strict=False)
|
| 110 |
+
model.eval().to(torch.device("cuda"))
|
| 111 |
+
|
| 112 |
+
text = "satyamevajayatenAnftaM"
|
| 113 |
+
ids = torch.tensor([[char_to_idx.get(c, PAD_ID) for c in text] + [PAD_ID]*2],
|
| 114 |
+
dtype=torch.long, device="cuda")
|
| 115 |
+
mask = torch.ones(1, len(text)+2, dtype=torch.long, device="cuda")
|
| 116 |
+
with torch.no_grad():
|
| 117 |
+
p = torch.sigmoid(model(input_ids=ids, attention_mask=mask)["logits"].squeeze(0)).cpu()
|
| 118 |
+
|
| 119 |
+
print("boundary probs:", [f"{p[i]:.2f}" for i in range(len(text))])
|
| 120 |
+
print("predicted split:", "".join(c + (" " if p[i] > 0.5 else "") for i, c in enumerate(text)))
|
| 121 |
```
|
| 122 |
|
| 123 |
---
|