激活函数gelu(视觉变压器)返回的阵列的含义

发布于 2025-01-18 08:43:06 字数 290 浏览 1 评论 0原文

我正在尝试了解VisionTransFormer(VIT),并且在基本实现中,它使用MLP内的GELU激活功能,这是最后一层。

该函数给出的向量是什么含义?

在我的项目中,我有4个类[0,50,80,100],并给出了一个X(图像),我使用的是MLP(SO GELU)的阵列的最高值,看起来像: [-0.00404951,-0.15865529,0。,0.8413447,2.9959507] 进行分类。

我可以这样做分类吗?取出最高值的索引,然后用该索引在输入中对X进行分类? GELU在值[-3,3]的范围内给出了向量?

I'm trying to understand VisionTransformer (ViT) and in the basic implementation it uses GELU activation function inside the MLP, that is the last layer.

What is the meaning of the vector given back by the function?

In my project I have 4 classes [0,50,80,100] and given an x (an image) I'm using the highest value of the array give back by the MLP (so the GELU) that is something that looks like:
[-0.00404951, -0.15865529, 0. , 0.8413447 , 2.9959507 ]
to do classification.

Can i do classification in this way? Taking the index of the highest value and then classify the x in input with that index?
Is the vector given back by the GELU in the range of values [-3,3]?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

溺ぐ爱和你が 2025-01-25 08:43:06

推理时不一定需要softmax函数,因此GELU的输出可以用于分类。
如果需要概率表示,可以使用softmax函数将GELU输出转换为[0, 1]。

例如,如果将相关 GELU 的输出输入到 softmax 函数中,您将得到以下值,但最大值的索引不会改变。

In [1]: import tensorflow as tf
In [2]: tf.nn.softmax([-0.00404951, -0.15865529, 0.0, 0.8413447, 2.9959507])
Out[2]:
<tf.Tensor: shape=(5,), dtype=float32, numpy=
array([0.0395644 , 0.03389692, 0.03972494, 0.09214137, 0.7946724 ],
      dtype=float32)>

The softmax function is not necessarily needed during inference, so the output of the GELU can be used for classification.
If you need a probabilistic representation, you can use the softmax function to convert the GELU output to [0, 1].

For example, if you input the output of GELU in question into the softmax function, you will get the following values, but the index of the largest value will not change.

In [1]: import tensorflow as tf
In [2]: tf.nn.softmax([-0.00404951, -0.15865529, 0.0, 0.8413447, 2.9959507])
Out[2]:
<tf.Tensor: shape=(5,), dtype=float32, numpy=
array([0.0395644 , 0.03389692, 0.03972494, 0.09214137, 0.7946724 ],
      dtype=float32)>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文