deeppavlov/core/commands/infer.py
def predict_on_stream(config: Union[str, Path, dict], batch_size: int = 1, file_path: Optional[str] = None) -> None:
    """Make a prediction with the component described in corresponding configuration file."""
    if file_path is None or file_path == '-':
        if sys.stdin.isatty():
            raise RuntimeError('To process data from terminal please use interact mode')
        f = sys.stdin
    else:
        f = open(file_path, encoding='utf8')

    model: Chainer = build_model(config)

    args_count = len(model.in_x)
    while True:
        batch = list((l.strip() for l in islice(f, batch_size * args_count)))

        if not batch:
            break

        args = []
        for i in range(args_count):
            args.append(batch[i::args_count])

        res = model(*args)
        if len(model.out_params) == 1:
            res = [res]
        for res in zip(*res):
            res = json.dumps(res, ensure_ascii=False)
            print(res, flush=True)

    if f is not sys.stdin:
        f.close()
def predict_on_stream(config: Union[str, Path, dict], batch_size: int = 1, file_path: Optional[str] = None) -> None:
    if file_path is None or file_path == '-':
        if sys.stdin.isatty():
            raise RuntimeError('To process data from terminal please use interact mode')
        f = sys.stdin
    else:
        f = open(file_path, encoding='utf8')

    model: Chainer = build_model(config)

    args_count = len(model.in_x)
    while True:
        batch = list((l.strip() for l in islice(f, batch_size * args_count)))

        if not batch:
            break

        args = []
        for i in range(args_count):
            args.append(batch[i::args_count])

        res = model(*args)
        if len(model.out_params) == 1:
            res = [res]
        for res in zip(*res):
            res = json.dumps(res, ensure_ascii=False)
            print(res, flush=True)

    if f is not sys.stdin:
        f.close()
def predict_on_stream ( config : Union [ str , Path , dict ] , batch_size : int = 1 , file_path : Optional [ str ] = None ) -> None : if file_path is None or file_path == '-' : if sys . stdin . isatty ( ) : raise RuntimeError ( 'To process data from terminal please use interact mode' ) f = sys . stdin else : f = open ( file_path , encoding = 'utf8' ) model : Chainer = build_model ( config ) args_count = len ( model . in_x ) while True : batch = list ( ( l . strip ( ) for l in islice ( f , batch_size * args_count ) ) ) if not batch : break args = [ ] for i in range ( args_count ) : args . append ( batch [ i : : args_count ] ) res = model ( * args ) if len ( model . out_params ) == 1 : res = [ res ] for res in zip ( * res ) : res = json . dumps ( res , ensure_ascii = False ) print ( res , flush = True ) if f is not sys . stdin : f . close ( )
Make a prediction with the component described in corresponding configuration file.
Make a prediction with the component described in corresponding configuration file .