Skip to content

Now we don't add extra space token at the beginning of the sequence #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "youtokentome"
version = "1.0.8"
version = "1.0.9"
description = "FL version of YTTM"
license = "MIT"
authors = ["Ivan Belonogov"]
Expand Down
3 changes: 0 additions & 3 deletions tests/unit_tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def test_decode():
)

with open("decode_text_out.txt", "r") as fin:
fin.readline()
text_out = fin.readline()

assert text_in == text_out[:-1]
Expand Down Expand Up @@ -224,8 +223,6 @@ def test_decode():
)

with open("decode_text_out.txt", "r") as fin:
# It is necessary to skip the first line, since everything in BPE starts from a new line
fin.readline()
text_out = fin.readline()

assert text_in == text_out[:-1]
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_english():
chronocoulometry
"""

test_text = "chronocline synchroscope "
test_text = "chronocline synchroscope \n"

TRAIN_DATA_PATH = "train_data.txt"
MODEL_PATH = "model.yttm"
Expand All @@ -48,7 +48,7 @@ def test_english():
model = yttm.BPE.train(TRAIN_DATA_PATH, MODEL_PATH, 200, n_threads=1)
tokenized_text = model.encode([test_text], output_type=yttm.OutputType.SUBWORD)
expected_result = [
["\n", "chrono", "c", "l", "i", "n", "e", " ", "s", "y", "n", "ch", "r", "o", "s", "co", "p", "e", " "]
["chrono", "c", "l", "i", "n", "e", " ", "s", "y", "n", "ch", "r", "o", "s", "co", "p", "e", " ", "\n"]
]
assert tokenized_text == expected_result
print(tokenized_text)
Expand All @@ -73,7 +73,7 @@ def test_japanese():
model = yttm.BPE.train(TRAIN_DATA_PATH, MODEL_PATH, 100)
tokenized_text = model.encode([test_text], output_type=yttm.OutputType.SUBWORD)
expected_result = [
["\n", " ", "おばあさん ", "が", " ", "川", " ", "で", " ", "せ", "ん", " "]
[" ", "おばあさん ", "が", " ", "川", " ", "で", " ", "せ", "ん", " "]
]
assert tokenized_text == expected_result
print(tokenized_text)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_encode_decode():
text_in = [" ".join("".join([random.choice("abcd ") for _ in range(50)]).split())]
ids = bpe.encode(text_in, yttm.OutputType.ID)
# It is necessary to add first empty line, since everything in BPE starts from a new line
text_in[0] = "\n" + text_in[0]
text_in[0] = text_in[0]
assert text_in == bpe.decode(ids)
ids_bos_eos = bpe.encode(text_in, yttm.OutputType.ID, bos=True, eos=True)
assert text_in == bpe.decode(ids_bos_eos, ignore_ids=[BOS_ID, EOS_ID])
Expand Down
4 changes: 3 additions & 1 deletion youtokentome/cpp/bpe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,10 +1539,12 @@ DecodeResult BaseEncoder::encode_sentence(const std::string &sentence_utf8,

auto begin_of_word = std::find_if_not(it_text, text.end(), is_space);
auto end_of_word = std::find_if(begin_of_word, text.end(), is_space);
if (begin_of_word != it_text) {
list.emplace_back(bpe_state.char2id.at(SPACE_TOKEN), 0);
}
it_text = end_of_word;

uint32_t new_token_cur = new_tokens_start;
list.emplace_back(bpe_state.char2id.at(SPACE_TOKEN), 0);

for (auto it_char_in_word = begin_of_word; it_char_in_word < end_of_word;) {
if (bpe_state.char2id.count(*it_char_in_word) == 0) {
Expand Down