File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 3333 from keras_nlp .layers import StartEndPacker
3434except ImportError :
3535 keras_nlp = None
36+ StartEndPacker = None
3637
3738
3839@keras_cv_export ("keras_cv.models.feature_extractor.CLIPProcessor" )
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414import regex as re
1515import tensorflow as tf
16- import tensorflow_text as tf_text
16+
17+ try :
18+ import tensorflow_text as tf_text
19+ except ImportError :
20+ tf_text = None
1721
1822try :
1923 import keras_nlp
2024 from keras_nlp .tokenizers import BytePairTokenizer
2125except ImportError :
2226 keras_nlp = None
27+ BytePairTokenizer = object
2328
2429# As python and TF handles special spaces differently, we need to
2530# manually handle special spaces during string split.
@@ -41,6 +46,11 @@ def split_strings_for_bpe(inputs, unsplittable_tokens=None):
4146 # support lookahead match, we are using an alternative insert a special
4247 # token "६" before leading space of non-space characters and after the
4348 # trailing space, e.g., " keras" will be "६ keras".
49+ if tf_text is None :
50+ raise ImportError (
51+ "BytePairTokenization requires `tensorflow_text`."
52+ "Please install with `pip install tensorflow_text`."
53+ )
4454 inputs = tf .strings .regex_replace (
4555 inputs , rf"( )([^\s{ SPECIAL_WHITESPACES } ])" , r"६\1\2"
4656 )
You can’t perform that action at this time.
0 commit comments