-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
huggingface "github.com/hupe1980/go-huggingface" | ||
) | ||
|
||
func main() { | ||
ic := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN")) | ||
|
||
res, err := ic.FillMask(context.Background(), &huggingface.FillMaskRequest{ | ||
Inputs: []string{"The answer to the universe is <mask>."}, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, r := range res { | ||
fmt.Println("Sequence:", r.Sequence) | ||
fmt.Println("Score:", r.Score) | ||
fmt.Println("TokenID:", r.TokenID) | ||
fmt.Println("TokenStr", r.TokenStr) | ||
fmt.Println("---") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package gohuggingface | ||
|
||
// Request structure for the Fill Mask endpoint | ||
type FillMaskRequest struct { | ||
// (Required) a string to be filled from, must contain the [MASK] token (check model card for exact name of the mask) | ||
Inputs []string `json:"inputs"` | ||
Options Options `json:"options,omitempty"` | ||
Model string `json:"-"` | ||
} | ||
|
||
// Response structure for the Fill Mask endpoint | ||
type FillMaskResponse []struct { | ||
// The actual sequence of tokens that ran against the model (may contain special tokens) | ||
Sequence string `json:"sequence,omitempty"` | ||
|
||
// The probability for this token. | ||
Score float64 `json:"score,omitempty"` | ||
|
||
// The id of the token | ||
TokenID int `json:"token,omitempty"` | ||
|
||
// The string representation of the token | ||
TokenStr string `json:"token_str,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters