I am saving my tf.keras model with a signature in TF2 to serve it with TFServing. In the signature function I would like to extract some entities with regex expressions.
My input is a Tensor with datatype tf.string. I cannot use numpy() within it, resulting in "Tensor object has no attribute numpy". tf.py_function() is unavailable in TFServing as well.
So I am left with tensorflow operations. How would I extract a substring with a pattern?
@tf.function
def serve_fn(input):
# Returns Today's date is . Tomorrow is another day. But I need 11/2020
output = tf.strings.regex_replace("Today's date is 11/2020. Tomorrow is another day.", pattern=r'[\d]{2}/[\d]{4}', rewrite=" ")
# model inference ...
return {'output': output}
That would return the a tensor with content "Today's date . Tomorrow is another day."
How would a pattern look like, which returns just the date? If I'm not mistaken, tf.strings.regex_replace uses re2 which does not support lookaheads. Are there maybe other solutions?
Thanks in advance