def test_one_hot_encoder_deserialize_transforms_to_np(): encoder = encoders.OneHotEncoder(["a", "b", "c"]) encoder.fit(np.array(["a", "b", "a"])) encoder = preprocessors.deserialize(preprocessors.serialize(encoder)) one_hot = encoder.transform( tf.data.Dataset.from_tensor_slices([["a"], ["c"], ["b"]]).batch(2)) for data in one_hot: assert data.shape[1:] == [3]
def test_one_hot_encoder_decode_to_same_string(): encoder = encoders.OneHotEncoder(["a", "b", "c"]) result = encoder.postprocess(np.eye(3)) assert np.array_equal(result, np.array([["a"], ["b"], ["c"]]))