Skip to content

Commit

Permalink
Improve error messages for tokenizer trainers (keras-team#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdangerw authored Jan 13, 2025
1 parent 86607dc commit 6afe94f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions keras_hub/src/tokenizers/sentence_piece_tokenizer_trainer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import io

from keras_hub.src.utils.tensor_utils import assert_tf_libs_installed

try:
import sentencepiece as spm
import tensorflow as tf
Expand Down Expand Up @@ -77,6 +79,7 @@ def compute_sentence_piece_proto(
tf.Tensor([ 4 8 12 5 9 14 5 6 13 4 7 10 11 6 13],
shape=(15,), dtype=int32)
"""
assert_tf_libs_installed("compute_sentence_piece_proto")

if spm is None:
raise ImportError(
Expand Down
3 changes: 3 additions & 0 deletions keras_hub/src/tokenizers/word_piece_tokenizer_trainer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from keras_hub.src.api_export import keras_hub_export
from keras_hub.src.tokenizers.word_piece_tokenizer import pretokenize
from keras_hub.src.utils.tensor_utils import assert_tf_libs_installed

try:
import tensorflow as tf
Expand Down Expand Up @@ -117,6 +118,8 @@ def normalize_and_split(x):
inputs.map(tokenizer.tokenize)
```
""" # noqa: E501
assert_tf_libs_installed("compute_word_piece_vocabulary")

# Read data files.
if not isinstance(data, (list, tf.data.Dataset)):
raise ValueError(
Expand Down

0 comments on commit 6afe94f

Please sign in to comment.