支架
supportr的Python项目详细描述
支架
简介
supportr是一个用来预测文本支持值的包。
它基于一个微调的bert模型。
安装
使用pip
如果安装了pip
,则可以直接从中安装supportr:
pip install supportr
依赖性
python>=3.6.0
torch>=0.4.1
numpy
pandas
unidecode
pytorch-pretrained-bert
pytorch-transformers
用法和示例
注意:在您第一次使用时,软件包会自动下载一个大约400MB的模型文件。
predict
predict
是这个包的核心方法,
它接受文本列表中的单个文本,并返回[1,5]
中的原始值列表(较高的表示更多支持,而较低的表示更少)。
最简单的用法
您可以直接导入supportr
,并使用默认的预测方法,例如:
>>> import supportr
>>> supportr.predict(["I am totally agree with you"])
[3.8364935]
从类构造
或者,也可以从类构造对象,在类中可以自定义模型路径和设备:
>>> from supportr import Supportr
>>> sr = Supportr()
# Predict a single text
>>> sr.predict(["I am totally agree with you"])
[3.8364935]
# Predict a list of texts
>>> preds = sr.predict(['I am totally agree with you','I hate you'])
>>> f"Raw values are {preds}"
[3.836493 1.7458204]
docstrings中提供了有关如何构造对象的更多详细信息。
将大数据集预处理为bert输入特征时使用多处理的模型
如果要在预处理大型数据集时通过多处理使用多个CPU核,可以通过
>>> pr = Supportr(CPU_COUNT=cpu_cpunt, CHUNKSIZE=chunksize)
如果要通过多个GPU加快代码速度,可以通过
>>> pr = Supportr(is_paralleled=True, BATCH_SIZE = batch_size)