运行allennlp训练的模型,并使用webapi提供服务。

allennlp-runmodel的Python项目详细描述


allennlp运行模型

运行一个经过AllenNLP训练的模型,并使用webapi为其提供服务。

用法

运行程序

在Terminator中执行程序,选项--help将显示帮助消息:

$ allennlp-runmodel --help
Usage: allennlp-runmodel [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...  Start a webservice for running AllenNLP models.Options:  -V, --version  -h, --host TEXT                 TCP/IP host for HTTP server.  [default:                                  localhost]  -p, --port INTEGER              TCP/IP port for HTTP server.  [default:                                  8000]  -a, --path TEXT                 File system path for HTTP server Unix domain                                  socket. Listening on Unix domain sockets is                                  not supported by all operating systems.  -l, --logging-config FILE       Path to logging configuration file (JSON,                                  YAML or INI) (ref: https://docs.python.org/l                                  ibrary/logging.config.html#logging-config-                                  dictschema)  -v, --logging-level [critical|fatal|error|warn|warning|info|debug|notset]                                  Sets the logging level, only affected when                                  `--logging-config` not specified.  [default:                                  info]  --help                          Show this message and exit.Commands:  load  Load a pre-trained AllenNLP model from it's archive file, and put        it...

以及

$ allennlp-runmodel load --help
Usage: allennlp-runmodel load [OPTIONS] ARCHIVE

  Load a pre-trained AllenNLP model from it's archive file, and put it into
  the webservice contrainer.

Options:
  -m, --model-name TEXT           Model name used in URL. eg: http://xxx.xxx.x
                                  xx.xxx:8000/?model=model_name
  -t, --num-threads INTEGER       Sets the number of OpenMP threads used for
                                  parallelizing CPU operations. [default: 4(on this machine)]
  -w, --max-workers INTEGER       Uses a pool of at most max_workers threads
                                  to execute calls asynchronously. [default:
                                  num_threads/cpu_count (1 on this machine)]
  -w, --worker-type [process|thread]
                                  Sets the workers execute in thread or
                                  process.  [default: process]
  -d, --cuda-device INTEGER       If CUDA_DEVICE is >=0, the model will be
                                  loaded onto the corresponding GPU. Otherwise
                                  it will be loaded onto the CPU.  [default:
                                  -1]
  -e, --predictor-name TEXT       Optionally specify which `Predictor`
                                  subclass; otherwise, the default one for the
                                  model will be used.
  --help                          Show this message and exit.

load可以多次调用子命令来加载多个模型。

例如:

allennlp-runmodel  --port 8080 load --model-name model1 /path/of/model1.tar.gz load --model-name model2 /path/of/model2.tar.gz

从http客户端进行预测

curl \
  --header "Content-Type: application/json"\
  --request POST \
  --data '{"premise":"Two women are embracing while holding to go packages.","hypothesis":"The sisters are hugging goodbye while holding to go packages after just eating lunch."}'\
  http://localhost:8080/?model=model1

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Docker&SeleniumJava:无法在Docker容器上运行的chrome浏览器中上载图像/文件   在python中运行java命令   Java垃圾收集器异常行为   java java是否根据底层操作系统执行字节码级优化?   java是否可以休眠自定义查询返回映射而不是列表?   java Spring引导RabbitMQ接收器Jackson反序列化到POJO   apache flex在ActionScript3中创建对象相等“HashMap”作为java HashMap   java如何在Eclipse集成中切换JProfiler启动器   缓存JSP页面结果的java最佳实践?   java集成jaxb绑定文件,使用CXF生成基于WSDL的客户端   java为什么在上传操作结束之前,客户端没有检测到HttpServletResponse的PrintWriter内容?   java在接口内创建类和在类内创建接口有什么用   java向文件写入错误Android Studio   java合并多个RealmList并对结果列表排序?   谷歌API视觉java。lang.NoSuchMethodError   java如何使用逗号分别存储每个值,然后将它们存储到单独的数组中?