def build(cls, params, sub_cls=None, controller=None): layer_cls_names = try_get_attr(params, f'{cls.prefix_name()}_layer_names') layer_clses = [ Layer.load_cls(layer_cls_name) for layer_cls_name in layer_cls_names ] layer_params = cls.collect_layer_params(layer_cls_names) layer_args = { name: try_get_attr(params, f'{cls.prefix_name()}_layer_{name}s') for name in layer_params.keys() } layer_args = { key: value for key, value in layer_args.items() if value is not None } layers = list() for idx, layer_cls in enumerate(layer_clses): layer_kwargs = { name: layer_arg[idx] for name, layer_arg in layer_args.items() } layer_kwargs = load_func_kwargs(layer_kwargs, layer_cls.__init__) layers.append(layer_cls(**layer_kwargs)) kwargs = load_func_params(params, cls.__init__, cls.prefix_name()) kwargs[f'{cls.prefix_name()}_layers'] = layers return cls.default_build(kwargs, controller=controller)
def build(cls, params, sub_cls=None, controller=None): kwargs = load_func_params(params, cls.__init__, cls.prefix_name()) for net_name in cls.net_names: net = Net.build(params, sub_cls=try_get_attr(params, f'{cls.prefix_name()}_{net_name}_cls'), controller=controller) kwargs[f'{cls.prefix_name()}_{net_name}'] = net return cls.default_build(kwargs, controller=controller)
def build(cls, params, sub_cls=None, controller=None): dataset_cls = Dataset.load_cls(params.dataset_cls) q_vocab, _ = dataset_cls.load_combined_vocab() kwargs = load_func_params(params, cls.__init__, cls.prefix_name()) kwargs[f'{cls.prefix_name()}_q_vocab'] = q_vocab return cls.default_build(kwargs, controller=controller)