如何在TF.NamedTensorMap中访问数据?
我正在学习TensorFlow.js,并且遇到了一个问题。因此,我正在使用的数据是破烂的字符串向量。我已经使用tf.string.stringsplit()
对数据进行了标记,但是我现在很难访问数据。我可以调用split.values.print()
获取张量摘要的控制台日志,但是我不知道如何直接访问值。我找不到有关tf.namedTensorMap
s的文档。我想在张量中以数个数组的形式获得拆分值。
const sentence = tf.string.stringSplit(['Hello , World !'], ' ')
console.log(sentence.values)
I'm learning Tensorflow.js and I've ran into a problem. So, the data I'm using are ragged string vectors. I've tokenized the data using tf.string.stringSplit()
, but I'm having trouble accessing the data now. I can call split.values.print()
to get a console log of a summary of values in the tensor, but I can't figure out how to access the values directly. There's no documentation I could find about tf.NamedTensorMap
s. I'd like to get the split values in the tensor as an array.
const sentence = tf.string.stringSplit(['Hello , World !'], ' ')
console.log(sentence.values)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我似乎到处都在看一些文档来解释
tf.NamedTensorMap
,但似乎不存在。从对象
类中播放方法后,我意识到我可以使用object.getPrototypeof()
访问所有方法名称。另外,通过使用object.keys()
,我能够在tf.nemedtensormap
中委托记录所有属性密钥。所以这就是我发现的。看来
tf.NemedTensorMap.Indices
,tf.nemedtensormap.values
和tf.nemedtensormap.shape.shape.shape
具有相同的方法,原因,即使它们持有不同的数据。我假设这是由于某种继承而造成的。无论如何,我能够找到多种方法,可用于从张量中获取数据。即tf.dataSync()
和tf.Arraysync()
,都适用于我的特定场景。由于张量的工作方式,如果我现在了解它们,试图制作包含张量的张量是一个坏主意,甚至可能行不通(我必须测试一个)。因此,如果您的数据像我正在使用的数据一样,您需要在数据集中的较低级别上拆分数据,则使用基本
string.split()
可能会更好。So, I've looked seemingly everywhere for some documentation to explain
tf.NamedTensorMap
, but it doesn't seem to exist. After playing around with methods from theObject
class, I realized I could access all of the method names by usingObject.getPrototypeOf()
. Also, by usingObject.keys()
, I was able to console log all of the property keys intf.NamedTensorMap
. So here is what I found.It seems that each of
tf.NamedTensorMap.indices
,tf.NamedTensorMap.values
, andtf.NamedTensorMap.shape
have the same methods for some reason even though they hold different data. I'm assuming it's due to some inheritance. Anyway, I was able to locate multiple methods which can be used to get the data from the tensor. Namelytf.dataSync()
andtf.arraySync()
which both work for my specific scenario.Because of how tensors work, if I understand them now, attempting to make a tensor that contains tensors is a bad idea and it may not even work (I'd have to test that one out). So, if your data is anything like the data I'm using and you need to split your data at a lower level in your dataset, it's likely much better to use the basic
string.split()
.