GithubHelp home page GithubHelp logo

silky / nlp.intent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sorpaas/nlp.intent

0.0 2.0 0.0 26 KB

An open source NLP library for recognizing intent and slots. Mirror of https://source.id.hn/diffusion/NLPI/

License: GNU General Public License v3.0

Clojure 100.00%

nlp.intent's Introduction

nlp.intent

nlp.intent (Project Page, Github Mirror) is an open source wit.ai alternative for natural language processing. It can be used to recognize intent and slots. For example, in a meeting schedule application, "Can you help schedule a 30 minute slot for us tomorrow?" can be regarded as a sentence with intent schedule meeting, a duration slot 30 minute and a time slot tomorrow.

The project is written in Clojure. It is in its very early stage. Things work, but all are subject to change. Submit an issue.

Usage

In Leiningen or Boot, add nlp.intent as a dependency:

[nlp.intent "0.0.1-SNAPSHOT"]

The thing for classifying intent and slots is called "rater". Create a rater:

(require '[nlp.intent :as intent])
(def my-rater (intent/new-rater))

Add a new type to the rater. A type is a Clojure vector where its first element is a name, and the rest of its elements are slot types. According to CoreNLP (which nlp.intent used under the hood), supported types are :money, :time, :date, :percent, :number, :ordinal, :duration, :person, :organization, and :location.

(intent/add-type my-rater [:schedule-meeting :duration])

Then we can train the rater. Note that you need at least 6 samples to make the rater return any result.

(intent/train my-rater :schedule-meeting "Can you schedule a 30 minute slot for us tomorrow?")
(intent/train my-rater :schedule-meeting "Please help schedule a 45 minute time for us on Wednesday.")
(intent/train my-rater :schedule-meeting "Can you help schedule a 1 hour slot for us the
                                          day after tomorrow?")
(intent/train my-rater :schedule-meeting "Would you please schedule a 30 minute slot for us tomorrow?")
(intent/train my-rater :schedule-meeting "Schedule a 30 minute slot for us tomorrow, please")
(intent/train my-rater :schedule-meeting "Hey, please schedule a 30 minute slot for us tomorrow")
(intent/train my-rater :schedule-meeting "Would you mind scheduling a 30 minute slot for us tomorrow?")

After training, you must sync to update the internal classifier. You can train and sync a rater multiple times.

(intent/sync my-rater)

And finally we can classify a sentence. The function rate returns a vector where its first element is the classified type name (the intent), and its rest of elements are slot instances (strings) which order is the same as when you define the type using add-type. If a slot is not found in a sentence, that place will be set to nil.

(intent/rate my-rater "Could you help schedule a 30 minutes slot for us on Thursday?")
; => [:schedule-meeting "30 minutes"]

That's it. Have fun building your own customized meeting scheduler and lunch organizer!

Under the Hood

nlp.intent uses CoreNLP's Named Entity Recognition for recognizing slots, and OpenNLP's Doccat model for recognizing intent.

Limitation

For now, nlp.intent is in its very early stage, so it may not be as accurate as you want it to be. Each slot types can only be used once in a rater type. So only [:schedule-meeting :duration :date :time] would work, but not [:schedule-meeting :duration :duration :date :time].

Examples

A slackbot example can be found in the examples folder.

Contribution

The project is managed in a Phabricator instance. For issues, submit one here. For patches, use arc diff to submit revisions.

License

Copyright © 2016 Wei Tang

Distributed under the GNU General Public License either version 3.0 or (at your option) any later version.

nlp.intent's People

Watchers

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