mideind / Tokenizer

A tokenizer for Icelandic text
Other
27 stars 6 forks source link

split_into_sentences changes sentences #24

Closed bnika closed 2 years ago

bnika commented 3 years ago

It would be helpful to have a version of split_into_sentences that does only that and does not touch the sentences in any other way. Two examples:

input: Faxaflói Suðlæg átt , 5 - 10 m/s , él og hiti kringum frostmark .
output: Faxaflói Suðlæg átt , 5 - 10 m / s , él og hiti kringum frostmark . # adding spaces around '/'

input: Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52 .
output: Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64 - 52 . # adding spaces around '-'
vthorsteinsson commented 3 years ago

Splitting up m/s is a legitimate bug, this should be handled as a measurement unit and thus as a single token. We will look into that.

The other case is different - there the hyphen is an independent token that has semantic meaning. So squeezing out the spaces around the hyphen token would require a different approach, either via a different pipe on our end or via some minimal post-processing on your end.

Have you tried taking the shallow-tokenized sentence strings and calling correct_spaces() on them? That pretty much restores original (or at least canonical/normalized) spacing. Would that be enough for your use case?

bnika commented 3 years ago

I haven't look into what the sentence splitter does exactly, but my first expectation would be that it only splits a text into sentences and doesn't care about tokens in that run. Here a few examples, adding correct_spaces(). Correct spaces does not really help regarding the original issue, because if the original text e.g. contains spaces around '-' , they will be deleted. Also note the corruption of the time tokens in the third example:

input: Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64 - 52 .
sent. split: Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64 - 52 .
correct spaces: Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52 .

input: Q4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981 .
sent. split: Q 4U er íslensk pönkhljómsveit , sem stofnuð var veturinn 1980 - 1981 .
correct spaces: Q 4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981.

input: Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00-18:00 .
sent. split: Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00 - 18:00 .
correct spaces: Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17: 00-18: 00.

My concern is less about what is correct in terms of tokenization, but more about predictability, that when I only want the text split into sentences, that I can count on that the sentences are still identical to the ones in the original text, and that I don't have to know about token definitions of the sentence splitter. But I understand that if the token processing is deeply anchored in the sentence splitter, that this is may not be a feasible option right now.

Holado commented 3 years ago

We are expecting a large update of the tokenizer soon, after that we'll look into this. The plan is to add some toggles, including some to prevent unwanted changes to the original sentence.

Holado commented 3 years ago

Regarding the "m/s" splitting, we've updated the Tokenizer so it handles such cases. The case of predictability and untouched sentences is still on the todo list, after we finish that large update I mentioned.

Holado commented 3 years ago

The optional argument -o has been added to the Tokenizer. This allows split_into_sentences() to return the original sentences.

The results can be seen below. This is the output of a simple program with and without the argument. Orig is the original input text. Split is each sentence returned from split_into_sentences(). CorrSp is the corrects_spaces() version of Split.

python tester.py -o Orig|||Faxaflói Suðlæg átt , 5 - 10 m/s , él og hiti kringum frostmark . Split||Faxaflói Suðlæg átt , 5 - 10 m/s , él og hiti kringum frostmark . CorrSp|Faxaflói Suðlæg átt, 5-10 m/s, él og hiti kringum frostmark.

Orig|||Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52 . Split||Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52 . CorrSp|Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52.

Orig|||Q4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981 . Split||Q4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981 . CorrSp|Q4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981.

Orig|||Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00-18:00 . Split||Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00-18:00 . CorrSp|Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17: 00-18: 00.

python tester.py Orig|||Faxaflói Suðlæg átt , 5 - 10 m/s , él og hiti kringum frostmark . Split||Faxaflói Suðlæg átt , 5 - 10 m/s , él og hiti kringum frostmark . CorrSp|Faxaflói Suðlæg átt, 5-10 m/s, él og hiti kringum frostmark.

Orig|||Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52 . Split||Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64 - 52 . CorrSp|Áfram hélt fjörið í síðari hálfleik og þegar 3. leikhluti var tæplega hálfnaður var staðan 64-52.

Orig|||Q4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981 . Split||Q 4U er íslensk pönkhljómsveit , sem stofnuð var veturinn 1980 - 1981 . CorrSp|Q 4U er íslensk pönkhljómsveit, sem stofnuð var veturinn 1980-1981.

Orig|||Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00-18:00 . Split||Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17:00 - 18:00 . CorrSp|Starfið verður í Kiwanishúsinu að Heiðartúni 4 alla þriðjudaga í vetur kl. 17: 00-18: 00.

HaukurPall commented 3 years ago

Will this be included in version 3.1.0?

Holado commented 3 years ago

Yes, it will be.