Skip to main content

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.jsontest.jsonrelation.json)路径正确。
  • 根据任务需求选择合适的 BERT 模型。

Release files for hellolyl 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hellolyl 1.1.5
File Size Uploaded
hellolyl-1.1.5.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hellolyl 1.1.5
File Interpreter ABI Platform
hellolyl-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 5.8 kB

Release files / hellolyl-1.1.5.tar.gz

Download URL hellolyl-1.1.5.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
72b33b6f1907f4159a277bc1f57eed792180dfbee260673ad6ce7532f89e17e5
BLAKE2b-256 checksum
How to use checksums
39408ddf2ba034c6032330a4dc0937f5de3a495524b391f5b51a3fb10657d829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / hellolyl-1.1.5-py3-none-any.whl

Download URL hellolyl-1.1.5-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b585809fe9c7e56bc1d62915baf4c5655b45d154e70846c2a0241228ce75daa
BLAKE2b-256 checksum
How to use checksums
a650de98d50d7a8d97933c1aa31d1d349408b4966b67594b1bf33a13ad210c82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page