如何设计神经网络来识别不同的特征?

How to design a neural network to recognize distinct features?

我正在尝试使用 tf.layers.dense 接口在 tensorflow 中构建一个神经网络。我想弄清楚如何让 tensorflow 将所有特征视为一组特征。

一个例子:

将一群人分类为 good/bad 篮球队(0- 差,1- 好)。 每个人都有 his/her 自己的特征(性别、年龄、身高、体重、打篮球的年限)。要将整个团队分类为好或坏,神经网络必须看到 5 个人的特征,输出应该是 0 或 1。

现在在这个例子中,我如何让网络看到与不同人相关的所有不同特征并输出一个分类数字?

我假设它与输入张量的形状有关,我尝试制作形状为 [batch_size、number_of_players、number_of_features] 的张量像这样:

[
 [[gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball], //team1
  [gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball]],

 [[gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball], //team2
  [gender, age, height, weight, years_playing_basketball],
  [gender, age, height, weight, years_playing_basketball]]
]

自然地,在将这个张量通过几个 tf.layers.dense 层之后,输出也将是一个 3D 张量,而我只需要一个数字作为输出。另一方面,如果我将所有团队特征放入一个数组中,我相信网络将无法知道这些实际上是 5 个不同人的特征。提前感谢您的帮助!

Naturally, after passing this tensor through several tf.layers.dense layers, the output would also be a 3D tensor while I would only need a single number as an output.

您需要具有 batch_size 不同输出的一维张量,对吗?批次中每个完整团队一个输出。

On the other hand, If I put all team features into a single array, I believe the network wouldn't have any way of knowing that these are in fact features of 5 different people.

这是最常见的解决方案,也可能是最好的解决方案。绝对是最简单的。此解决方案仅在您确定每个团队始终有 5 人时才有效,我想这是一个安全的假设?

这个解决方案通常被称为 "flattening"(在许多框架中,您可以使用名为 [=13= 的函数将 (number_of_players, number_of_features) 张量转换为 (number_of_players * number_of_features) 张量]).是的,你是正确的,神经网络无法“'knowing'”团队成员 X 的年龄特征在某种程度上与团队成员 Y 的年龄特征相似,或者“'knowing'”与团队成员 X 的年龄特征和团队成员 Y 的性别特征相比,团队成员 X 的年龄和性别特征在某种程度上彼此更密切相关……但这通常没问题。如果事实证明学习这样的东西很重要,它仍然可以这样做。


一个额外的提示:如果不同的人出现在同一个团队中的顺序并不重要(例如,如果没有一些重要的、一致的基于位置的排序或类似的东西),我建议 增加你的数据 通过将你已经拥有的团队的随机版本也包括在你的数据中。例如,如果您的数据包含一个团队 [P1, P2, P3, P4, P5](其中每个 P 都是对应于一个人的一系列特征),我会通过添加一个团队 [P2, P1] 来扩充数据集, P3, P4, P5], 和一个团队 [P3, P1, P2, P4, P5], 等等。你基本上可以添加所有可能的排列。