https://github.com/rootfs/candle-bert-go
https://github.com/rootfs/candle-bert-go
bert bert-model golang rust
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rootfs/candle-bert-go
- Owner: rootfs
- Created: 2025-04-11T19:41:36.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-04-11T20:09:59.000Z (about 2 months ago)
- Last Synced: 2025-04-11T21:24:46.976Z (about 2 months ago)
- Topics: bert, bert-model, golang, rust
- Language: Rust
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Candle BERT Go
Go bindings for the Candle machine learning framework to run BERT models with text classification capabilities.
## Overview
This project provides Go bindings for the Candle machine learning framework, allowing you to:
1. Load pre-trained BERT models
2. Classify text into multiple categories
3. Integrate into Go applications## Project Structure
```
candle-bert-go/
├── cmd/ # Go command-line applications
│ └── bert/ # BERT text classification CLI
├── examples/ # Example Go applications
│ └── simple_classification.go # Simple classification example
├── pkg/ # Go packages
│ └── classifier/ # Text classification library
├── rust/ # Rust code for Candle bindings
│ ├── src/ # Rust source files
│ └── Cargo.toml # Rust dependencies
├── scripts/ # Build and utility scripts
├── Makefile # Build automation
├── .gitignore # Git ignore rules
└── go.mod # Go module definition
```## Prerequisites
- Go 1.21+
- Rust and Cargo## Building
You can use the provided Makefile for easy building:
```bash
# Build both Rust and Go components
make# Build only the Rust library
make rust# Build only the Go application
make go# Build example applications
make examples
```## Running
Using the Makefile:
```bash
# Run the main application
make run# Run the simple classification example
make run-example
```## Using as a Library
You can use this package as a library in your own Go applications:
```go
import "github.com/rootfs/candle-bert-go/pkg/classifier"// Initialize the BERT model
success := classifier.InitBert("sentence-transformers/all-MiniLM-L6-v2", 3, true)// Classify text
classIdx := classifier.ClassifyText("Your text to classify")// Get readable class name
className := classifier.GetClassName(classIdx)
```See the `examples/` directory for more examples.
## Cleaning Up
```bash
make clean
```## Additional Makefile Commands
- `make test` - Run tests
- `make install` - Install to GOPATH/bin
- `make docs` - Generate documentation
- `make help` - Show help information## License
MIT or Apache 2.0 license.