razdel -RULE-BASED SYSTEM For Russian Sentence and Word Tokenization.
> >> from razdel import tokenize
> >> tokens = list ( tokenize ( 'Кружка-термос на 0.5л (50/64 см³, 516;...)' ))
> >> tokens
[ Substring ( 0 , 13 , 'Кружка-термос' ),
Substring ( 14 , 16 , 'на' ),
Substring ( 17 , 20 , '0.5' ),
Substring ( 20 , 21 , 'л' ),
Substring ( 22 , 23 , '(' )
...]
>> > [ _ . text for _ in tokens ]
[ 'Кружка-термос' , 'на' , '0.5' , 'л' , '(' , '50/64' , 'см³' , ',' , '516' , ';' , '...' , ')' ] > >> from razdel import sentenize
> >> text = '''
... - "Так в чем же дело?" - "Не ра-ду-ют".
... И т. д. и т. п. В общем, вся газета
... '''
> >> list ( sentenize ( text ))
[ Substring ( 1 , 23 , '- "Так в чем же дело?"' ),
Substring ( 24 , 40 , '- "Не ра-ду-ют".' ),
Substring ( 41 , 56 , 'И т. д. и т. п.' ),
Substring ( 57 , 76 , 'В общем, вся газета' )] razdel Supports Python 3.7+ and Pypy 3.
$ pip install razdelMaterials are in Russian:
UNFORTUNATELY, the IS No Single Correct Way to Split Text Into Sentences and Tokens. For Example, One May Split «Как же так?! Захар...» — воскликнут Пронин. Into Three Sentences ["«Как же так?!", "Захар...»", "— воскликнут Пронин."] While razdel splits it into two ["«Как же так?!", "Захар...» — воскликнут Пронин."] . What Woup Be the Correct Way to Tokenizer т.е. ? One May Split in Into т.|е. , razdel Splits Into т|.|е|. .
razdel Tries to Mimic Segtion of these 4 Datasets: Syntagrus, Opencorpora, Gicrya and Rnc. These Datasets Mainly Consist of News and Fiction. razdel Rules are Optimized for Th, Kinds of Texts. Library May Perform Worse on Otomains Like Social Media, Scientific Articles, Legal Documents.
We Measure Absolute Number of Errors. There Are a Lot of Trivial Cases in the Tokenization Task. For example, Text чуть-чуть?! IS not non-travial, one may split it into чуть|-|чуть|?|! While The Correct Tokenization is чуть-чуть|?! , Such Examples Are Rare. VAST Majority of Cases Are Trivial, For Example Text в 5 часов ... is Correctly Tokenized Even Via Python Native str.split Into в| |5| |часов| |... Due to the Large Number of Trivial Case Overall Quality of All Segmenators Is High, Its Hard to Compare Differentate Between for Examlpe 99.33%, 99.95%and 99.88%, and 99.8%, and 99.8%, so we report the absolute number of errors.
errors - Number of Errors Per 1000 Tokens/Sentencies. For Example, Consider Etalon Segtion is что-то|? , Prediction is что|-|то? , The Number of Errors is 3: 1 for Missing Split то? + 2 For Extra Splits что|-|то .
time - Seconds Taken to Process Whole Datase.
spacy_tokenize , aatimofeev and Others a Defined in Naeval/Segment/Models.py, For Links to Models See Naeval Registry. Tables Are Computed in Naeval/Segment/Main.ipynb.
| Corpora | Syntag | Gicrya | RNC | |||||
|---|---|---|---|---|---|---|---|---|
| Errors | Time | Errors | Time | Errors | Time | Errors | Time | |
| Re.findall ( w+| d+| p+) | 24 | 0.5 | 16 | 0.5 | 19 | 0.4 | 60 | 0.4 |
| Space | 26 | 6.2 | 13 | 5.8 | 14 | 4.1 | 32 | 3.9 |
| nltk.word_tokenize | 60 | 3.4 | 256 | 3.3 | 75 | 2.7 | 199 | 2.9 |
| Mystem | 23 | 5.0 | 15 | 4.7 | 19 | 3.7 | 14 | 3.9 |
| Mosestokenizer | 11 | 2.1 | 8 | 1.9 | 15 | 1.6 | 16 | 1.7 |
| Segtok.word_tokenize | 16 | 2.3 | 8 | 2.3 | 14 | 1.8 | 9 | 1.8 |
| Aatimofeev/Space_russian_tokenizer | 17 | 48.7 | 4 | 51.1 | 5 | 39.5 | 20 | 52.2 |
| Koziev/Rutokenizer | 15 | 1.1 | 8 | 1.0 | 23 | 0.8 | 68 | 0.9 |
| razdel.tokenize | 9 | 2.9 | 9 | 2.8 | 3 | 2.0 | 16 | 2.2 |
| Corpora | Syntag | Gicrya | RNC | |||||
|---|---|---|---|---|---|---|---|---|
| Errors | Time | Errors | Time | Errors | Time | Errors | Time | |
| Re.split ([.?! ...]) | 114 | 0.9 | 53 | 0.6 | 63 | 0.7 | 130 | 1.0 |
| segtok.split_single | 106 | 17.8 | 36 | 13.4 | 1001 | 1.1 | 912 | 2.8 |
| Mosestokenizer | 238 | 8.9 | 182 | 5.7 | 80 | 6.4 | 287 | 7.4 |
| nltk.sent_tokenize | 92 | 10.1 | 36 | 5.3 | 44 | 5.6 | 183 | 8.9 |
| Deeppavlov/Rusenttokenize | 57 | 10.9 | 10 | 7.9 | 56 | 6.8 | 119 | 7.0 |
| razdel.Sentenize | 52 | 6.1 | 7 | 3.9 | 72 | 4.5 | 59 | 7.5 |
DEV ENV
python -m venv ~ /.venvs/natasha-razdel
source ~ /.venvs/natasha-razdel/bin/activate
pip install -r requirements/dev.txt
pip install -e .Test
make test
make int # 2000 integration testsRelease
# Update setup.py version
git commit -am ' Up version '
git tag v0.5.0
git push
git push --tags mystem errors on syntag
# see naeval/data
cat syntag_tokens.txt | razdel-ctl sample 1000 | razdel-ctl gen | razdel-ctl diff --show moses_tokenize | lessNon-travial token tests
pv data/ * _tokens.txt | razdel-ctl gen --recall | razdel-ctl diff space_tokenize > tests.txt
pv data/ * _tokens.txt | razdel-ctl gen --precision | razdel-ctl diff re_tokenize >> tests.txtUpdate Integration Tests
cd tests/data/
pv sents.txt | razdel-ctl up sentenize > t ; mv t sents.txt razdel and moses Diff
cat data/ * _tokens.txt | razdel-ctl sample 1000 | razdel-ctl gen | razdel-ctl up tokenize | razdel-ctl diff moses_tokenize | less razdel Performance
cat data/ * _tokens.txt | razdel-ctl sample 10000 | pv -l | razdel-ctl gen | razdel-ctl diff tokenize | wc -l