Skip to main content

一行代码训练 BERT

Project description

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

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

pybert-0.0.2.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

pybert-0.0.2-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file pybert-0.0.2.tar.gz.

File metadata

  • Download URL: pybert-0.0.2.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pybert-0.0.2.tar.gz
Algorithm Hash digest
SHA256 88a558d14930ed546ff827e189955c8448dfdb90a06d3350e260fa34a32a1f93
MD5 c6b56aec2b40f9ef7572735b84d8c73e
BLAKE2b-256 49f1372bd98b5ae7ebce3906ee284cb5fd507dcf9e897f020be7f1733f73e1e3

See more details on using hashes here.

File details

Details for the file pybert-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pybert-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pybert-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8ffa6ccfd44232ada27082d285690c8cbda9b363c4c20f284365796151116d4
MD5 f1624b10f56f44e26084708998f68846
BLAKE2b-256 baee4873531be4c3c307749b15bd894ae38c805a16902c5acbaf0787a6bf1ddf

See more details on using hashes here.

Supported by

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