【问题标题】:How to convert list of tuple (tf.constant, tf.constant) as tensorflow dataset?如何将元组列表(tf.constant,tf.constant)转换为张量流数据集?
【发布时间】:2020-05-13 17:14:44
【问题描述】:

我正在尝试创建一个 Transformer 模型,我有 2 个np.arrays,都有字符串,我用它们来创建一个元组列表

元组的格式是:

class 'tuple' (tf.Tensor: shape=(), dtype=string, numpy=b'abc', tf.Tensor: shape=(), dtype=string, numpy=b'xyz')

我想将这些元组组合成tensorflow.python.data.ops.dataset_ops._OptionsDataset,我该怎么做?

或者有没有其他方法可以做到?

新手,感谢您的帮助!

【问题讨论】:

    标签: python numpy tensorflow dataset


    【解决方案1】:

    您可以使用tensor_from_slicesHere.

    编辑

    Example
    # Two tensors can be combined into one Dataset object. 
    values1 = tf.constant(['A', 'B', 'A']) # ==> 3x1 tensor
    values2 = tf.constant(['A', 'B', 'A']) # ==> 3x1 tensor
    dataset = Dataset.from_tensor_slices((values1, values2))
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-01
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 2018-06-27
    相关资源
    最近更新 更多