Fill-Mask
Transformers
Safetensors
Ancient Greek (to 1453)
char_bert
ancient-greek
classical-philology
character-level
masked-diffusion
text-restoration
epigraphy
papyrology
custom_code
Instructions to use anonymous-stoicheia/Stoicheia-restoration-test4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use anonymous-stoicheia/Stoicheia-restoration-test4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="anonymous-stoicheia/Stoicheia-restoration-test4", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("anonymous-stoicheia/Stoicheia-restoration-test4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Processor: restore_respaced -- fill letters, then re-decide word division
Browse files- processing_char_bert.py +27 -0
processing_char_bert.py
CHANGED
|
@@ -295,6 +295,33 @@ class CharBertProcessor:
|
|
| 295 |
cap = batch["_cap"]
|
| 296 |
return self._restore_polytonic(chars, dia, cap, pred_bnd, punct)
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
def restore_elastic(self, model, text: str, min_width: int = 1,
|
| 299 |
mask_dia_boundary: bool = False, predict_punct: bool = True,
|
| 300 |
sentence_breaks: bool = True, gap_word_breaks: bool = True):
|
|
|
|
| 295 |
cap = batch["_cap"]
|
| 296 |
return self._restore_polytonic(chars, dia, cap, pred_bnd, punct)
|
| 297 |
|
| 298 |
+
def restore_respaced(self, model, text: str, **kw) -> str:
|
| 299 |
+
"""Restore a gap, then re-decide word division on the completed text.
|
| 300 |
+
|
| 301 |
+
The five planes are predicted independently in one pass, which is fine when the
|
| 302 |
+
whole context is bare (everything is decided together) but unreliable when a gap
|
| 303 |
+
sits inside already-spaced text: the boundary head sees a half-known segmentation
|
| 304 |
+
and hedges, so a correctly restored word can come back cut in two.
|
| 305 |
+
|
| 306 |
+
This does it in the order an editor would: fill the letters first, throw away the
|
| 307 |
+
spacing entirely, and run the model again over the resulting *scriptio continua*
|
| 308 |
+
with the boundary and diacritic planes unknown everywhere -- the regime the model
|
| 309 |
+
was pretrained on. `text` may carry either a `-` run or a `[N±M]` marker.
|
| 310 |
+
"""
|
| 311 |
+
if _ELASTIC_RE.search(text):
|
| 312 |
+
filled, _, _ = self.restore_elastic(model, text, **kw)
|
| 313 |
+
else:
|
| 314 |
+
batch = self(text)
|
| 315 |
+
with torch.no_grad():
|
| 316 |
+
out = model(**{k: v for k, v in batch.items() if not k.startswith("_")})
|
| 317 |
+
filled = self.decode_restoration(out, batch, **kw)
|
| 318 |
+
letters = "".join(ch for ch in unicodedata.normalize("NFD", filled)
|
| 319 |
+
if unicodedata.category(ch).startswith("L"))
|
| 320 |
+
batch = self(letters, mask_planes=["dia", "boundary"], has_boundaries=False)
|
| 321 |
+
with torch.no_grad():
|
| 322 |
+
out = model(**{k: v for k, v in batch.items() if not k.startswith("_")})
|
| 323 |
+
return self.decode_restoration(out, batch)
|
| 324 |
+
|
| 325 |
def restore_elastic(self, model, text: str, min_width: int = 1,
|
| 326 |
mask_dia_boundary: bool = False, predict_punct: bool = True,
|
| 327 |
sentence_breaks: bool = True, gap_word_breaks: bool = True):
|