A versatile 5-gram language model for Slovenian trained on Wikipedia, forum discussions, and social media data using KenLM.
Model Description
This is a statistical n-gram language model designed for perplexity-based filtering and quality assessment of Slovenian text. The model was trained using the KenLM toolkit on a diverse mix of formal and informal Slovenian text sources.
Model Details
Model Type: 5-gram statistical language model
Language: Slovenian (sl)
Training Data:
Wikipedia (formal, encyclopedic): ~134k sentences from 5,000 articles
Janes-Forum (informal healthcare forums): ~28k sentences from 5,000 posts
Janes-Tag (social media, tweets, blogs): ~20k sentences of CMC data
Total Training Data: ~182k sentences
Model Size: ~50-100 MB (binary format with pruning)
Format: KenLM binary format
Preprocessing: Lowercased, cleaned of special characters, sentence-segmented (min 5 words)
Intended Use
This model is primarily intended for:
Text quality filtering: Identifying well-formed Slovenian text based on perplexity scores
Data cleaning: Filtering web-scraped corpora (e.g., OSCAR, Common Crawl)
Language detection: Distinguishing Slovenian from other languages
Quality assessment: Evaluating fluency and naturalness of generated text
Versatile Coverage
Unlike models trained only on Wikipedia, this mixed model handles:
✅ Formal/encyclopedic language (Wikipedia style)
✅ Forum discussions and questions
✅ Conversational Slovenian (everyday topics)
✅ Common slang and informal expressions
✅ Social media style text
Example Use Case
The model can be used to filter large text corpora by computing perplexity scores and keeping only texts within a reasonable range (25-5000), effectively removing:
Non-Slovenian or mixed-language content (high perplexity > 10,000)
Repetitive or boilerplate text (very low perplexity < 25)
Malformed or noisy text (high perplexity > 5,000)
Perplexity Benchmarks
Examples of perplexity scores on different text types:
Text Type
Example
Perplexity
Formal/encyclopedic
"V Sloveniji živi približno dva milijona ljudi."
44
Forum question
"Ima kdo izkušnje s tem programom."
74
Everyday conversation
"Danes je lep sončen dan."
318
Common slang
"Ma dej no to ni resno."
416
Informal praise
"Haha to je bilo smešno res."
1,523
English text
"the quick brown fox jumps"
37,960
Gibberish
"asdf qwer zxcv tyui hjkl"
408,383
Usage
python
1import kenlm
2from huggingface_hub import hf_hub_download
34# Download model from HuggingFace5model_path = hf_hub_download(6 repo_id="zustmartin/slovenian-kenlm-5gram-mixed",7 filename="slovenian_5gram_mixed.binary"8)910# Load the model11model = kenlm.Model(model_path)1213# Compute perplexity for a text14text ="to je primer slovenskega besedila"15perplexity = model.perplexity(text.lower())16print(f"Perplexity: {perplexity}")1718# Score individual sentences19score = model.score(text.lower())20print(f"Log10 probability: {score}")2122# Filter a corpus23defis_good_slovenian(text, lower=25, upper=5000):24"""Check if text is good quality Slovenian."""25 ppl = model.perplexity(text.lower().strip())26return lower <= ppl <= upper
2728texts =[29"Danes je lep sončen dan.",# Good30"asdf qwer zxcv",# Bad (gibberish)31"the quick brown fox",# Bad (English)32]3334for text in texts:35 ppl = model.perplexity(text.lower())36 status ="✅ KEEP"if is_good_slovenian(text)else"❌ FILTER"37print(f"{status} - {text} (perplexity: {ppl:.0f})")
Training Details
Training Data
Three diverse sources:
Wikipedia (formal, encyclopedic)
Source: Wikimedia Wikipedia (wikimedia/wikipedia dataset, version 20231101.sl)
1@misc{janesTag,
2 title={Training corpus Janes-Tag 3.0},
3 author={Erjavec, Toma{\v z} and Fišer, Darja and Krek, Simon and Ledinek, Nina and Arhar Holdt, {\v S}pela},
4 url={http://hdl.handle.net/11356/1732},
5 note={Slovenian language resource repository {CLARIN}.{SI}},
6 year={2022}
7}
89@misc{janesForum,
10 title={Janes-Forum 1.0: Corpus of Slovene forum posts},
11 author={Fišer, Darja and Erjavec, Toma{\v z} and Ljubešić, Nikola},
12 url={http://hdl.handle.net/11356/1139},
13 note={Slovenian language resource repository {CLARIN}.{SI}},
14 year={2017}
15}
License
The model weights are released under CC-BY-SA 4.0, compatible with the training data licenses: