Beispiel #1
0
    def get_parameter_types(self, ex):
        """
        For each config() parameter specified in the codebase for each module, deduce the correct type.
        Specifically, key_types[x] contains a function that we can call to cast the cmdline parameter to the correct type
        Eg: "none" should be casted to None
        """
        parameter_types = {}
        for k, v in ex.config(module_config)().items():
            parameter_types[k] = type("string")

        for k, v in ex.config(stateless_config)().items():
            parameter_types[k] = forced_types.get(type(v), type(v))

        parameter_types["pipeline"] = str
        for k, v in ex.config(pipeline_config)().items():
            parameter_types[k] = forced_types.get(type(v), type(v))

        return parameter_types
Beispiel #2
0
    def get_parameters_to_module_for_feature_parameters(self, ex):
        """
        Adds config related to the extractor associated with the supplied NIR Reranker to the parameter_to_module dict.
        Eg: See `EmbedText.config()`
        """
        self.parameter_types["extractor"] = str
        for feature_cls in self.module2cls["reranker"].EXTRACTORS:
            for k, v in ex.config(feature_cls.config)().items():
                if k in self.parameters_to_module:
                    raise RuntimeError(f"extractor {feature_cls} contains conflicting config key {k}")
                self.parameters_to_module[k] = "extractor"
                self.parameter_types[k] = forced_types.get(type(v), type(v))

        return self.parameters_to_module, self.parameter_types
Beispiel #3
0
    def get_parameters_to_module_for_missing_parameters(self, ex):
        """
        Not all parameters are supplied by the user. This method determines which parameters were not supplied by the
        user and plugs in sensible defaults for them
        """
        # config keys for each module
        for module in modules:
            if module == "collection":  # collections do not have their own configs
                continue
            for k, v in ex.config(self.module2cls[module].config)().items():
                if k not in self.parameters_to_module:
                    self.parameters_to_module[k] = module
                    self.parameter_types[k] = forced_types.get(type(v), type(v))

        return self.parameters_to_module, self.parameter_types