saber:生物医学实体和关系的序列注释器
saber的Python项目详细描述
军刀
saber(ss equenceanotator forbiomedicalentities andrr elations)是一个深入学习的工具,用于生物医学领域的信息提取。
Installation• Quickstart• Documentation
安装
要安装saber,您需要python>=3.5
。如果尚未安装,python>=3.5
可以通过
- official installer
- Homebrew,在macos上(
brew install python3
) - Miniconda3/Anaconda3
(可选)激活虚拟环境(有关帮助,请参见below)
$ conda activate saber # Notice your command prompt has changed to indicate that the environment is active(saber) $
然后安装军刀
(saber) $ pip install saber
要获得saber的最新开发版本,请使用pip
(saber) $ pip install https://github.com/BaderLab/saber.git
或者克隆存储库,然后使用pip
来安装包
(saber) $ git clone https://github.com/BaderLab/saber.git (saber) $ cd saber (saber) $ pip install .
现在,您需要安装所需的Spacy模型和keras-contrib存储库(即使您安装了pip install saber
)
# keras-contrib(saber) $ pip install git+https://www.github.com/keras-team/keras-contrib.git # NeuralCoref medium model built on top of Spacy, this might take a few minutes to download!(saber) $ pip install https://github.com/huggingface/neuralcoref-models/releases/download/en_coref_md-3.0.0/en_coref_md-3.0.0.tar.gz
(可选)创建和激活虚拟环境
使用pip
时,通常建议在虚拟环境中安装软件包,以避免修改系统状态。创建名为saber
使用virtualenv或venv
$ virtualenv --python=python3 /path/to/new/venv/saber
使用venv
$ python3 -m venv /path/to/new/venv/saber
接下来,您需要激活环境
$ source /path/to/new/venv/saber/bin/activate # Notice your command prompt has changed to indicate that the environment is active(saber) $
使用conda
如果使用Conda,则可以通过运行
$ conda create -n saber python=3.6
然后使用
$ conda activate saber # Again, your command prompt should change to indicate that the environment is active(saber) $
快速启动
如果您的目标是使用saber注释生物医学文本,那么您可以使用web-service或pre-trained model。如果您只想签出saber,而不在本地安装任何东西,请尝试Google Colaboratory笔记本。
谷歌Colaboratory
签出saber的最快方式是跟随google colaboratory笔记本()。要运行单元格,请选择“在操场中打开”,或者将副本保存到您自己的google驱动器帐户(file>;save a copy in drive)。
网络服务
要将saber用作localweb服务,请运行
(saber) $ python -m saber.cli.app
或者,如果您愿意,可以从docker hub中提取并运行saber图像
# Pull Saber image from Docker Hub $ docker pull pathwaycommons/saber # Run docker (use `-dt` instead of `-it` to run container in background) $ docker run -it --rm -p 5000:5000 --name saber pathwaycommons/saber
目前有两个端点,/annotate/text
和/annotate/pmid
。两者都需要一个带有json负载的POST
请求,例如,
{"text":"The phosphorylation of Hdm2 by MK2 promotes the ubiquitination of p53."}
或
{"pmid":11835401}
例如,在本地运行web服务并使用cURL
$ curl -X POST 'http://localhost:5000/annotate/text'\ --data '{"text": "The phosphorylation of Hdm2 by MK2 promotes the ubiquitination of p53."}'
saber web服务api的文档可以在here中找到。
预先训练的模型
首先,导入Saber
类。这是Saber的界面
fromsaber.saberimportSaber
要加载预先训练的模型,首先创建一个Saber
对象
saber=Saber()
然后加载我们选择的模型
saber.load('PRGE')
您可以在存储库中的web-service API docs或saber/pretrained_models文件夹中看到所有预先训练的模型,或者运行以下代码行
fromsaber.constantsimportENTITIES;print(list(ENTITIES.keys()))
要用模型注释文本,只需调用Saber.annotate()
方法
saber.annotate("The phosphorylation of Hdm2 by MK2 promotes the ubiquitination of p53.")
有关详细信息,请参见documentation。
文档
saber api的文档可以在here中找到。web服务api有自己的文档here。最后,我们提供了一个jupyter notebook,介绍了使用saber的主要方法。有关设置JupyterLab的帮助,请参见here。