INNER CODE UNIT · Go

DotProductOptimized

takara-ai/go-attention · attention/attention.go:75

func DotProductOptimized(v1, v2 Vector) (float64, error) {
	return DotProduct(v1, v2)
}

// Softmax applies the softmax function to a vector
// Performance: O(n) where n=len(x)
func Softmax(x Vector) Vector {
	if len(x) == 0 {
		return Vector{}
	}

	maxVal := x[0]
	// Find max value for numerical stability
	for _, v := range x[1:] {
		if v > maxVal {
			maxVal = v
		}
	}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…