Skip to content

hupe1980/go-huggingface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤗 go-huggingface

Build Status Go Reference

The Hugging Face Inference Client in Golang is a modul designed to interact with the Hugging Face model repository and perform inference tasks using state-of-the-art natural language processing models. Developed in Golang, it provides a seamless and efficient way to integrate Hugging Face models into your Golang applications.

Installation

go get github.com/hupe1980/go-huggingface

How to use

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/hupe1980/go-huggingface"
)

func main() {
	ic := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN"))

	res, err := ic.ZeroShotClassification(context.Background(), &huggingface.ZeroShotClassificationRequest{
		Inputs: []string{"Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"},
		Parameters: huggingface.ZeroShotClassificationParameters{
			CandidateLabels: []string{"refund", "faq", "legal"},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(res[0].Sequence)
	fmt.Println("Labels:", res[0].Labels)
	fmt.Println("Scores:", res[0].Scores)
}

Output:

Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!
Labels: [refund faq legal]
Scores: [0.8777876496315002 0.10522633790969849 0.016985949128866196]

For more example usage, see _examples.

License

MIT