Clarify error messages in case of invalid vocabulary format for index lookup layers.
PiperOrigin-RevId: 342962819
Change-Id: Ib662699aef1c285684288457596c2a00997d7d06
diff --git a/tensorflow/python/keras/layers/preprocessing/index_lookup.py b/tensorflow/python/keras/layers/preprocessing/index_lookup.py
index 1d4d617..cfe300b 100644
--- a/tensorflow/python/keras/layers/preprocessing/index_lookup.py
+++ b/tensorflow/python/keras/layers/preprocessing/index_lookup.py
@@ -248,21 +248,29 @@
has_oov = False
if all([should_have_mask, has_mask, should_have_oov]) and not has_oov:
- raise ValueError("The passed vocabulary has the correct mask token `%s` "
+ raise ValueError("Invalid vocabulary format. The layer was created with "
+ "`mask_token=%s` and `oov_token=%s`. These tokens should"
+ " be included in the provided vocabulary. "
+ "The passed vocabulary has the correct mask token `%s` "
"at index 0, but does not have the OOV token `%s` in "
"indices [%s:%s]. Instead, we found `%s`. Was this "
"vocabulary generated by a layer with incompatible "
"settings?" %
- (self.mask_token, self.oov_token, oov_start, oov_end,
+ (self.mask_token, self.oov_token,
+ self.mask_token, self.oov_token, oov_start, oov_end,
vocab[oov_start:oov_end]))
if all([should_have_oov, has_oov, should_have_mask]) and not has_mask:
raise ValueError(
+ "Invalid vocabulary format. The layer was created with "
+ "`mask_token=%s` and `oov_token=%s`. These tokens should "
+ "be included in the provided vocabulary. "
"The passed vocabulary has the correct OOV token `%s` at "
"indices [%s:%s], but does not have the mask token `%s` in "
"index 0. Instead, we found `%s`. Was this vocabulary "
"generated by a layer with incompatible settings?" %
- (self.oov_token, oov_start, oov_end, self.mask_token, vocab[0]))
+ (self.mask_token, self.oov_token, self.oov_token,
+ oov_start, oov_end, self.mask_token, vocab[0]))
insert_special_tokens = not has_oov and not has_mask