|
287 | 287 | Bilinear(W::AbstractArray, [bias, σ])
|
288 | 288 |
|
289 | 289 | Creates a Bilinear layer, which operates on two inputs at the same time.
|
290 |
| -It its output, given vectors `x`, `y` is another vector `z` with, |
| 290 | +Its output, given vectors `x` & `y`, is another vector `z` with, |
291 | 291 | for all `i ∈ 1:out`:
|
292 | 292 |
|
293 | 293 | z[i] = σ(x' * W[i,:,:] * y + bias[i])
|
@@ -323,23 +323,27 @@ julia> sc = SkipConnection(
|
323 | 323 |
|
324 | 324 | julia> sc(x) |> size
|
325 | 325 | (3, 32)
|
| 326 | +
|
| 327 | +julia> Flux.Bilinear(rand(4,8,16), false, tanh) # first dim of weight is the output |
| 328 | +Bilinear(8, 16, 4, tanh, bias=false) |
326 | 329 | ```
|
327 | 330 | """
|
328 |
| -struct Bilinear{A,B,S} |
| 331 | +struct Bilinear{F,A,B} |
329 | 332 | weight::A
|
330 | 333 | bias::B
|
331 |
| - σ::S |
| 334 | + σ::F |
| 335 | + function Bilinear(W::A, bias = true, σ::F = identity) where {A<:AbstractArray, F} |
| 336 | + ndims(A) == 3 || throw(ArgumentError("expected a 3-array of weights")) |
| 337 | + b = create_bias(W, bias, size(W,1)) |
| 338 | + new{F,A,typeof(b)}(W, b, σ) |
| 339 | + end |
332 | 340 | end
|
333 | 341 |
|
334 | 342 | @functor Bilinear
|
335 | 343 |
|
336 |
| -Bilinear(weight::AbstractArray, bias = true) = Bilinear(weight, create_bias(weight, bias, size(weight,1)), identity) |
337 |
| - |
338 | 344 | function Bilinear(in1::Integer, in2::Integer, out::Integer, σ = identity;
|
339 |
| - init = glorot_uniform, bias = true) |
340 |
| - W = init(out, in1, in2) |
341 |
| - b = create_bias(W, bias, out) |
342 |
| - return Bilinear(W, b, σ) |
| 345 | + init = glorot_uniform, bias = true) |
| 346 | + Bilinear(init(out, in1, in2), bias, σ) |
343 | 347 | end
|
344 | 348 |
|
345 | 349 | function (a::Bilinear)(x::AbstractMatrix, y::AbstractMatrix)
|
|
0 commit comments