Flux.jl
Flux.jl copied to clipboard
display fieldnames in show of a container
I think it would be helpfuld to display the fieldnames in our bigshow. For example, we currently have
julia> rnn = RNN(4 => 6)
RNN(
RNNCell(4 => 6, tanh), # 66 parameters
)
that could become
julia> rnn = RNN(4 => 6)
RNN(
cell = RNNCell(4 => 6, tanh), # 66 parameters
)
The present recursion roughly assumes the existence of the default constructor. This instead assumes the existence of a keyword constructor, which is much less common:
julia> RNN(
cell = RNNCell(4 => 6, tanh), # 66 parameters
)
ERROR: MethodError: no method matching RNN(; cell::RNNCell{typeof(tanh), Matrix{Float32}, Matrix{Float32}, Vector{Float32}})
The type `RNN` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
...
RNN(::M) where M got unsupported keyword argument "cell"
@ Flux ~/.julia/packages/Flux/5vIRy/src/layers/recurrent.jl:171
You could put field names in the comment without breaking anything, # .cell, 66 parameters.
It does show names for some where a keyword constructor is known to exist. That mechanism could surely be made more generalisable it someone wants it enough:
julia> Chain(one=RNN(4 => 6, tanh), two=identity)
Chain(
one = RNN(
RNNCell(4 => 6, tanh), # 66 parameters
),
two = identity,
) # Total: 3 arrays, 66 parameters, 424 bytes.
This is because you want the output to be a valid constructor when copy-pasted, right?
We can have an option for Flux.@layer :named MyModel to display the field names. Even if copy-pasting cannot construct I think it would be useful.