Text Classification
Transformers
Safetensors
Bosnian
Croatian
Serbian
llama
LID
bosnian
croatian
serbian
yugo
text-embeddings-inference
Instructions to use absltnull/prebij with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use absltnull/prebij with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="absltnull/prebij")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("absltnull/prebij") model = AutoModelForSequenceClassification.from_pretrained("absltnull/prebij", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +104 -0
- chart1_plain.png +0 -0
- chart2_cyrillic.png +3 -0
- chart3_ascii.png +0 -0
- config.json +43 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +26 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
chart2_cyrillic.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# preBIJ :: Bosnian / Croatian / Serbian LID
|
| 2 |
+
|
| 3 |
+
*The linguistic intelligence of a native BCS language model used for language identificaton.*
|
| 4 |
+
|
| 5 |
+
**predBor Identifikator Jezika ("predBor Language Identifier")**, a language classification model based on the now retired predBor-v1 small BCS language model, **made specifically to tell apart Bosnian, Croatian and Serbian.**
|
| 6 |
+
|
| 7 |
+
## Retired but not forgotten
|
| 8 |
+
As noted, I made the decision to retire the predBor model series as the newer Bor models are in the works. However, retirement does not necessarily mean abandonment, at least not to me.
|
| 9 |
+
|
| 10 |
+
**preBIJ is a direct fine-tune of predBor,** changing the architecture to a classification model while **preserving all linguistical knowledge of the base,** effectively giving the old model a new life.
|
| 11 |
+
|
| 12 |
+
## Architecture
|
| 13 |
+
| Name | Value |
|
| 14 |
+
| --- | --- |
|
| 15 |
+
| Architecture | **LlamaForSequenceClassification** |
|
| 16 |
+
| Base Model | `absltnull/predBor-v1` |
|
| 17 |
+
| Maximum Sequence Length | **4096 tokens** (trained up to 196 tokens, retains accuracy up to 1024, untested beyond) |
|
| 18 |
+
| Classes | **bs, hr, sr** |
|
| 19 |
+
| Tokenizer Vocabulary | **65,000 tokens** |
|
| 20 |
+
| Tokenizer | **BorTokenizer-v2** |
|
| 21 |
+
| Supported Scripts | **Bosnian (Lat, Cyr), Serbian (Lat, Cyr), Croatian (Lat)** |
|
| 22 |
+
|
| 23 |
+
## The Idea
|
| 24 |
+
After the retirement of predBor, new ideas began to emerge for its new purpose. **RoBERTo-v2**, while capable, **is severely limited by its tokenizer and size**, so the natural question would be: *how would a native model perform at labeling such languages?*
|
| 25 |
+
|
| 26 |
+
**predBor was the perfect match.** It had a native BCS tokenizer, was triple the size of RoBERTo-v2, and had a massive, specialized understanding of all three languages *(plus English, not relevant)*, so it was naturally the first choice.
|
| 27 |
+
|
| 28 |
+
## The Surgery
|
| 29 |
+
I started with the original predBor-v1 model. Instead of loading it as a casual LM model, I used the `AutoModelForSequenceClassification.from_pretrained("absltnull/predBor-v1", num_labels=3)` function to load it as a three-way classification model with the type `LlamaForSequenceClassification`, initializing a random classification head on top of the model, instead of the base LM head.
|
| 30 |
+
|
| 31 |
+
Next, I had to train that randomly-initialized head to actually know which language is which, using the representations present in the base LM. This was a trivial task for me, though, as I already have my `absltnull/bcs-lang-id` dataset with over 90k examples of labeled BCS data.
|
| 32 |
+
|
| 33 |
+
The model trained for about 4 hours on my RTX 2050, and training loss dropped under 1.0 in the first 4% of the run, indicating that the head "got the gist" in like 10 minutes.
|
| 34 |
+
|
| 35 |
+
## The Performance
|
| 36 |
+
The final training loss was 0.2, **with 92% accuracy on the evaluation set,** basically **beating RoBERTo-v2 by 5 points of accuracy and F1.**
|
| 37 |
+
|
| 38 |
+
I ranked RoBERTo-v2 vs preBIJ on multiple tests other than accuracy and F1, and here are the results:
|
| 39 |
+
|
| 40 |
+
### Round 1: Accuracy
|
| 41 |
+

|
| 42 |
+
|
| 43 |
+
**model (acc, f1): preBIJ (0.919, 0.919) vs RoBERTo-v2 (0.868, 0.868)**
|
| 44 |
+
|
| 45 |
+
A close call, but actually beats RoBERTo-v2 on its own dataset. **preBIJ was actually trained on the same dataset as RoBERTo-v2,** yet it came out as the victor in this test.
|
| 46 |
+
|
| 47 |
+
### Round 2: Cyrillic
|
| 48 |
+

|
| 49 |
+
|
| 50 |
+
**Bosnian script (prebij acc, roberto acc): Latin (0.892, 0.847), Cyrillic (0.792, 0.000)**
|
| 51 |
+
**Serbian script (prebij acc, roberto acc): Latin (0.950, 0.871), Cyrillic (0.959, 1.000)**
|
| 52 |
+
|
| 53 |
+
As we all know, RoBERTo-v2 has a massive Cyrillic bias: **"all Cyrillic text => 100% Serbian".** This causes it to label every single Cyrillic text as Serbian, which makes it score 0% on the Cyrillic Bosnian test, and score a 100% on the Cyrillic Serbian test.
|
| 54 |
+
|
| 55 |
+
preBIJ, on the other hand, has managed to outperform RoBERTo-v2 on every metric on this test, scoring:
|
| 56 |
+
- 90% accuracy in recognizing Bosnian Latin text,
|
| 57 |
+
- 80% accuracy in recognizing Bosnian Cyrillic text,
|
| 58 |
+
- 95% accuracy in recognizing Serbian Latin text,
|
| 59 |
+
- 96% accuracy in recognizing Serbian Cyrillic text
|
| 60 |
+
|
| 61 |
+
**The amazing part is: it was never specifically trained to do this.**
|
| 62 |
+
|
| 63 |
+
**preBIJ has never seen a single sample in Cyrillic,** but predBor has. This means that the classification head has learned to generalize, basically using predBor's diverse knowledge of all three languages to recognize the *content* of the input rather than finding shortcuts in data.
|
| 64 |
+
|
| 65 |
+
**In plain words:** predBor knows the difference between Bosnian and Serbian, no matter the script, and the classification head inherited that knowledge, **making it beat RoBERTo-v2 in this metric effortlesly.**
|
| 66 |
+
|
| 67 |
+
### Round 3: Diacritics
|
| 68 |
+

|
| 69 |
+
|
| 70 |
+
**script (prebij acc, roberto acc): Latin (0.921, 0.859), ASCII (0.921, 0.851)**
|
| 71 |
+
|
| 72 |
+
Pretty useless test, but it proves a point: both models score the exact same result in labeling the languages, both with and without the diacritics *(though RoBERTo-v2 lost like 0.008 points without diacritics, but we'll ignore that)*.
|
| 73 |
+
|
| 74 |
+
## Using the model
|
| 75 |
+
**After seeing these results, we are safe to conclude that preBIJ is the top model for distinguishing BCS languages, even in rare script cases.**
|
| 76 |
+
|
| 77 |
+
To use the model, you can use this snipplet:
|
| 78 |
+
```python
|
| 79 |
+
import torch
|
| 80 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 81 |
+
|
| 82 |
+
tok = AutoTokenizer.from_pretrained("absltnull/prebij")
|
| 83 |
+
model = AutoModelForSequenceClassification.from_pretrained("absltnull/prebij")
|
| 84 |
+
|
| 85 |
+
classifier = pipeline(
|
| 86 |
+
"text-classification",
|
| 87 |
+
model=model,
|
| 88 |
+
tokenizer=tok,
|
| 89 |
+
device=0 if torch.cuda.is_available() else -1,
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
texts = [
|
| 93 |
+
"Ove sedmice moram da kupim bijeli hljeb.", # bs
|
| 94 |
+
"Ove nedelje moram da kupim beli hleb.", # sr
|
| 95 |
+
"Ovog tjedna moram da kupim bijeli kruh.", # hr
|
| 96 |
+
]
|
| 97 |
+
|
| 98 |
+
predictions = classifier(texts)
|
| 99 |
+
for text, pred in zip(texts, predictions):
|
| 100 |
+
print(f"[{pred['label']}] ({pred['score']:.2%}) {text}")
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## TL;DR
|
| 104 |
+
Absolute Intelligence has provided this model to be used freely, without any copyright obligations, other than stating that this model belongs to its rightful owner. Feel free to use, fine-tune or adapt this model to any of your preferences. Made with love in Bosnia. Bye.
|
chart1_plain.png
ADDED
|
chart2_cyrillic.png
ADDED
|
Git LFS Details
|
chart3_ascii.png
ADDED
|
config.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 3,
|
| 10 |
+
"head_dim": 96,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 1536,
|
| 13 |
+
"id2label": {
|
| 14 |
+
"0": "bs",
|
| 15 |
+
"1": "hr",
|
| 16 |
+
"2": "sr"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 4096,
|
| 20 |
+
"label2id": {
|
| 21 |
+
"bs": 0,
|
| 22 |
+
"hr": 1,
|
| 23 |
+
"sr": 2
|
| 24 |
+
},
|
| 25 |
+
"max_position_embeddings": 4096,
|
| 26 |
+
"mlp_bias": false,
|
| 27 |
+
"model_type": "llama",
|
| 28 |
+
"num_attention_heads": 16,
|
| 29 |
+
"num_hidden_layers": 24,
|
| 30 |
+
"num_key_value_heads": 16,
|
| 31 |
+
"pad_token_id": 3,
|
| 32 |
+
"pretraining_tp": 1,
|
| 33 |
+
"problem_type": "single_label_classification",
|
| 34 |
+
"rms_norm_eps": 1e-05,
|
| 35 |
+
"rope_parameters": {
|
| 36 |
+
"rope_theta": 10000.0,
|
| 37 |
+
"rope_type": "default"
|
| 38 |
+
},
|
| 39 |
+
"tie_word_embeddings": true,
|
| 40 |
+
"transformers_version": "5.21.1",
|
| 41 |
+
"use_cache": false,
|
| 42 |
+
"vocab_size": 65000
|
| 43 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af0d28e7027156b1cfe370ab8988b1845605e157887fe71ad24f6bac48e27410
|
| 3 |
+
size 1558828568
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"byte_fallback": true,
|
| 6 |
+
"clean_up_tokenization_spaces": false,
|
| 7 |
+
"eos_token": "<__end__>",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<s>",
|
| 10 |
+
"</s>",
|
| 11 |
+
"<__end__>",
|
| 12 |
+
"<__end_turn__>"
|
| 13 |
+
],
|
| 14 |
+
"is_local": false,
|
| 15 |
+
"legacy": false,
|
| 16 |
+
"local_files_only": false,
|
| 17 |
+
"model_max_length": 4096,
|
| 18 |
+
"normalization_rule_name": "identity",
|
| 19 |
+
"pad_token": "<__end__>",
|
| 20 |
+
"padding_side": "right",
|
| 21 |
+
"tokenizer_class": "TokenizersBackend",
|
| 22 |
+
"truncation_side": "right",
|
| 23 |
+
"unk_id": 0,
|
| 24 |
+
"unk_token": "<unk>",
|
| 25 |
+
"use_fast": false
|
| 26 |
+
}
|