CasRel 数据处理工具包
这是一个基于 CasRel 模型的中文关系抽取数据处理工具包,支持 BERT 预训练模型。
支持的 BERT 模型
- bert-base-chinese: 默认中文 BERT 基础模型,适用于通用中文任务,参数量适中,bert_dim=768。
安装
- pip install casrel_datautils
使用示例
以下是一个使用 casrel_datautils 进行数据加载和单条样本处理的示例代码:
from casrel_datautils.Base_Conf import BaseConfig
from casrel_datautils.data_loader import get_dataloader
from casrel_datautils.process import single_sample_process
# 配置基础参数
baseconf = BaseConfig(
bert_path_or_bertModel_name="bert-base-chinese", #模型路径或模型名称
train_data=r"本地数据路径train.json",
test_data=r"本地数据路径test.json",
rel_data=r"本地关系数据路径relation.json",
batch_size=2
)
# 获取数据加载器
dataloaders = get_dataloader(baseconf)
# 单条样本处理
sample = {"text": "这是一个测试句子"}
input_tensor, mask_tensor = single_sample_process(baseconf, sample)
print(input_tensor.shape)
print(mask_tensor.shape)
说明
- BaseConfig: 用于设置 BERT 模型路径、数据路径和批次大小等参数。
- get_dataloader: 返回训练、验证和测试的数据加载器。
- single_sample_process: 处理单条文本样本,返回输入张量和掩码张量。
注意事项
- 确保数据文件(如
train.json、test.json、relation.json)路径正确。 - 根据任务需求选择合适的 BERT 模型。
Metadata
Release files for casrel-datautils 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| casrel_datautils-1.1.5.tar.gz | 1.3 MB | Without provenance | Details for casrel_datautils-1.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| casrel_datautils-1.1.5-py3-none-any.whl | Python 3 | none | any | Details for casrel_datautils-1.1.5-py3-none-any.whl |
Total release size: 1.3 MB
Release files / casrel_datautils-1.1.5.tar.gz
| Download URL | casrel_datautils-1.1.5.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c518a85a41116af7172be1ed9b49d0a83eb59d3a079d63f13be769f4c5f15f1
|
|
BLAKE2b-256 checksum How to use checksums |
bb319c5067ae1651838dacd76189a5f910cb003baca21cbe76b53b307f4bdfa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / casrel_datautils-1.1.5-py3-none-any.whl
| Download URL | casrel_datautils-1.1.5-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d1e9db2265d0a7fc2df6d5e45c449a5d5330c6525970fbea6a54f823c44420e
|
|
BLAKE2b-256 checksum How to use checksums |
97719d827fb87dfcd4717da017c7838e701d6dbb7ab1cbe77c272771713b8f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for casrel-datautils 1.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.