File size: 8,646 Bytes
33df640 46d2c3b 15e2aa1 e088865 33df640 4a2ba3c a14e613 57dee11 a14e613 17eb257 a14e613 2647141 a14e613 57dee11 a14e613 52d40f9 359aad8 a14e613 359aad8 a14e613 86ed547 a14e613 86ed547 a14e613 86ed547 a14e613 91cc0ce 86ed547 a14e613 cc008b5 a14e613 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | ---
license: apache-2.0
language:
- sr
datasets:
- procesaur/sr-tokenizer-test
---
<img style="width:100%;" src="cover.png" class="cover">
<table style="width:100%;border-collapse:collapse;">
<tr style="width:100%;">
<td colspan=2 align=center>
<h1>
<span class="highlight-container">
<span class="highlight">Srna Tokenizer</span>
</span>
</h1>
</td>
</tr>
<tr style="width:100%;height:100%">
<td width=50% valign=top>
<p><b>Срна</b> је специјализовани токенизатор за српски језик.</p>
<p>Укључује неколико слојева нормализације у циљу уједначавања ћирилице и латинице и смањења броја редудантних токена.</p>
<p>Покривена су три случаја:</p>
<ul>
<li><b>Компресија писма</b>: реч <code>текст</code> postaje <code><boc> tekst<eoc></code> приликом обраде, чувајући информацији о употреби писма, како би се у процесу декодирања извршила рестаурација.</li>
<li><b>Компресија капитализације</b>: реч <code>Tekst</code> постаје <code><cap> tekst</code>, чувајући потребне информације да би се текст реконстурисао, избегавајући засебне токене за <code>Tekst</code> и <code>tekst</code>.</li>
<li><b>Компресија великих слова</b>: реч <code>TEKST</code> постаје <code><up> tekst</code>, како би се избегло разбијање на појединачне карактере, притом чувајући инофмрације неопходне за рекоснтрукцију као и у претходним случајевима.</li>
</ul>
<p>Овај приступ изједначава латиницу и ћирилицу у моделу, смањујући дупликацију, олакшавајући учење и побољшавајући компресију кроз ослобађање места у вокабулару.</p>
<p><b>Ограничење:</b> рестаурација ћирилице је комплексан задатак и захтева листу изузетака за диграфе (<code>dž</code>, <code>lj</code>, <code>nj</code> и у посебним случајевима <code>dj</code>). Овде су имплементиране до сада најпотпуније листе изузетака за српски језик, оформљене за потребе софтвера <a href="https://github.com/turanjanin/cirilizator/">Ћирилизатор</a>.</p>
<p>Напомена: и постојећи токенизатори/модели се могу адаптирати. У том случају, је препоручено је искључивање компресије капитализације и великих слова, уколико се не ради дообучавање модела.</p>
</td>
<td width=50% valign=top>
<p><b>Srna</b> is a specialized tokenizer for the Serbian language.</p>
<p>It includes several layers of normalization in order to equlaize Cyrillic and Latin scripts and reduce the number of redundant tokens.</p>
<p>Three cases are covered:</p>
<ul>
<li><b>Script compression</b>: the word <code>text</code> becomes <code><boc> text<eoc></code> during processing, preserving information about the script usage, in order to perform restoration during the decoding process.</li>
<li><b>Capitalization compression</b>: the word <code>Text</code> becomes <code><cap> text</code>, preserving the information needed to reconstruct the text, avoiding separate tokens for <code>Text</code> and <code>text</code>.</li>
<li><b>Uppercase compression</b>: the word <code>TEXT</code> becomes <code><up> text</code>, to avoid breaking it into individual characters, while preserving the information necessary for reconstruction as in the previous cases.</li>
</ul>
<p>This approach equates Latin and Cyrillic in the model, reducing duplication, facilitating learning, and improving compression by freeing up space in the vocabulary.</p>
<p><b>Limitation:</b> Cyrillic restoration is a complex task and requires a list of exceptions for digraphs (<code>dž</code>, <code>lj</code>, <code>nj</code> and in some cases <code>dj</code>). The most complete lists of exceptions for the Serbian language have been implemented here, designed for the needs of the <a href="https://github.com/turanjanin/cirilizator/">Cirilizator</a> software.</p>
<p>Note: Existing tokenizers/models can also be adapted. In that case, it is recommended to turn off capitalization and uppercase compression unless fine-tuning of the model is being done.</p>
</td>
</td>
</tr>
</table>
---
## Употреба / Usage
```python
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("procesaur/Srna_tokenizer", trust_remote_code=True)
# Options
#tokenizer.case_compression=False
#tokenizer.script_compression=False
#tokenizer.omit_tags=True
text = "Pitao sam se 'да ли ће ме и рођени дјед и оџак надживети'?"
# Tokenize and print tokens
tokens = tokenizer.tokenize(text)
print(tokens)
# Encode to ids and decode back to string
ids = tokenizer.encode(text)
decoded = tokenizer.decode(ids)
print(decoded)
print(text==decoded)
```
```python
['<capi>', 'pita', 'o', 'Ġsam', 'Ġse', "Ġ'", '<csta>', 'da', 'Ġli', 'ĠÄĩe', 'Ġme', 'Ġi', 'ĠroÄijeni', 'Ġdje', 'd', 'Ġi', 'Ġod', 'žak', 'Ġnad', 'ži', 'veti', "'", '?']
"Pitao sam se 'да ли ће ме и рођени дјед и оџак надживети'?"
True
```
<div class="inline-flex flex-col" style="line-height: 1.5;padding-right:50px">
<div style="text-align: center; margin-top: 3px; font-size: 16px; font-weight: 800">Аутор / Author</div>
<a href="https://huggingface.co/procesaur">
<div class="flex">
<div
style="display:DISPLAY_1; margin-left: auto; margin-right: auto; width: 92px; height:92px; border-radius: 50%;
background-size: cover; background-image: url('https://cdn-uploads.huggingface.co/production/uploads/1673534533167-63bc254fb8c61b8aa496a39b.jpeg?w=200&h=200&f=face')">
</div>
</div>
</a>
<div style="text-align: center; font-size: 16px; font-weight: 800">Mihailo Škorić</div>
<div>
<a href="https://huggingface.co/procesaur">
<div style="text-align: center; font-size: 14px;">@procesaur</div>
</a>
</div>
</div>
</div>
Citation:
```bibtex
ускоро / soon
```
<div id="zastava">
<div class="grb">
<img src="https://www.ai.gov.rs/img/logo_60x120-2.png" style="position:relative; left:30px; z-index:10; height:85px">
</div>
<table width=100% style="border:0px">
<tr style="background-color:#C6363C;width:100%;border:0px;height:30px"><td style="width:100vw"></td></tr>
<tr style="background-color:#0C4076;width:100%;border:0px;height:30px"><td></td></tr>
<tr style="background-color:#ffffff;width:100%;border:0px;height:30px"><td></td></tr>
</table>
</div>
<style>
.ffeat: {
color:red
}
.cover {
width: 100%;
margin-bottom: 5pt
}
.highlight-container, .highlight {
position: relative;
text-decoration:none
}
.highlight-container {
display: inline-block;
}
.highlight{
color:white;
text-transform:uppercase;
font-size: 16pt;
}
.highlight-container{
padding:5px 10px
}
.highlight-container:before {
content: " ";
display: block;
height: 100%;
width: 100%;
margin-left: 0px;
margin-right: 0px;
position: absolute;
background: #e80909;
transform: rotate(2deg);
top: -1px;
left: -1px;
border-radius: 20% 25% 20% 24%;
padding: 10px 18px 18px 10px;
}
div.grb, #zastava>table {
position:absolute;
top:0px;
left: 0px;
margin:0px
}
div.grb>img, #zastava>table{
margin:0px
}
#zastava {
position: relative;
margin-bottom:120px
}
p {
font-size:14pt
}
</style> |