Skip to content
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

Fix empty strings as output of whitespace tokenizer #6143

Merged
merged 7 commits into from
Jul 6, 2020
Merged
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
1 change: 1 addition & 0 deletions changelog/6143.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent ``WhitespaceTokenizer`` from outputting empty list of tokens.
6 changes: 3 additions & 3 deletions rasa/nlu/tokenizers/whitespace_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def tokenize(self, message: Message, attribute: Text) -> List[Token]:
text,
).split()

words = [self.remove_emoji(w) for w in words]
words = [w for w in words if w]

# if we removed everything like smiles `:)`, use the whole text as 1 token
if not words:
words = [text]

words = [self.remove_emoji(w) for w in words]
words = [w for w in words if w]

return self._convert_words_to_tokens(words, text)
1 change: 1 addition & 0 deletions tests/nlu/tokenizers/test_whitespace_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
),
(":)", [":)"], [(0, 2)]),
("Hi :-)", ["Hi"], [(0, 2)]),
("👍", ["👍"], [(0, 1)]),
],
)
def test_whitespace(text, expected_tokens, expected_indices):
Expand Down