项目作者: nlpodyssey

项目描述 :
Self-contained Machine Learning and Natural Language Processing library in Go
高级语言: Go
项目地址: git://github.com/nlpodyssey/spago.git
创建时间: 2020-01-05T20:39:29Z
项目社区:https://github.com/nlpodyssey/spago

开源协议:BSD 2-Clause "Simplified" License

下载









Build


Coverage


Go Report Card


Maintainability


Documentation


License


PRs Welcome


Awesome Go




If you like the project, please ★ star this repository to show your support! 🤩



15 Jan 2024 - As I reflect on the journey of Spago, I am filled with gratitude for the enriching experience it has provided me. Mastering Go and revisiting the fundamentals of Deep Learning through Spago has been immensely rewarding. The unique features of Spago, especially its asynchronous computation graph and focusing on clean coding, have made it an extraordinary project to work on. Our goal was to create a minimalist ML framework in Go, eliminating the dependency on Python in production by enabling the creation of standalone executables. This approach of Spago successfully powered several of my projects in challenging production environments.

However, the endeavor to elevate Spago to a level where it can compete effectively in the evolving ‘AI space’, which now extensively involves computation on GPUs, requires substantial commitment. At the same time, the vision that Spago aspired to achieve is now being impressively realized by the Candle project in Rust. With my limited capacity to dedicate the necessary attention to Spago, and in the absence of a supporting maintenance team, I have made the pragmatic decision to pause the project for now.

I am deeply grateful for the journey Spago has taken me on and for the community that has supported it. As we continue to explore the ever-evolving field of machine learning, I look forward to the exciting developments that lie ahead.

Warm regards,

Matteo Grella


Spago is a Machine Learning library written in pure Go designed to support relevant neural architectures in Natural
Language Processing
.

Spago is self-contained, in that it uses its own lightweight computational graph both for training and
inference, easy to understand from start to finish.

It provides:

  • Automatic differentiation via dynamic define-by-run execution
  • Feed-forward layers (Linear, Highway, Convolution…)
  • Recurrent layers (LSTM, GRU, BiLSTM…)
  • Attention layers (Self-Attention, Multi-Head Attention…)
  • Gradient descent optimizers (Adam, RAdam, RMS-Prop, AdaGrad, SGD)
  • Gob compatible neural models for serialization

If you’re interested in NLP-related functionalities, be sure to explore the Cybertron package!

Usage

Requirements:

Clone this repo or get the library:

  1. go get -u github.com/nlpodyssey/spago

Getting Started

A good place to start is by looking at the implementation of built-in neural models, such as the LSTM.

Example 1

Here is an example of how to calculate the sum of two variables:

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "github.com/nlpodyssey/spago/ag"
  6. "github.com/nlpodyssey/spago/mat"
  7. )
  8. func main() {
  9. // define the type of the elements in the tensors
  10. type T = float32
  11. // create a new node of type variable with a scalar
  12. a := mat.Scalar(T(2.0), mat.WithGrad(true)) // create another node of type variable with a scalar
  13. b := mat.Scalar(T(5.0), mat.WithGrad(true)) // create an addition operator (the calculation is actually performed here)
  14. c := ag.Add(a, b)
  15. // print the result
  16. fmt.Printf("c = %v (float%d)\n", c.Value(), c.Value().Item().BitSize())
  17. c.AccGrad(mat.Scalar(T(0.5)))
  18. if err := ag.Backward(c); err != nil {
  19. log.Fatalf("error during Backward(): %v", err)
  20. }
  21. fmt.Printf("ga = %v\n", a.Grad())
  22. fmt.Printf("gb = %v\n", b.Grad())
  23. }

Output:

  1. c = [7] (float32)
  2. ga = [0.5]
  3. gb = [0.5]

Example 2

Here is a simple implementation of the perceptron formula:

  1. package main
  2. import (
  3. "fmt"
  4. . "github.com/nlpodyssey/spago/ag"
  5. "github.com/nlpodyssey/spago/mat"
  6. )
  7. func main() {
  8. x := mat.Scalar(-0.8)
  9. w := mat.Scalar(0.4)
  10. b := mat.Scalar(-0.2)
  11. y := Sigmoid(Add(Mul(w, x), b))
  12. fmt.Printf("y = %0.3f\n", y.Value().Item())
  13. }

Contributing

If you think something is missing or could be improved, please open issues and pull requests.

To start contributing, check the Contributing Guidelines.

Contact

We highly encourage you to create an issue as it will contribute to the growth of the community. However, if you prefer to communicate with us privately, please feel free to email Matteo Grella with any questions or comments you may have.