Giter Club home page Giter Club logo

unf's Introduction

Introduction

UNF(Universal NLP Framework) is built on pytorch and torchtext. Its design philosophy is:

  • modularity: specifically, on the one hand, it is convenient to quickly run some nlp-related tasks; on the other hand, it is convenient for secondary development and research to implement some new models or technologies.
  • efficiency: supports distributed training and half-precision training, which is convenient for quickly training the model, although the current support is relatively crude
  • comprehensive: support pytorch trace into static graph, support c ++ server, provide web-server for debugging tools

Support Tasks

Now, support text classification and sequence labeling related tasks.

Related Papers

  • Convolutional Neural Networks for Sentence Classification 2014
  • Bag of Tricks for Efficient Text Classification 2016
  • Deep Pyramid Convolutional Neural Networks for Text Categorization 2017, ACL
  • Hierarchical Attention Networks for Document Classification 2017, ACL
  • A STRUCTURED SELF-ATTENTIVE SENTENCE EMBEDDING 2017,ICLR
  • Joint Embedding of Words and Labels for Text Classification2018,ACL
  • Neural Architectures for Named Entity 2016,ACL
  • Semi-supervised Multitask Learning for Sequence Labeling 2017, ACL

Framwork

image

Module relation

Module name Module function
UNF.data Load data from disk to RAM, include batch, padding,numerical
UNF.module Neural network layer, include encoder, decoder, embedding, provided for use by the model
UNF.model Neural network model structure, include DpCnn, SelAttention,Lstm-crf..and python predictor for those models
UNF.training Model training, include early stopping, model save and reload, visualize metrics throuth Tensorboard
UNF.tracing Trace pytorch dynamic graph to static graph, and provide c++ serving
UNF.web_server Web server tool related

Requirement

python3

pip3 install -r requirement.txt

Training

#quick start
python3 train_flow.py

Only 5 line code need

#data loader
data_loader = DataLoader(data_loader_conf)
train_iter, dev_iter, test_iter = data_loader.generate_dataset()

#model loader
model, model_conf = ModelLoader.from_params(model_conf, data_loader.fields)

#learner loader
learner = LearnerLoader.from_params(model, train_iter, dev_iter, learner_conf, test_iter=test_iter, fields=data_loader.fields, model_conf=model_conf)

#learning
learner.learn()

train_flow.py is the demo code for training,Run directly!!

conf for multu-gpu and mixed precision

"use_fp16": False,
"multi_gpu": False

tensorboard demo

image image

Python inference

#quick start
python3 score_flow.py
#core code
from models.predictor import Predictor

predictor = Predictor(model_path, device, model_type)
logits = predictor.predict(input)

(0.18, -0.67)

C++ inference

step1: Trace dynamic graph to static graph

#quick start
python3 trace.py
#core code
net = globals()[model_cls](**config.__dict__)
net.load_state_dict_trace(torch.load("%s/best.th" % model_path))
net.eval()

mock_input = net.mock_input_data()
tr = torch.jit.trace(net, mock_input)
tr.save("trace/%s" % save_path)

step2: c++ serving

  • install cmake
  • download libtorch and unzip to trace folder
cd trace
cmake -DCMAKE_PREFIX_PATH=libtorch .

image

make

image

./predict trace.pt predict_vocab.txt
output: 2.2128 -2.3287

RESTFUL-API web demo

cd web_server
python run.py

image

unf's People

Contributors

waterzxj avatar

Watchers

James Cloos 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.