简体   繁体   English

通过正则表达式模式将TF.string分隔为定界符

[英]Split TF.string by regex pattern as delimiter

I want to split string by regex pattern in Tensorflow(TF). 我想在Tensorflow(TF)中按正则表达式模式拆分字符串。 I found tf.string_split() 我发现了tf.string_split()

But, it expects delimiter as string not regex. 但是,它期望定界符为字符串而不是正则表达式。 How to do that in TF 1.2. 如何在TF 1.2中做到这一点。

Code Sample : 代码示例:

data = tf.Variable("aa the boy aaa the boy aaaaa")
data_split = tf.string_split(data, re.compile("a*"))
TypeError: Expected string, got re.compile('.') of type 'SRE_Pattern' instead.

As of august 2017 there is no op in tensorflow to do this, but it's straightforward to implement one by copying the C++ code in StringSplit and editing it. 截至2017年8月,tensorflow中尚无操作可进行此操作,但通过在StringSplit中复制C ++代码并对其进行编辑可以很容易地实现一个操作。 Alternatively you can use tf.py_func to split in python instead of tensorflow. 另外,您可以使用tf.py_func在python中拆分,而不是使用tensorflow。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM