https://github.com/robherley/guesslang-go
Go port of guesslang to detect programming languages with deep learning
https://github.com/robherley/guesslang-go
go tensorflow
Last synced: 4 months ago
JSON representation
Go port of guesslang to detect programming languages with deep learning
- Host: GitHub
- URL: https://github.com/robherley/guesslang-go
- Owner: robherley
- License: mit
- Created: 2023-04-20T23:45:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-01-10T18:28:18.000Z (6 months ago)
- Last Synced: 2026-01-11T05:31:33.085Z (6 months ago)
- Topics: go, tensorflow
- Language: Go
- Homepage:
- Size: 15.4 MB
- Stars: 22
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# guesslang-go 🔍
[](https://pkg.go.dev/github.com/robherley/guesslang-go)
[](https://github.com/robherley/guesslang-go/actions/workflows/test.yml)
Go port of [yoeo/guesslang](https://github.com/yoeo/guesslang). Detects programming language of source code using a deep learning model.
> [!NOTE]
> If you are looking for a library with similar functionality, try [robherley/magika-go](https://github.com/robherley/magika-go). It has a more accurate model (uses [Magika](https://securityresearch.google/magika/introduction/overview) from Google) and lighter runtime dependencies (ONNX instead of Tensorflow).
## Setup
### Dependencies
Requires [`libtensorflow`](https://www.tensorflow.org/install/lang_c) C API.
On macOS, it can be installed with homebrew:
```
brew install libtensorflow
```
Alternatively, for Linux-based systems:
```
script/install-libtensorflow
```
### Install
```
go get github.com/robherley/guesslang-go
```
See example usage in [`examples/main.go`](/example/main.go)
## Caveats
To work around some of the limitations of the Go TensorFlow bindings (and the wrapper library)[^1], the [SavedModel](https://www.tensorflow.org/guide/saved_model) is embeded in the binary and
when a [`Guesser`](https://pkg.go.dev/github.com/robherley/guesslang-go/pkg/guesser#Guesser) is initialized, it temporarily writes the model to a directory (and removes it after).
So, in order to use this package, you must at least have a writeable temporary directory that aligns with Go's [`os.TempDir()`](https://pkg.go.dev/os@go1.20.3#TempDir).
[^1]: https://github.com/galeone/tfgo/issues/44#issuecomment-841806254
## Acknowledgements
Powered by:
- [yoeo/guesslang](https://github.com/yoeo/guesslang): language model
- [tensorflow/tensorflow](https://github.com/tensorflow/tensorflow): TensorFlow
- [galeone/tfgo](https://github.com/galeone/tfgo): TensorFlow in Go
Inspired by:
- [microsoft/vscode-languagedetection](https://github.com/microsoft/vscode-languagedetection)
- [hieplpvip/guesslang-js](https://github.com/hieplpvip/guesslang-js)