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

Conditionally import tf_text everywhere #684

Merged
merged 1 commit into from
Jan 23, 2023
Merged
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
9 changes: 8 additions & 1 deletion keras_nlp/models/roberta/roberta_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import copy

import tensorflow as tf
import tensorflow_text as tf_text
from tensorflow import keras

from keras_nlp.models.preprocessor import Preprocessor
Expand All @@ -28,6 +27,12 @@
)
from keras_nlp.utils.keras_utils import pack_x_y_sample_weight
from keras_nlp.utils.python_utils import classproperty
from keras_nlp.utils.tf_utils import assert_tf_text_installed

try:
import tensorflow_text as tf_text
except ImportError:
tf_text = None


@keras.utils.register_keras_serializable(package="keras_nlp")
Expand Down Expand Up @@ -236,6 +241,8 @@ def __init__(
truncate="round_robin",
**kwargs,
):
assert_tf_text_installed(self.__class__.__name__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this surface a readable error message? Is this the only place we need to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you search code, we do this in already 8 other places, this is a spot we missed. And yes, this just raises an error, utility so our language could stay consistent.

https://github.com/keras-team/keras-nlp/blob/87019700821662d33d573ce47a1348f44418aa5a/keras_nlp/utils/tf_utils.py#L69-L75


super().__init__(**kwargs)
self.sequence_length = sequence_length
if truncate not in ("round_robin", "waterfall"):
Expand Down