Documentation
¶
Overview ¶
Package layers implements layers and graph functions that commonly used in GNN operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SparseSoftmax ¶
SparseSoftmax takes a logits vector [N] and the indices where they should aggregate [N, 1], and returns the probabilities:
denominator[j] = \sum_{i \in set{indices[i] = j}}(exp(logits[i]))
softmask[i] = exp(logits[i]) / denominator[indices[i]]
If logitsMask is not nil, exp(logits[i]) is replaced with 0 where logitsMask is false.
Args:
- logits: vector shaped [N] of some float dtype.
- logitsMask: nil or a vector shaped [N] of bools.
- indices: shapes [N, 1], with the indices on which the logits are part of.
- maxIndex: it's the max(indices), it is required statically (not a graph Node) because we reduce sum the exponentials on a temporary node with this shape. It must be known in the graph building time.
- sorted: if the indices are sorted set this to true, it will lead to faster runtime in some platforms. In doubt, leave this as false: it could lead to undefined behavior if the indices are not actually sorted.
It returns a vector shaped [N] with the same dtype as logits.
Example:
logits := Const(g, []float32{ln1, ln2, ln1, ln2, ln1, 0, 0, 0})
indices := Const(g, []int32{0, 0, 0, 1, 1, 0, 0, 0})
mask := Const(g, []bool{true, true, true, true, true, false, false, false})
inputs = []*Node{logits, indices, mask}
softmax := SparseSoftmax(logits, mask, ExpandAxes(indices, -1), 2, false)
// softmax == []float32{1.0 / 4, 2.0 / 4, 1.0 / 4, 2.0 / 3, 1.0 / 3, 0, 0, 0}
Types ¶
This section is empty.