sentencepiecego

package module
v0.1.98-x86-64-debian-v2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

SENTENCEPIECEGO

This is a golang interface of sentencepiece for serving. For more information, please follow google sentencepiece.

Usages

  1. Download shared library Please check sentencepiece library first with pip and spm-train. You can download v0.1.96 and v0.1.90 in releases.
sudo wget https://github.com/activezhao/sentencepiecego/releases/download/v0.1.96-x86-64/libsentencepiecego.so -P /usr/local/lib/
ldconfig
  1. Export CGO variable
export CGO_CXXFLAGS=-std=c++11
  1. Go get
go get github.com/evan176/sentencepiecego
package main

import (
        "fmt"

        "github.com/evan176/sentencepiecego"
)

func main() {
        // Load pre-trained spm model
        m, err := sentencepiecego.Load("spm.model")
        if err != nil {
                panic(err)
        }
        // Encode text to ids([]int) with spm model
        ids, err := m.Encode("test")
        if err != nil {
                panic(err)
        }
        fmt.Printf("%+v\n", ids)
        // Release model before exit
        m.Free()
}
~

References

https://github.com/google/sentencepiece

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SentencePieceProcessor

type SentencePieceProcessor struct {
	// contains filtered or unexported fields
}

func Load

func Load(path string) (*SentencePieceProcessor, error)

func (*SentencePieceProcessor) Encode

func (sp *SentencePieceProcessor) Encode(text string) ([]int, error)

func (*SentencePieceProcessor) Free

func (sp *SentencePieceProcessor) Free()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL