deeppavlov/core/commands/infer.py
def build_model(config: Union[str, Path, dict], mode: str = 'infer',
                load_trained: bool = False, download: bool = False,
                serialized: Optional[bytes] = None) -> Chainer:
    """Build and return the model described in corresponding configuration file."""
    config = parse_config(config)

    if serialized:
        serialized: list = pickle.loads(serialized)

    if download:
        deep_download(config)

    import_packages(config.get('metadata', {}).get('imports', []))

    model_config = config['chainer']

    model = Chainer(model_config['in'], model_config['out'], model_config.get('in_y'))

    for component_config in model_config['pipe']:
        if load_trained and ('fit_on' in component_config or 'in_y' in component_config):
            try:
                component_config['load_path'] = component_config['save_path']
            except KeyError:
                log.warning('No "save_path" parameter for the {} component, so "load_path" will not be renewed'
                            .format(component_config.get('class_name', component_config.get('ref', 'UNKNOWN'))))

        if serialized and 'in' in component_config:
            component_serialized = serialized.pop(0)
        else:
            component_serialized = None

        component = from_params(component_config, mode=mode, serialized=component_serialized)

        if 'in' in component_config:
            c_in = component_config['in']
            c_out = component_config['out']
            in_y = component_config.get('in_y', None)
            main = component_config.get('main', False)
            model.append(component, c_in, c_out, in_y, main)

    return model
def build_model(config: Union[str, Path, dict], mode: str = 'infer',
                load_trained: bool = False, download: bool = False,
                serialized: Optional[bytes] = None) -> Chainer:
    """Build and return the model described in corresponding configuration file."""
    config = parse_config(config)

    if serialized:
        serialized: list = pickle.loads(serialized)

    if download:
        deep_download(config)

    import_packages(config.get('metadata', {}).get('imports', []))

    model_config = config['chainer']

    model = Chainer(model_config['in'], model_config['out'], model_config.get('in_y'))

    for component_config in model_config['pipe']:
        if load_trained and ('fit_on' in component_config or 'in_y' in component_config):
            try:
                component_config['load_path'] = component_config['save_path']
            except KeyError:
                log.warning('No "save_path" parameter for the {} component, so "load_path" will not be renewed'
                            .format(component_config.get('class_name', component_config.get('ref', 'UNKNOWN'))))

        if serialized and 'in' in component_config:
            component_serialized = serialized.pop(0)
        else:
            component_serialized = None

        component = from_params(component_config, mode=mode, serialized=component_serialized)

        if 'in' in component_config:
            c_in = component_config['in']
            c_out = component_config['out']
            in_y = component_config.get('in_y', None)
            main = component_config.get('main', False)
            model.append(component, c_in, c_out, in_y, main)

    return model
def build_model ( config : Union [ str , Path , dict ] , mode : str = 'infer' , load_trained : bool = False , download : bool = False , serialized : Optional [ bytes ] = None ) -> Chainer : config = parse_config ( config ) if serialized : serialized : list = pickle . loads ( serialized ) if download : deep_download ( config ) import_packages ( config . get ( 'metadata' , { } ) . get ( 'imports' , [ ] ) ) model_config = config [ 'chainer' ] model = Chainer ( model_config [ 'in' ] , model_config [ 'out' ] , model_config . get ( 'in_y' ) ) for component_config in model_config [ 'pipe' ] : if load_trained and ( 'fit_on' in component_config or 'in_y' in component_config ) : try : component_config [ 'load_path' ] = component_config [ 'save_path' ] except KeyError : log . warning ( 'No "save_path" parameter for the {} component, so "load_path" will not be renewed' . format ( component_config . get ( 'class_name' , component_config . get ( 'ref' , 'UNKNOWN' ) ) ) ) if serialized and 'in' in component_config : component_serialized = serialized . pop ( 0 ) else : component_serialized = None component = from_params ( component_config , mode = mode , serialized = component_serialized ) if 'in' in component_config : c_in = component_config [ 'in' ] c_out = component_config [ 'out' ] in_y = component_config . get ( 'in_y' , None ) main = component_config . get ( 'main' , False ) model . append ( component , c_in , c_out , in_y , main ) return model
Build and return the model described in corresponding configuration file.
Build and return the model described in corresponding configuration file .