sentiment

package module
v1.0.0-...-3aa38b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2018 License: MIT Imports: 6 Imported by: 4

README

BiDiSentiment GoDoc Build Status

Text sentiment analyser for Go and Python.

Runs on top of Tensorflow. The architecture is a bidirectional two-level character LSTM.

Happy and sad gophers

Installation of the inference module

go get gopkg.in/vmarkovtsev/BiDiSentiment.v1/...

Usage of the inference module

For every line in stdin, the command line tool prints the probability of the negative sentiment (the probability of the positive sentiment is 1 - negative).

echo "This is the worst movie I have ever seen, it sucks balls!" | sentiment 
0.9961139
echo "This is the best movie I have ever seen, just love it!" | sentiment
0.000769752

API expects string batches for performance reasons:

import "gopkg.in/vmarkovtsev/BiDiSentiment.v1"

func main() {
  session, _ := sentiment.OpenSession()
  defer session.Close()
  result, _ := sentiment.Evaluate(
    []string{"This is the best movie I have ever seen, simply love it!"},
    session)
  println(result[0])
}

Science

arch

We scan through the text by byte in both directions, and the length is constrained to 180 bytes. The training is written in Python and is based on Keras and Tensorflow. The achieved accuracy on 20% validation is 87%. The train dataset was 1.5 million tweets. The default parameters were used. The model easily overfits, so only the first 5 epochs were used.

validation

Update the model in the Go inference application by executing

go-bindata  -nomemcopy -nometadata -pkg assets -o assets/bindata.go  model.pb english.json

Contributins

...are welcome! See CONTRIBUTING.md and CODE_OF_CONDUCT.md.

License

MIT, see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(texts []string, session *tf.Session) ([]float32, error)

Evaluate analyzes the sentiment of the specified batch of texts.

func EvaluateWithProgress

func EvaluateWithProgress(texts []string, session *tf.Session,
	onBatchProcessed func(int, int)) ([]float32, error)

EvaluateWithProgress analyzes the sentiment of the specified batch of texts. onBatchProcessed callback is invoked after processing every minibatch.

func GetBatchSize

func GetBatchSize() int

GetBatchSize returns the model's minibatch size.

func GetSequenceLength

func GetSequenceLength() int

GetSequenceLength returns the maximum length of the text, Longer texts are automatically split by sentence.

func OpenSession

func OpenSession() (*tf.Session, error)

OpenSession creates the Tensorflow session which is used by Evaluate()/EvaluateWithProgress().

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL