Skip to content
Gammer0909Public

About

Various Machine Learning Projects, written in Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

ML-Go

This is a grouping of various Machine Learning projects (and tools) written all in go.

Here is a list of the current projects for quick reference

Name Description
N-Gram A basic N-gram word generator
Vectorize A naive tf-ibf vectorizer
Sentiment-Analysis A sentiment analysis model

Installation

Simply clone the git repo:

git clone https://github.com/Gammer0909/ml-go.git

Make sure to add a main.go file, then enjoy messing around!

N-Gram

N-gram is a simple implementation of the n-gram algorithm for generating words based on previous data.

Using this project is simple, clone the repo, then in your main.go file:

n := 4
cap := 100
model := ngram.NewModel(trainingText, n)
fmt.Println(model.Generate(strings.Fields("This is an example"), cap))

Vectorize

Vectorize is a very simple and naive vectorizer for text, using the tf-idf algorithm.

Again, using this is very simple:

documents := []string{
    "this is a document!",
    "They are different strings!", 
}

vectorized, _ := Vectorize(documents)

// optionally, should you want the Inverse Document Frequency included alongside the TF-IDF, provide a second return variable:
// vectorized, idf := Vectorize(documents)

Note: This is a very NAIVE tokenizer, so it splits by whitespace and simply strips punctuation from text!

Sentiment-Analysis

Sentiment-Analysis is a very simple Logistic Regression based model, and like the others, using it is very simple!

For training your own model:

// where documents is your training data, and labels is your "answer key" for that data
trainer := sentimentanalysis.NewTrainer(documents, labels)

epochs := 1000

trainer.Fit(epochs)

// Using a trained model:
model := trainer.Model

confidence := model.PredictText("I really love this product, it's the best!")

fmt.Println(confidence)

To load the pretrained model from JSON:

weights, err := os.ReadFile("./weights/weights.json")
if err != nil {
	fmt.Println("Error opening weights file: ", err)
	return
}

model := sentimentanalysis.FromJSON(weights)

// ... use as usual

Citations

The pretrained model was trained under the UCI Machine Learning Repository "Sentiment Labelled Sentences" Dataset, filed under the Creative Commons 4.0 International license:

Kotzias, D. (2015). Sentiment Labelled Sentences [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C57604.

I'd like to thank the creator of this dataset for making this project possible.

About

Various Machine Learning Projects, written in Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages