INNER CODE UNIT · Go

testDotProductAttention

takara-ai/go-attention · cmd/demo/main.go:25

func testDotProductAttention() {
    // Create a simple query-key-value setup
    query := attention.Vector{1.0, 0.0, 1.0, 0.0}  // Looking for patterns similar to [1,0,1,0]
    keys := attention.Matrix{
        {1.0, 0.0, 1.0, 0.0},  // Similar to query
        {0.0, 1.0, 0.0, 1.0},  // Different from query
        {0.5, 0.5, 0.5, 0.5},  // Neutral pattern
    }
    values := attention.Matrix{
        {1.0, 2.0},  // Value for similar key
        {3.0, 4.0},  // Value for different key
        {5.0, 6.0},  // Value for neutral key
    }

    // Compute attention
    output, weights, err := attention.DotProductAttention(query, keys, values)
    if err != nil {
        log.Fatal(err)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…