Skip to main content

pybert

安装

>pip install pybert

预训练模型

下载地址:

所需文件:

  • pytorch_model.bin
  • bert_config.json
  • vocab.txt

放到 bert_pretrain 文件夹中

训练数据下载

THUCNews

  • 可以任意指定文件夹名称,训练数据的格式要和上面一致

训练和预测

训练

from pybert.models import bert
from pybert.train_eval import load_and_train

dataset = 'THUCNews'  # 数据集
logfile = 'log.txt'  # 日志文件
config = bert.Config(dataset, logfile=logfile)
load_and_train(config)

预测

# coding: UTF-8
import pybert.models.bert as bert
from pybert.train_eval import Prediction

config = bert.Config(dataset='THUCNews')
prediction = Prediction(config)

sentences = ['野兽用纪录打爆第二中锋 掘金版三巨头已巍然成型', '56所高校预估2009年湖北录取分数线出炉']

predict_label, score = prediction.predict(sentences)
print("predict label:")
print(predict_label)

对应论文

[1] BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding

Metadata

Release files for pybert 0.0.2

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

Source distribution (sdist)

Source distribution for pybert 0.0.2
File Size Uploaded
pybert-0.0.2.tar.gz 28.6 kB Details

Built distribution (wheel)

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

Total release size: 58.5 kB

Release files / pybert-0.0.2.tar.gz

Download URL pybert-0.0.2.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
88a558d14930ed546ff827e189955c8448dfdb90a06d3350e260fa34a32a1f93
BLAKE2b-256 checksum
How to use checksums
49f1372bd98b5ae7ebce3906ee284cb5fd507dcf9e897f020be7f1733f73e1e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release files / pybert-0.0.2-py3-none-any.whl

Download URL pybert-0.0.2-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8ffa6ccfd44232ada27082d285690c8cbda9b363c4c20f284365796151116d4
BLAKE2b-256 checksum
How to use checksums
baee4873531be4c3c307749b15bd894ae38c805a16902c5acbaf0787a6bf1ddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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