Skip to content

Commit

Permalink
Stop asserting key order in bart preprocessor (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdangerw authored Aug 21, 2023
1 parent bab767a commit 22e21af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keras_nlp/models/bart/bart_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_config(self):
def call(self, x, y=None, sample_weight=None):
if not (
isinstance(x, dict)
and ["encoder_text", "decoder_text"] == list(x.keys())
and all(k in x for k in ("encoder_text", "decoder_text"))
):
raise ValueError(
'`x` must be a dictionary, containing the keys `"encoder_text"`'
Expand Down
16 changes: 16 additions & 0 deletions keras_nlp/models/bart/bart_preprocessor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ def test_tokenize_strings(self):
output["decoder_padding_mask"], [1, 1, 1, 1, 1, 1, 1, 1, 0]
)

def test_key_order(self):
self.assertAllClose(
self.preprocessor(
{
"encoder_text": " airplane at airport",
"decoder_text": " kohli is the best",
}
),
self.preprocessor(
{
"decoder_text": " kohli is the best",
"encoder_text": " airplane at airport",
}
),
)

def test_tokenize_list_of_strings(self):
input_data = {
"encoder_text": [" airplane at airport"] * 4,
Expand Down

0 comments on commit 22e21af

Please sign in to comment.