ContrastEncoder: missing buildmatrix with vector-valued mode gives "Nothing is not callable" instead of BUILDFUNC_MUST_BE_SPECIFIED
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 90/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- julia
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Bắt đầu bằng cách đọc src/encoders/contrast_encoder/contrast_encoder.jl xung quanh contrast_encoder_fit, đặc biệt là phần xác thực chế độ và lệnh gọi buildmatrix. Chạy các trường hợp tái hiện lỗi, sau đó cập nhật các bài kiểm thử hiện có trong test/encoders/contrast_encoder.jl để bao phủ các chế độ vectơ chứa :contrast hoặc :hypothesis và các chế độ AbstractVector{Symbol} không phải Vector. Công việc hoàn tất khi các trường hợp này ném ra ArgumentError dự kiến thay vì MethodError hoặc lỗi chế độ không được hỗ trợ, đồng thời hành vi hiện có đối với giá trị vô hướng vẫn được kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When mode is given as a vector, the buildmatrix check in contrast_encoder_fit never runs, so forgetting buildmatrix for a :contrast / :hypothesis feature gives a confusing MethodError instead of the intended BUILDFUNC_MUST_BE_SPECIFIED message.
The check is:
if mode in (:contrast, :hypothesis)
buildmatrix === nothing && throw(ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED))
end
For mode = [:contrast, :dummy] this is [:contrast, :dummy] in (:contrast, :hypothesis), which is false, so we fall through to buildmatrix(name, k) with buildmatrix === nothing at L109/L113.
Reproduction
using MLJTransforms, MLJBase, CategoricalArrays
X = (A = categorical(["a", "b", "c", "a"]), B = categorical(["x", "y", "x", "y"]))
# scalar mode: helpful error
try
MLJTransforms.contrast_encoder_fit(X, [:A]; mode = :contrast, ignore = false)
catch e
println("scalar mode -> ", sprint(showerror, e))
end
# vector mode: check is skipped
try
MLJTransforms.contrast_encoder_fit(X, [:A, :B]; mode = [:contrast, :dummy], ignore = false)
catch e
println("vector mode -> ", sprint(showerror, e))
end
# same through the MLJ interface
enc = ContrastEncoder(features = [:A, :B], mode = [:hypothesis, :dummy], ignore = false)
mach = machine(enc, X)
try
fit!(mach, verbosity = 0)
catch e
println("machine -> ", sprint(showerror, e)[1:min(end, 300)])
end
Output:
scalar mode -> ArgumentError: In ContrastEncoder with mode=:contrast or mode=:hypothesis, the `buildmatrix` argument must be specified.
vector mode -> MethodError: objects of type Nothing are not callable.
In case you did not try calling it explicitly, check if a Nothing has been passed as an argument to a method that expects a callable instead.
The object of type `Nothing` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.
┌ Error: Problem fitting the machine machine(ContrastEncoder(features = [:A, :B], …), …).
└ @ MLJBase ~/.julia/packages/MLJBase/lZsbe/src/machines.jl:758
[ Info: Running type checks...
[ Info: Type checks okay.
machine -> MethodError: objects of type Nothing are not callable.
In case you did not try calling it explicitly, check if a Nothing has been passed as an argument to a method that expects a callable instead.
The object of type `Nothing` exists, but no method is defined for this combination of argument types wh
Expected: the vector case throws the same ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED) as the scalar case.
Actual: MethodError: objects of type Nothing are not callable.
Related: non-Vector mode vectors
A nearby detail in the same block: the keyword is typed mode::Union{Symbol, AbstractVector{Symbol}} (and the struct allows AbstractVector{Symbol}), but the vector branch at L90 tests mode isa Vector{Symbol}. So any other AbstractVector{Symbol} skips the vector handling and the whole vector ends up treated as one mode:
modes = view([:sum, :dummy, :helmert], 1:2) # AbstractVector{Symbol}, not a Vector
MLJTransforms.contrast_encoder_fit(X, [:A, :B]; mode = modes, ignore = false)
ArgumentError: Mode [:sum, :dummy] is not supported.
Possible fix
Something like:
mode_is_vector = mode isa AbstractVector{Symbol}
...
modes = mode_is_vector ? mode : (mode,)
if any(in((:contrast, :hypothesis)), modes)
buildmatrix === nothing && throw(ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED))
end
plus a test next to the existing BUILDFUNC_MUST_BE_SPECIFIED one in test/encoders/contrast_encoder.jl (which currently only covers the scalar mode = :contrast case). Happy to open a PR if this sounds right.
Versions
- MLJTransforms
devat d3e3db3 (v0.2.4) - Julia 1.13.3, MLJBase from the registry, Linux x86_64
- Ngôn ngữ chính
- Julia
- Star
- 1
- Fork
- 5
- Merge trung bình
- 1 ngày 20 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaAI/MLJTransforms.jl
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
JuliaAI/MLJTransforms.jl#107 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
JuliaAI/MLJTransforms.jl#106 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 66/100
JuliaAI/MLJTransforms.jl#105 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add a `Transformer` wrapper for models that supervised that transformCó thể làm lại được @ablaom đã nhận 240 ngày trước và không có pull request nào đang mở. Đang mởenhancement
JuliaAI/MLJTransforms.jl#52 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
JuliaAI/MLJTransforms.jl#39 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của JuliaAI/MLJTransforms.jl
Issue tương tự
-
The entrypoint deletes its manifest runfiles tree at exit even under TEST_TMPDIRCó thể đã có người làm @TrapsterDK đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
periareon/rules_julia#64 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tagbot-manual
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Add to "Why Wren.jl"Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
JuliaBayes/Wren.jl#370 · 3 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
JuliaGPU/GemmKernels.jl#232 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100