如何在TF.NamedTensorMap中访问数据?

发布于 2025-01-23 12:30:57 字数 370 浏览 0 评论 0原文

我正在学习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.NamedTensorMaps. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤凫 2025-01-30 12:30:57

因此,我似乎到处都在看一些文档来解释tf.NamedTensorMap,但似乎不存在。从对象类中播放方法后,我意识到我可以使用object.getPrototypeof()访问所有方法名称。另外,通过使用object.keys(),我能够在tf.nemedtensormap中委托记录所有属性密钥。所以这就是我发现的。

看来tf.NemedTensorMap.Indicestf.nemedtensormap.valuestf.nemedtensormap.shape.shape.shape具有相同的方法,原因,即使它们持有不同的数据。我假设这是由于某种继承而造成的。无论如何,我能够找到多种方法,可用于从张量中获取数据。即tf.dataSync()tf.Arraysync(),都适用于我的特定场景。

Tensor {
  rank: [Getter],
  buffer: [Function (anonymous)],
  bufferSync: [Function (anonymous)],
  array: [Function (anonymous)],
  arraySync: [Function (anonymous)],
  data: [Function (anonymous)],
  dataToGPU: [Function (anonymous)],
  dataSync: [Function (anonymous)],
  bytes: [Function (anonymous)],
  dispose: [Function (anonymous)],
  isDisposed: [Getter],
  throwIfDisposed: [Function (anonymous)],
  print: [Function (anonymous)],
  clone: [Function (anonymous)],
  toString: [Function (anonymous)],
  cast: [Function (anonymous)],
  variable: [Function (anonymous)],
  abs: [Function (anonymous)],
  acos: [Function (anonymous)],
  acosh: [Function (anonymous)],
  add: [Function (anonymous)],
  all: [Function (anonymous)],
  any: [Function (anonymous)],
  argMax: [Function (anonymous)],
  argMin: [Function (anonymous)],
  asScalar: [Function (anonymous)],
  asType: [Function (anonymous)],
  as1D: [Function (anonymous)],
  as2D: [Function (anonymous)],
  as3D: [Function (anonymous)],
  as4D: [Function (anonymous)],
  as5D: [Function (anonymous)],
  asin: [Function (anonymous)],
  asinh: [Function (anonymous)],
  atan: [Function (anonymous)],
  atan2: [Function (anonymous)],
  atanh: [Function (anonymous)],
  avgPool: [Function (anonymous)],
  batchToSpaceND: [Function (anonymous)],
  batchNorm: [Function (anonymous)],
  broadcastTo: [Function (anonymous)],
  ceil: [Function (anonymous)],
  clipByValue: [Function (anonymous)],
  concat: [Function (anonymous)],
  conv1d: [Function (anonymous)],
  conv2dTranspose: [Function (anonymous)],
  conv2d: [Function (anonymous)],
  cos: [Function (anonymous)],
  cosh: [Function (anonymous)],
  cumprod: [Function (anonymous)],
  cumsum: [Function (anonymous)],
  depthToSpace: [Function (anonymous)],
  depthwiseConv2d: [Function (anonymous)],
  dilation2d: [Function (anonymous)],
  divNoNan: [Function (anonymous)],
  div: [Function (anonymous)],
  dot: [Function (anonymous)],
  elu: [Function (anonymous)],
  equal: [Function (anonymous)],
  erf: [Function (anonymous)],
  exp: [Function (anonymous)],
  expandDims: [Function (anonymous)],
  expm1: [Function (anonymous)],
  fft: [Function (anonymous)],
  flatten: [Function (anonymous)],
  floor: [Function (anonymous)],
  floorDiv: [Function (anonymous)],
  gather: [Function (anonymous)],
  greaterEqual: [Function (anonymous)],
  greater: [Function (anonymous)],
  ifft: [Function (anonymous)],
  irfft: [Function (anonymous)],
  isFinite: [Function (anonymous)],
  isInf: [Function (anonymous)],
  isNaN: [Function (anonymous)],
  leakyRelu: [Function (anonymous)],
  lessEqual: [Function (anonymous)],
  less: [Function (anonymous)],
  localResponseNormalization: [Function (anonymous)],
  logSigmoid: [Function (anonymous)],
  logSoftmax: [Function (anonymous)],
  logSumExp: [Function (anonymous)],
  log: [Function (anonymous)],
  log1p: [Function (anonymous)],
  logicalAnd: [Function (anonymous)],
  logicalNot: [Function (anonymous)],
  logicalOr: [Function (anonymous)],
  logicalXor: [Function (anonymous)],
  matMul: [Function (anonymous)],
  maxPool: [Function (anonymous)],
  max: [Function (anonymous)],
  maximum: [Function (anonymous)],
  mean: [Function (anonymous)],
  min: [Function (anonymous)],
  minimum: [Function (anonymous)],
  mirrorPad: [Function (anonymous)],
  mod: [Function (anonymous)],
  mul: [Function (anonymous)],
  neg: [Function (anonymous)],
  norm: [Function (anonymous)],
  notEqual: [Function (anonymous)],
  oneHot: [Function (anonymous)],
  onesLike: [Function (anonymous)],
  pad: [Function (anonymous)],
  pool: [Function (anonymous)],
  pow: [Function (anonymous)],
  prelu: [Function (anonymous)],
  prod: [Function (anonymous)],
  reciprocal: [Function (anonymous)],
  relu: [Function (anonymous)],
  relu6: [Function (anonymous)],
  reshapeAs: [Function (anonymous)],
  reshape: [Function (anonymous)],
  resizeBilinear: [Function (anonymous)],
  resizeNearestNeighbor: [Function (anonymous)],
  reverse: [Function (anonymous)],
  rfft: [Function (anonymous)],
  round: [Function (anonymous)],
  rsqrt: [Function (anonymous)],
  selu: [Function (anonymous)],
  separableConv2d: [Function (anonymous)],
  sigmoid: [Function (anonymous)],
  sign: [Function (anonymous)],
  sin: [Function (anonymous)],
  sinh: [Function (anonymous)],
  slice: [Function (anonymous)],
  softmax: [Function (anonymous)],
  softplus: [Function (anonymous)],
  spaceToBatchND: [Function (anonymous)],
  split: [Function (anonymous)],
  sqrt: [Function (anonymous)],
  square: [Function (anonymous)],
  squaredDifference: [Function (anonymous)],
  squeeze: [Function (anonymous)],
  stack: [Function (anonymous)],
  step: [Function (anonymous)],
  stridedSlice: [Function (anonymous)],
  sub: [Function (anonymous)],
  sum: [Function (anonymous)],
  tan: [Function (anonymous)],
  tanh: [Function (anonymous)],
  tile: [Function (anonymous)],
  toBool: [Function (anonymous)],
  toFloat: [Function (anonymous)],
  toInt: [Function (anonymous)],
  topk: [Function (anonymous)],
  transpose: [Function (anonymous)],
  unique: [Function (anonymous)],
  unsortedSegmentSum: [Function (anonymous)],
  unstack: [Function (anonymous)],
  where: [Function (anonymous)],
  zerosLike: [Function (anonymous)]
}

由于张量的工作方式,如果我现在了解它们,试图制作包含张量的张量是一个坏主意,甚至可能行不通(我必须测试一个)。因此,如果您的数据像我正在使用的数据一样,您需要在数据集中的较低级别上拆分数据,则使用基本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 the Object class, I realized I could access all of the method names by using Object.getPrototypeOf(). Also, by using Object.keys(), I was able to console log all of the property keys in tf.NamedTensorMap. So here is what I found.

It seems that each of tf.NamedTensorMap.indices, tf.NamedTensorMap.values, and tf.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. Namely tf.dataSync() and tf.arraySync() which both work for my specific scenario.

Tensor {
  rank: [Getter],
  buffer: [Function (anonymous)],
  bufferSync: [Function (anonymous)],
  array: [Function (anonymous)],
  arraySync: [Function (anonymous)],
  data: [Function (anonymous)],
  dataToGPU: [Function (anonymous)],
  dataSync: [Function (anonymous)],
  bytes: [Function (anonymous)],
  dispose: [Function (anonymous)],
  isDisposed: [Getter],
  throwIfDisposed: [Function (anonymous)],
  print: [Function (anonymous)],
  clone: [Function (anonymous)],
  toString: [Function (anonymous)],
  cast: [Function (anonymous)],
  variable: [Function (anonymous)],
  abs: [Function (anonymous)],
  acos: [Function (anonymous)],
  acosh: [Function (anonymous)],
  add: [Function (anonymous)],
  all: [Function (anonymous)],
  any: [Function (anonymous)],
  argMax: [Function (anonymous)],
  argMin: [Function (anonymous)],
  asScalar: [Function (anonymous)],
  asType: [Function (anonymous)],
  as1D: [Function (anonymous)],
  as2D: [Function (anonymous)],
  as3D: [Function (anonymous)],
  as4D: [Function (anonymous)],
  as5D: [Function (anonymous)],
  asin: [Function (anonymous)],
  asinh: [Function (anonymous)],
  atan: [Function (anonymous)],
  atan2: [Function (anonymous)],
  atanh: [Function (anonymous)],
  avgPool: [Function (anonymous)],
  batchToSpaceND: [Function (anonymous)],
  batchNorm: [Function (anonymous)],
  broadcastTo: [Function (anonymous)],
  ceil: [Function (anonymous)],
  clipByValue: [Function (anonymous)],
  concat: [Function (anonymous)],
  conv1d: [Function (anonymous)],
  conv2dTranspose: [Function (anonymous)],
  conv2d: [Function (anonymous)],
  cos: [Function (anonymous)],
  cosh: [Function (anonymous)],
  cumprod: [Function (anonymous)],
  cumsum: [Function (anonymous)],
  depthToSpace: [Function (anonymous)],
  depthwiseConv2d: [Function (anonymous)],
  dilation2d: [Function (anonymous)],
  divNoNan: [Function (anonymous)],
  div: [Function (anonymous)],
  dot: [Function (anonymous)],
  elu: [Function (anonymous)],
  equal: [Function (anonymous)],
  erf: [Function (anonymous)],
  exp: [Function (anonymous)],
  expandDims: [Function (anonymous)],
  expm1: [Function (anonymous)],
  fft: [Function (anonymous)],
  flatten: [Function (anonymous)],
  floor: [Function (anonymous)],
  floorDiv: [Function (anonymous)],
  gather: [Function (anonymous)],
  greaterEqual: [Function (anonymous)],
  greater: [Function (anonymous)],
  ifft: [Function (anonymous)],
  irfft: [Function (anonymous)],
  isFinite: [Function (anonymous)],
  isInf: [Function (anonymous)],
  isNaN: [Function (anonymous)],
  leakyRelu: [Function (anonymous)],
  lessEqual: [Function (anonymous)],
  less: [Function (anonymous)],
  localResponseNormalization: [Function (anonymous)],
  logSigmoid: [Function (anonymous)],
  logSoftmax: [Function (anonymous)],
  logSumExp: [Function (anonymous)],
  log: [Function (anonymous)],
  log1p: [Function (anonymous)],
  logicalAnd: [Function (anonymous)],
  logicalNot: [Function (anonymous)],
  logicalOr: [Function (anonymous)],
  logicalXor: [Function (anonymous)],
  matMul: [Function (anonymous)],
  maxPool: [Function (anonymous)],
  max: [Function (anonymous)],
  maximum: [Function (anonymous)],
  mean: [Function (anonymous)],
  min: [Function (anonymous)],
  minimum: [Function (anonymous)],
  mirrorPad: [Function (anonymous)],
  mod: [Function (anonymous)],
  mul: [Function (anonymous)],
  neg: [Function (anonymous)],
  norm: [Function (anonymous)],
  notEqual: [Function (anonymous)],
  oneHot: [Function (anonymous)],
  onesLike: [Function (anonymous)],
  pad: [Function (anonymous)],
  pool: [Function (anonymous)],
  pow: [Function (anonymous)],
  prelu: [Function (anonymous)],
  prod: [Function (anonymous)],
  reciprocal: [Function (anonymous)],
  relu: [Function (anonymous)],
  relu6: [Function (anonymous)],
  reshapeAs: [Function (anonymous)],
  reshape: [Function (anonymous)],
  resizeBilinear: [Function (anonymous)],
  resizeNearestNeighbor: [Function (anonymous)],
  reverse: [Function (anonymous)],
  rfft: [Function (anonymous)],
  round: [Function (anonymous)],
  rsqrt: [Function (anonymous)],
  selu: [Function (anonymous)],
  separableConv2d: [Function (anonymous)],
  sigmoid: [Function (anonymous)],
  sign: [Function (anonymous)],
  sin: [Function (anonymous)],
  sinh: [Function (anonymous)],
  slice: [Function (anonymous)],
  softmax: [Function (anonymous)],
  softplus: [Function (anonymous)],
  spaceToBatchND: [Function (anonymous)],
  split: [Function (anonymous)],
  sqrt: [Function (anonymous)],
  square: [Function (anonymous)],
  squaredDifference: [Function (anonymous)],
  squeeze: [Function (anonymous)],
  stack: [Function (anonymous)],
  step: [Function (anonymous)],
  stridedSlice: [Function (anonymous)],
  sub: [Function (anonymous)],
  sum: [Function (anonymous)],
  tan: [Function (anonymous)],
  tanh: [Function (anonymous)],
  tile: [Function (anonymous)],
  toBool: [Function (anonymous)],
  toFloat: [Function (anonymous)],
  toInt: [Function (anonymous)],
  topk: [Function (anonymous)],
  transpose: [Function (anonymous)],
  unique: [Function (anonymous)],
  unsortedSegmentSum: [Function (anonymous)],
  unstack: [Function (anonymous)],
  where: [Function (anonymous)],
  zerosLike: [Function (anonymous)]
}

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文