Skip to main content

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_yyd

使用示例

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

casrel_datautils_yyd-0.0.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

casrel_datautils_yyd-0.0.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file casrel_datautils_yyd-0.0.1.tar.gz.

File metadata

  • Download URL: casrel_datautils_yyd-0.0.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for casrel_datautils_yyd-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c686f69e0ec1faaf50c13dfb53a3467e4f61be5d3a0d9a55a1268e8dcdeaf9a4
MD5 71ad2f1a280d69da92107a3ade758722
BLAKE2b-256 9b77cc5a937df04708934110fee65011782480753e3de986b5d3e2078cf776ca

See more details on using hashes here.

File details

Details for the file casrel_datautils_yyd-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for casrel_datautils_yyd-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7ebb7bb21ad8c68f8937e860b3f1266640f1466cbbcca535b59a66abf8bc5c8
MD5 0265f3009614f4327ce60deb6ec06243
BLAKE2b-256 28d14cffa42ddff19aad8010e65d3b65d63ff09f99d14896acda29056391708b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page