Feature request: Modify `text.regex_split_with_offsets()` behavior to be in line with `tf.strings.length()`
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 379
- Avg merge
- 3h 30m
- Merged PRs (30d)
- 8
Description
text.regex_split_with_offsets() currently returns begin and end as tf.int64 tensors that count indices in bytes.
tf.strings.length() on the other hand, returns a tf.int32 tensor which counts lengths in either bytes or UTF8 characters according to the value of the parameter unit.
So this would actually be two separate requests:
- Change the return types of
text.regex_split_with_offsets()totf.int32, removing the need for a cast when comparing withtf.strings.length(). I doubt there will be a use case for strings longer than INT32_MAX in the foreseeable future. - Add parameter
unit: Literal["BYTE", "UTF8_CHAR"] = "BYTE"matching the behavior oftf.strings.length()andtf.strings.substr(). Seeing the regular expressions are already being interpreted in 'utf-8', I think it would make sense to add a layer of abstraction to facilitate slicing by UTF-8 character index.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the text.regex_split_with_offsets() API and compare its documented offsets with tf.strings.length() and tf.strings.substr(), especially their BYTE and UTF8_CHAR behavior. Trace the implementation and existing tests for the split operation; done means the offsets use the requested unit and return tf.int32 values consistently with the related TensorFlow string APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, tensorflow
- Domain
- api, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100