github.com/hupe1980/go-huggingface@v0.0.15/_examples/token_classification/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/hupe1980/go-huggingface"
    10  )
    11  
    12  func main() {
    13  	ic := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN"))
    14  
    15  	res, err := ic.TokenClassification(context.Background(), &huggingface.TokenClassificationRequest{
    16  		Inputs: "My name is Sarah Jessica Parker but you can call me Jessica.",
    17  	})
    18  	if err != nil {
    19  		log.Fatal(err)
    20  	}
    21  
    22  	for _, r := range res {
    23  		fmt.Printf("Word: %s\n", r.Word)
    24  		fmt.Printf("EntityGroup: %s\n", r.EntityGroup)
    25  		fmt.Printf("Score: %f\n", r.Score)
    26  		fmt.Printf("Start: %d\n", r.Start)
    27  		fmt.Printf("End: %d\n", r.End)
    28  		fmt.Println("::")
    29  	}
    30  }