Coder Social home page Coder Social logo

ztrain's Introduction

💡 ZTrain: 基于Pytorch的一个模块化的训练、验证、测试框架

提供一个模块化,易于扩展的训练、验证、测试框架和API,和一些常用的NLP任务示例


请注意: ZTrain仍然处于早期阶段,API很可能会继续变化。

🚀 安装

请确保你预先安装了PyTorchTransformers.

# 即将推出
pip install -U ZTrain

或者

# 目前推荐
git clone https://github.com/cyberfish1120/ZTrain.git && cd ZTrain
pip install -e . --verbose

“-e”表示“可编辑”模式,这样你就不用每次修改都重新安装了

⚡ 快速上手

一个简单的例子

import torch

from ZTrain.training import Trainer
from ZTrain.training.callbacks import EarlyStopping

from model import MyModel
from metric import metric
from config import arg_parse
from prepare_dataset import PrepareDataset, MyDataset

args = arg_parse()

train_data_raw = PrepareDataset(file=None)

train_data = MyDataset(train_data_raw)

dev_data_raw = PrepareDataset(file=None)
test_data_raw = PrepareDataset(file=None)

model = MyModel()
optimizer = torch.optim.SGD(model.parameters(), args.learning_rate)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=100, gamma=0.5)

trainer = Trainer(model, optimizer=optimizer, scheduler=scheduler, metric=metric, device=args.device)
callbacks = EarlyStopping(monitor='loss', patience=3)
trainer.fit(train_data, dev_data_raw, args.batch_size, args.epochs, callbacks=callbacks)
trainer.evaluate(test_data_raw)
# trainer.predict(test_data_raw)

👀 更新

ztrain's People

Contributors

cyberfish1120 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.