Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nlpodyssey/spago
Self-contained Machine Learning and Natural Language Processing library in Go
https://github.com/nlpodyssey/spago
artificial-intelligence automatic-differentiation automatic-translation bart bert bert-as-service computation-graph deep-learning deeplearning language-model lstm machine-learning named-entities-recognition natural-language-processing neural-network nlp question-answering recurrent-networks transformer-architecture
Last synced: 4 days ago
JSON representation
Self-contained Machine Learning and Natural Language Processing library in Go
- Host: GitHub
- URL: https://github.com/nlpodyssey/spago
- Owner: nlpodyssey
- License: bsd-2-clause
- Created: 2020-01-05T20:39:29.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-19T18:10:02.000Z (22 days ago)
- Last Synced: 2025-01-31T04:44:19.644Z (11 days ago)
- Topics: artificial-intelligence, automatic-differentiation, automatic-translation, bart, bert, bert-as-service, computation-graph, deep-learning, deeplearning, language-model, lstm, machine-learning, named-entities-recognition, natural-language-processing, neural-network, nlp, question-answering, recurrent-networks, transformer-architecture
- Language: Go
- Homepage:
- Size: 19.5 MB
- Stars: 1,769
- Watchers: 38
- Forks: 87
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Authors: AUTHORS.md
Awesome Lists containing this project
- awesome-go - spaGO - Self-contained Machine Learning and Natural Language Processing library in Go. (Natural Language Processing / Morphological Analyzers)
- awesome-golang-ai - spago - contained Machine Learning and Natural Language Processing library in Go. (General Machine Learning libraries)
- zero-alloc-awesome-go - spaGO - Self-contained Machine Learning and Natural Language Processing library in Go. (Natural Language Processing / Morphological Analyzers)
- awesome-go - spaGO - Self-contained Machine Learning and Natural Language Processing library in Go. Stars:`1.8K`. (Natural Language Processing / Morphological Analyzers)
- awesome-go-extra - spago - contained Machine Learning and Natural Language Processing library in Go|1222|69|11|2020-01-05T20:39:29Z|2022-08-01T11:49:22Z| (Bot Building / Morphological Analyzers)
README
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](https://github.com/huggingface/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 serializationIf you're interested in NLP-related functionalities, be sure to explore the [Cybertron](https://github.com/nlpodyssey/cybertron) package!
## Usage
Requirements:
* [Go 1.21](https://golang.org/dl/)
Clone this repo or get the library:
```console
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:```go
package mainimport (
"fmt"
"log""github.com/nlpodyssey/spago/ag"
"github.com/nlpodyssey/spago/mat"
)func main() {
// define the type of the elements in the tensors
type T = float32// create a new node of type variable with a scalar
a := mat.Scalar(T(2.0), mat.WithGrad(true)) // create another node of type variable with a scalar
b := mat.Scalar(T(5.0), mat.WithGrad(true)) // create an addition operator (the calculation is actually performed here)
c := ag.Add(a, b)// print the result
fmt.Printf("c = %v (float%d)\n", c.Value(), c.Value().Item().BitSize())c.AccGrad(mat.Scalar(T(0.5)))
if err := ag.Backward(c); err != nil {
log.Fatalf("error during Backward(): %v", err)
}fmt.Printf("ga = %v\n", a.Grad())
fmt.Printf("gb = %v\n", b.Grad())
}
```Output:
```console
c = [7] (float32)
ga = [0.5]
gb = [0.5]
```### Example 2
Here is a simple implementation of the perceptron formula:
```go
package mainimport (
"fmt"
. "github.com/nlpodyssey/spago/ag"
"github.com/nlpodyssey/spago/mat"
)func main() {
x := mat.Scalar(-0.8)
w := mat.Scalar(0.4)
b := mat.Scalar(-0.2)y := Sigmoid(Add(Mul(w, x), b))
fmt.Printf("y = %0.3f\n", y.Value().Item())
}
```## Contributing
If you think something is missing or could be improved, please open issues and pull requests.
To start contributing, check the [Contributing Guidelines](https://github.com/nlpodyssey/spago/blob/main/CONTRIBUTING.md).
## 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](mailto:[email protected]) with any questions or comments you may have.