【问题标题】:np.split() with output from tf.nn.softmaxnp.split() 与 tf.nn.softmax 的输出
【发布时间】:2023-03-26 11:26:01
【问题描述】:

我正在使用 Tensorflow 进行词性标注。我以这种方式获得了 softmax 层的输出(它使用 tf.nn.softmax):

pos_tags_confidences = sess.run(
        self.pos_tags_softmax_op,
        feed_dict=self.feed_dict(batch, is_test=True)
    )

POS-tags confidence 有一个形状 (580, 21),如下所示:

[[  2.84045556e-04   1.08584835e-07   5.98690785e-05 ...,   
    7.19540509e-18
    9.11230517e-18   1.95343427e-21]
[  9.98795390e-01   4.86789819e-12   1.50688564e-07 ...,   
   8.64652642e-23
2.89635869e-14   1.35281987e-18]
[  1.54589606e-03   1.40889606e

我想在前一个数组上使用 np.split() 并将其拆分为 [550, 30]

问题是我得到以下结果:

  • 形状为 (550,21) 的数组
  • 一个空数组,
  • 另一个形状为 (550,21) 的数组

代替:

  • 形状为 (550,21) 的数组
  • 形状为 (30,21) 的数组

可能出了什么问题?请注意,我在项目的其他地方使用相同的代码并且运行良好。

【问题讨论】:

    标签: python arrays numpy tensorflow


    【解决方案1】:
    pos_tags_confidences = pos_tags_confidences.squeeze()
    assert pos_tags_confidences.shape==(580, 21) 
    split_arrays = np.split(pos_tags_confidences, [550], axis=0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2018-06-04
      • 1970-01-01
      相关资源
      最近更新 更多