INNER CODE UNIT · Go

attended

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

	attended := make(Vector, d_v) // Use d_v determined earlier
	for i, weight := range weights {
        // Ensure consistent value dimensions within the loop
        if len(values[i]) != d_v {
             return nil, nil, fmt.Errorf("value dimension mismatch at index %d: expected %d, got %d", i, d_v, len(values[i]))
        }

        // Optimization: Skip summation if weight is zero
        if weight == 0 {
            continue
        }

		// Fuse the scaling by weight into the accumulation loop
		valueVec := values[i] // Local ref might help optimizer, maybe minor
		for j := 0; j < d_v; j++ { // Iterate up to d_v
			attended[j] += weight * valueVec[j]
		}
	}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…