-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new option for exporting learning networks as stand-alone composite model types #841
Conversation
For a 0.20.11 release
For a 0.20.12 release
For a 0.20.13 release
For a 0.20.14 release
For a 0.20.15 release
For a 0.20.16 release
Adapt some tests for Julia nightly.
For a 0.20.17 release
For 0.20.18 release
oops generalize models(::AbstractNode) to find symbolic models fix test fix logic in `fit_only!` for symbolic machines fix some tests
extra cleanup around serialization fix missed tests
The MLJ doc update associated with the change proposed here has been posted. The new rewritten Learning Networks section is here. |
Hey, sorry I've been very busy. I'm trying to integrate it currently, my approach is as follows: We defined wrappers for detectors (previously resulting in composite detectors, now in composite network detectors) that take a variabled number of arguments as base detectors. Previously these base detector were used in I used something like Otherwise I don't see major hurdles, another small thing is that we defined a fallback for |
Sorry I've just realised I've missed that! I'll try to have a look in the next couple days, it looks really promising, but please feel free to go ahead since it's been open for some time already. |
kwargs...) | ||
return Machine(model, arg1, args...; kwargs...) | ||
end | ||
|
||
function machine(model::Symbol, arg1::AbstractNode, args::AbstractNode...; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method is now redundant with the method above.
Thanks @ablaom for this simplification of the learning network definition process! My only reservations are about the symbolic access of models in the definition of the network itself. For that magic to occur you've had to hack into and complexify |
@davnn Thanks for looking at this.
Whenever you call
Mmm. I think I need more context to understand why this is not working, as I've by now forgotten the details. Can you please point me to the relevant code and I'll take a look. (I didn't think we had a An alternative is to leave that particular line alone - that should still work. You don't have to do the symbol replacement. The problem will be that the reports and fitted_params for the individual detectors in your ensemble will not automatically appear in the composite model's report and fitted_params. In the case of reports, we can (probably) add them "manually" using report nodes; in the case of fitted_params I'm now thinking of adding a facility to do that also in this PR. But I should first like to see if we can avoid this workaround. |
Relax type restriction on `y` in `train_test_pairs(::StratifiedCV, rows, y)`
@olivierlabayle Thanks for taking the time to look over this substantial PR and for your valuable feedback.
Yes, there is some complication to
Yes, it's slightly more tedious to debug. When working with an unexported learning network with the symbol replacements, you need to add the |
Yes, I've implemented Edit: At least I managed to fix the package to work with current #dev and the latest releases (0.20.12 - 0.20.20). The fix is hacky, but better than nothing, see OutlierDetectionJL/OutlierDetection.jl@0398eba. The fix should equally work for #banana, but that appears to break other, non-report related, functionality I think. |
update serialization for NetworkComposite models re fitted_params fixed overlooked problems
@davnn I'm going to continue the OutlierDetection specific discussion in a new thread which will appear shortly below. |
This
non-breakingPR addresses #831.It is mildly breaking: Where previously
report(mach)
returnedNamedTuple()
, it will now returnnothing
instead.Requires:
report
method for merging fit reports with operational reports MLJModelInterface.jl#160Has been tested (with above MLJModelInterface PR) as non-breaking for MLJTuning, MLJEnsembles, MLJIteration.
Has been tested with MLJTestIntegration, which applies integration tests for majority of model providing packages.
Summary
This PR adds a new abstract type
NetworkComposite
, with subtypesDeterministicNetworkComposite
, etc, for the purpose of "exporting" learning networks as new stand-alone model types. It is intended to render all existing alternatives obsolete, but these are not touched in this PR. It is simpler, in that there are no "learning network machines" , noSurrogate
models, and no specialreturn!
method to call. Refer to #831 for a list of other drawbacks overcome by the new approach.Below is a demonstration of exporting a learning network to combine predictions of two regressors. It additionally exposes in the new model's report the output of a node called
disagreement
(measuring disagreement between the two regressors, at time of training):Step 1: Define the composite type - must subtype
NetworkComposite
Step 2: Implement
MLJBase.prefit
(method added in this PR)This method has same signature as
fit(model, ...)
and returns a named tuple constituting an "interface" to a learning network constructed out of it's arguments. A novelty is that component models are represented by the names (symbols) of the relevant field of the composite.Details
A new documentation PR at MLJ has already been posted. The relevant section is here
There are two additional changes introduced in this PR which make the above possible:
Symbols instead of models in machines
One can bind data in a machine to a "virtual" model, which is just a symbol, as in
mach = machine(:transformer, X)
. Ifmy_composite
is any object with:transformer
as a property, thenfit!(mach; composite=my_composite)
will train the machine with:transformer
replaced withgetproperty(my_composite, :transformer)
. This "run-time interpolation" of models propagates to all machines in a learning network. The general user need not bother with this, but if they know about it, the export process above is less mysterious.Separate training reports and operation reports in machines
In a change purely internal to MLJBase, the
report
field of a machine is now a dictionaryd
, keyed on method (:fit
,:predict
, etc). When an reporting operation is called on the machine, it's report is added to the dictionary; previously it was merged with the training report. Now when you callreport
on a machine, the various reports in dictionary get merged by calling a new methodMLJModelInterface.report(::Model, d)
. This method can be overloaded by a model but there is a fallback that does a pretty good job of it (the fallback unexpectedly "just worked" for the newNetworkComposite
types).In the existing export process,
fitted_params(::Machine, ...)
andreport(::Machine, ...)
have to be special-cased for composite model types. With this new approach, that is no longer necessary, which restores uniformity to the interface.To do
save
andrestore
methods for serialising<:NetworkComposite
fitted_params
, as we have already forreport
s.