将字符串张量转换为小写 [英] Convert string tensor to lower case

查看:43
本文介绍了将字符串张量转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将字符串张量转换为小写,而无需在会话中进行评估?某种 tf.string_to_lower op ?

Is there any way to convert a string tensor to lower case, without evaluating in the session ? Some sort of tf.string_to_lower op ?

更具体地说,我正在从 tfrecords 文件中读取数据,因此我的数据由张量组成.然后我想使用 tf.contrib.lookup.index_table_from_* 来查找数据中单词的索引,我需要它不区分大小写.在将数据写入 tfrecords 之前降低数据不是一种选择,因为它需要保持原始格式.一种选择是存储原始的和降低的,但如果可能,我想避免这种情况.

More specifically, I am reading data from tfrecords files, so my data is made of tensors. I then want to use tf.contrib.lookup.index_table_from_* to lookup indices for words in the data, and I need this to be case-insensitive. Lowering the data before writing it to tfrecords is not an option, as it needs to be kept in original format. One option would be to store both original and lowered, but I'd like to avoid this if possible.

推荐答案

在 Tensorflow 1.14 中,添加了一个较低的操作.一个简短的代码片段(在急切执行模式下)如下所示:

In Tensorflow 1.14, a lower op has been added. A short code snippet (in eager execution mode) looks like the following:

astring = tf.constant('A String', dtype=tf.string)
tf.strings.lower(astring)

<tf.Tensor: id=79, shape=(), dtype=string, numpy=b'a string'>

这篇关于将字符串张量转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆