theblackcat102 / go-fasttext

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go-FastText

Golang bindings to the fasttext library. Added nearest neighbor query function

package main

import (
    "fmt"
    "github.com/k0kubun/pp"
    fasttext "github.com/theblackcat102/go-fasttext"
)

func main() {
    // Replace with the path to your .bin model file
    modelPath := "<model path>"
    model := fasttext.Open(modelPath)
    defer model.Close()

    word := "YOLO"
    mostSimilars, err := model.Neighbor(word, 10)
    if err != nil {
        fmt.Println(err)
        return
    }
    pp.Println(mostSimilars)
}

Usage

To perform a prediction on a model, use the following command

go run main.go prediction -m [model_path] [query]

For example

go run main.go predict -m ~/Downloads/ag_news.bin chicken

About

License:University of Illinois/NCSA Open Source License


Languages

Language:HTML 55.0%Language:C++ 32.1%Language:JavaScript 7.5%Language:CSS 1.6%Language:Shell 1.5%Language:Python 1.2%Language:Go 0.8%Language:Perl 0.1%Language:CMake 0.1%Language:Makefile 0.1%Language:C 0.0%