Giter Club home page Giter Club logo

js-maxent's Introduction

js-maxent

A JavaScript (ES6) implementation of a proof-of-concept maximum-entropy (MaxEnt) classifier. When trained on a set of examples, it learns feature weights for classifying inputs with a predicted label (e.g. "Chicago, Illinois" => "place").

This implementation is based on a more complex Java architecture found in an assignment from Statistical Natural Language Processing Fall 2017 at NYU's Courant Institute.

The library is lightweight enough to use stored weights to classify –– or even run the perceptron to train –– from the DOM.

TODOs:

  • Create an averaged-perceptron trainer
  • Create, or adapt, a BFGS gradient descent trainer

Sample invocation:

const maxent = require("./maxent.js")
const fs = require("fs")

t = new maxent.Translator()

var training = JSON.parse(fs.readFileSync("./data/train.json")).map( (elem) => { return new maxent.LabeledDatum(elem[1],elem[0])})
var encoded_training = training.map( (elem) => { return new maxent.EncodedDatum(elem,t) })

// Randomize the order of the training data
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5)
encoded_training = shuffleArray(encoded_training)

// Learn weights with the simple perceptron
var cw = maxent.Perceptron.train(t, encoded_training, 1)

// Create a classifier using the weight array and the translator
var classifier = new maxent.Classifier(cw, t)

Now you can interact with the classifier like so:

console.log(classifier.predict("Chicago, Illinois"))
// This should print 'place'

console.log(classifier.scores("Chicago, Illinois"))
// This should print an array of log probabilities for the labels

js-maxent's People

Contributors

sgbalogh avatar

Stargazers

 avatar  avatar Laurence avatar

Watchers

James Cloos avatar  avatar

Forkers

neelhabib

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.