GithubHelp home page GithubHelp logo

model2module-template's Introduction

Model2Module Template

Deploy your trained deep learning models for NLP as simple python module.

Note: Only applicable for NLP models trained using Keras

Quickstart

Create an instance of ModelTemplate and initialize it with the path of the following files:

  • json_file - the .json file that contains the structure of your deep neural network model
  • weight_file - the file containing the weights of your trained model
  • words_file - a .tsv file containing a list of your word tokens. The first column should be the index of each word followed by the actual word tokens
  • classes_file - a .tsv file containing a list of the class labels used on your model. You can include multiple labels by creating multiple columns. The first row will be the headers which will be later used to switch between different class labels.

Below is a sample code using a machine learing model trained for emotion classification:

from model2module.models import ModelTemplate

dataset = [
    "Nakakaasar nman! ahhh... ang dami dami kong gagawin... kulang time...",
    "Asar... Badtrip!",
    "May bagong bagyo ang namataan sa kanlurang bahagi ng bansa.",
    "Thank you po Lord Jesus at gumana din sya.",
    "Congrats po sa inyong lahat!",
]

json_file='C:/location/of/model/json_file.json',
weight_file='C:/location/of/model/weight_file.h5',
words_file='C:/location/of/model/words.tsv',
classes_file='C:/location/of/model/classes.tsv'

model = ModelTemplate(json_file=json_file, weight_file=weight_file,
                       words_file=words_file, classes_file=classes_file)
pred = model.predict_dataset(dataset, output_type='emotion')
print(pred)

You can set raw_output=True in the ModelTemplate.predict_dataset() function to retrieve output in vector form.

Below is what classes_file.tsv looks like. The first row contains the header which can be used in the output_type parameter of the ModelTemplate.predict_dataset() function

index	emoji	emotion	sentiment
0	๐Ÿ“	neutral	neutral
1	๐Ÿ˜„	happy	positive
2	๐Ÿ˜Œ	relief	positive
3	๐Ÿ˜‘	unammused	negative
4	๐Ÿ˜˜	love	positive
5	๐Ÿ˜œ	playful	positive
6	๐Ÿ˜ž	sad	negative
7	๐Ÿ˜ก	angry	negative
8	๐Ÿ˜ฑ	shocked	negative
9	๐Ÿ˜ท	sick	negative
10	๐Ÿค”	pondering	neutral

The file words_file.tsv looks like this. The first column contains the indexes of the tokens followed by the actual words.

1	aacts
2	aad
3	aada
4	aadal
5	aadalan
6	aadapt
7	aadc
8	aadd
9	aaddict
10	aadfghjkl

model2module-template's People

Contributors

atmarges 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.