Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- udm
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
Inspired by https://huggingface.co/slone/bert-tiny-char-ctc-bak-denoise
|
| 7 |
+
|
| 8 |
+
# bert-tiny-char-ctc-udm-denoise
|
| 9 |
+
|
| 10 |
+
This is a tiny BERT model for Udmurt, intended for fixing OCR errors.
|
| 11 |
+
|
| 12 |
+
Here is the code to run it (it uses a custom tokenizer, with the code downloaded in the runtime):
|
| 13 |
+
```python
|
| 14 |
+
import torch
|
| 15 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 16 |
+
|
| 17 |
+
MODEL_NAME = 'udmurtNLP/bert-tiny-char-ctc-udm-denoise'
|
| 18 |
+
model = AutoModelForMaskedLM.from_pretrained(MODEL_NAME)
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 20 |
+
|
| 21 |
+
def fix_text(text, verbose=False, spaces=2):
|
| 22 |
+
with torch.inference_mode():
|
| 23 |
+
batch = tokenizer(text, return_tensors='pt', spaces=spaces, padding=True, truncation=True, return_token_type_ids=False).to(model.device)
|
| 24 |
+
logits = torch.log_softmax(model(**batch).logits, axis=-1)
|
| 25 |
+
decoded = tokenizer.decode(logits[0].argmax(-1), skip_special_tokens=True)
|
| 26 |
+
return tokenizer.clean_up_tokenization(decoded)
|
| 27 |
+
fix_text("кыче мои солы оскылй!")
|
| 28 |
+
# Кыӵе мон солы оскылӥ!
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
It was trained on a parallel corpus (corrupted + fixed sentence) with CTC loss. On our test dataset, it reduces OCR errors by 50%.
|