k1lib.selector module

This module is mainly used internally, although end users can enjoy some of its benefits too. The idea is to create a tree structure exactly like the given nn.Module. With the exact tree structure, we can then select specific parts of the module, for any purposes that we’d like, hence the main class’s name is ModuleSelector.

Let's say you have a network architecture like this:

Let's create a new network:

This is moderately complex. We can then create a simple selector:

So essentially, this is kinda similar to CSS selectors. #a will selects any module with name a. b will selects any module with class name b. Inheritance operators, like a b (indirect child) and a > b (direct child) works the same as in CSS too.

You can also use the asterisk * to select everything. So, #a > * will match all child of module with name a, and #a * will select everything recursively under it. In fact, when you first create k1lib.Learner, the css is * to select everything by default.

For each selection sentences, you can attach specific properties to it. If no properties are specified, then the property "*" will be used. You can then get a list of selected modules:

Here, it selects any modules with properties “propA” or “*”.

There are other methods that are analogues of nn.Module like named_children() and whatnot.