A Chinese relation extraction data utility toolkit based on CasRel model
Project description
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=r"C:\Lucky_dt\2_bj\BJ_AI23_KG\12days\KG_code\chapter4_code\CasRel_RE\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 模型。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
liu939-1.1.5.tar.gz
(14.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
liu939-1.1.5-py3-none-any.whl
(17.1 kB
view details)
File details
Details for the file liu939-1.1.5.tar.gz.
File metadata
- Download URL: liu939-1.1.5.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8dee7a1398cf31da47cc635206496782eb397e2bb3a20e3fbe7834b6b827ab
|
|
| MD5 |
7f32305e62ecd9816e90b4343aa3cb24
|
|
| BLAKE2b-256 |
2b9edbac97f17424d96be242e70bc4e66dace73cd094c82cfa505456cebae3c1
|
File details
Details for the file liu939-1.1.5-py3-none-any.whl.
File metadata
- Download URL: liu939-1.1.5-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7293060feec8ec9df6ce2f1851a0f940eaf5e17457453dfa7f0ddce938cbd6e
|
|
| MD5 |
e7501d147b336b603e802bab9dd77307
|
|
| BLAKE2b-256 |
e4ee5e318f86d14a209dcae81c002fd9510a6b698dada14c54bcab458dd1b52a
|