No description
Find a file
2025-10-22 17:26:07 -04:00
datasets initial commit of simple sentiment analysis package 2015-07-29 17:04:44 -07:00
.gitignore project: tidy up for modern go 2019-09-27 10:16:20 -04:00
bindata.go Integrate Restore() functionality back into multi-language model 2015-08-05 17:17:00 -07:00
en.go Integrate Restore() functionality back into multi-language model 2015-08-05 17:17:00 -07:00
go.mod move go module 2025-10-22 17:26:07 -04:00
go.sum move go module 2025-10-22 17:26:07 -04:00
helper.go Refactor to language modularity in progress 2015-08-05 14:20:39 -07:00
init.go This fixed RestoreModels so it compiles 2016-11-21 11:04:45 +01:00
model.go Added NoLanguage as an empty language so JSON can marshal when trying to accept it 2015-08-05 17:25:24 -07:00
README.md Fixing dead link in README.md 2017-01-09 11:53:55 +01:00
sentiment.go :shipit: refactor into modular, language based models complete 😄 2015-08-05 15:57:02 -07:00
sentiment_test.go Integrate Restore() functionality back into multi-language model 2015-08-05 17:17:00 -07:00

Sentiment

Simple, Drop In Sentiment Analysis in Golang

GoDoc wercker status

This package relies on the work done in my other package, goml, for multiclass text classification

Sentiment lets you pass strings into a function and get an estimate of the sentiment of the string (in english) using a very simple probabalistic model. The model is trained off of this dataset which is a collection of IMDB movie reviews classified by sentiment. The returned values for single word classification is the given score in {0,1}/{negative/positive} for sentiment as well as the probability on [0,1] that the word is of the expected class. For document sentiment only the class is given (floats would underflow otherwise.)

Implemented Languages

If you want to implement another language, open an issue or email me. It really is not hard (if you have a dataset.)

  • English
    • dataset: IMDB Reviews

Model

Sentiment uses a Naive Bayes classification model for prediction. There are plusses and minuses, but Naive bayes tends to do well for text classification.

Example

You can save the model trained off of the dataset to a json file using the PersistToFile(filepath string) error function so you don't have to run the training again, though it only takes about 4 seconds max.

Training, or Restoring a Pre-Trained Model:

// Train is used within the library, but you should
// usually prefer Restore because it's faster and
// you don't have to be in the project's directory
//
// model, err := sentiment.Train()

model, err := sentiment.Restore()
if err != nil {
    panic(fmt.Sprintf("Could not restore model!\n\t%v\n", err))
}

Analysis:

// get sentiment analysis summary
// in any implemented language
analysis = model.SentimentAnalysis("You're mother is an awful lady", sentiment.English) // 0

LICENSE - MIT