Instructions to use Eraly-ml/KazBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Eraly-ml/KazBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Eraly-ml/KazBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("Eraly-ml/KazBERT") model = AutoModelForMaskedLM.from_pretrained("Eraly-ml/KazBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download data-pipline.py from Eraly-ml/KazBERT: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/Eraly-ml/KazBERT/resolve/main/data-pipline.py
- Command line
-
hf download hf://Eraly-ml/KazBERT/data-pipline.py
-
curl -L -o data-pipline.py https://huggingface.co/Eraly-ml/KazBERT/resolve/main/data-pipline.py
1.19 kB
| import re | |
| import unicodedata | |
| import random | |
| input_file = "/kaggle/input/kaz-rus-eng-wiki/combined.txt" | |
| train_file = "train.txt" | |
| dev_file = "dev.txt" | |
| def normalize_text(text): | |
| text = unicodedata.normalize("NFC", text) | |
| text = text.lower() | |
| return text | |
| def clean_text(text): | |
| text = re.sub(r"<[^>]+>", " ", text) | |
| text = re.sub(r"\[\[.*?\]\]", " ", text) | |
| text = re.sub(r"\s+", " ", text) | |
| text = text.strip() | |
| return text | |
| cleaned_lines = [] | |
| with open(input_file, "r", encoding="utf-8") as f: | |
| for line in f: | |
| line = line.strip() | |
| if len(line) < 10: | |
| continue | |
| line = normalize_text(line) | |
| line = clean_text(line) | |
| if line: | |
| cleaned_lines.append(line) | |
| random.shuffle(cleaned_lines) | |
| split_index = int(0.8 * len(cleaned_lines)) | |
| train_lines = cleaned_lines[:split_index] | |
| dev_lines = cleaned_lines[split_index:] | |
| with open(train_file, "w", encoding="utf-8") as f: | |
| for line in train_lines: | |
| f.write(line + "\n") | |
| with open(dev_file, "w", encoding="utf-8") as f: | |
| for line in dev_lines: | |
| f.write(line + "\n") | |
| print(f"Train: {len(train_lines)}, Dev: {len(dev_lines)}") | |