TSLM
anitopy 兼容
此仓库提供 anitopy 兼容的接口,只需要将 import anitopy 替换为 import tslm.anitopy 即可。
使用方法
TSLM 会从 Hugging Face 下载推荐模型文件。首次使用时会自动下载,后续会复用本地缓存。
主动下载模型
如果希望在程序启动或部署阶段提前下载模型,可以主动调用下载方法。
GPU 推荐模型:
from tslm import Tslm
model_path = Tslm.download_from_huggingface(use_cuda=True)
print(model_path)
CPU 推荐模型:
from tslm import Tslm
model_path = Tslm.download_from_huggingface(use_cuda=False)
print(model_path)
use_cuda=True 会下载 tslm-fp16.onnx,适合 NVIDIA GPU 推理。
use_cuda=False 会下载 tslm-int8.onnx,适合 CPU 推理。
CPU 推荐用法
没有 GPU 时推荐使用 CPU 配置。模型文件为 tslm-int8.onnx,推荐每次处理 1 条。
from tslm import Tslm
tslm = Tslm(use_cuda=False, threads=4)
result = tslm("示例标题")
threads 表示 ONNX Runtime 使用的 CPU 线程数,可以按机器实际核心数和系统负载设置。例如低配 NAS 可使用 2 或 4,空闲机器可使用更高线程数。
也可以先主动下载模型,再显式传入模型路径:
from tslm import Tslm
model_path = Tslm.download_from_huggingface(use_cuda=False)
tslm = Tslm(use_cuda=False, threads=4, model_path=model_path)
result = tslm("示例标题")
GPU 推荐用法
有 NVIDIA GPU 时推荐使用 GPU 配置。模型文件为 tslm-fp16.onnx,推荐每次处理 2 条,可兼顾显存占用和处理速度。
from tslm import Tslm
tslm = Tslm(use_cuda=True)
result = tslm.batch([
"示例标题 1",
"示例标题 2",
])
也可以先主动下载模型,再显式传入模型路径:
from tslm import Tslm
model_path = Tslm.download_from_huggingface(use_cuda=True)
tslm = Tslm(use_cuda=True, model_path=model_path)
result = tslm.batch([
"示例标题 1",
"示例标题 2",
])
单条解析
parse 默认使用 CPU 推荐模型。
from tslm import parse
result = parse("示例标题")
如果希望使用 GPU:
from tslm import parse
result = parse("示例标题", use_cuda=True)
返回结果
TSLM.batch() 返回结果是以原始标题为 key 的字典,value 为识别出的字段列表。
Metadata
Release files for torrenkt-tslm 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torrenkt_tslm-0.2.0.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torrenkt_tslm-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.6 kB
Release files / torrenkt_tslm-0.2.0.tar.gz
| Download URL | torrenkt_tslm-0.2.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
996db5c1e5b116700197ae02314658d08436ce5b04165d6401d354b28522b522
|
|
BLAKE2b-256 checksum How to use checksums |
449255048861bfd1074adb2bb712428dcd2c2da6a08b59bba238fe5c11ef8c20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / torrenkt_tslm-0.2.0-py3-none-any.whl
| Download URL | torrenkt_tslm-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d31d530c9bfbca2ef5338eebbff5f4c8066a75bf814b43d5d25107c3c9757887
|
|
BLAKE2b-256 checksum How to use checksums |
4b6638b3f543f529d072c8d87ce5c6c7a154d40f0632bc1e2b2633f21492e877
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|