package main
import (
"context"
"encoding/json"
"fmt"
"github.com/nlpodyssey/cybertron/pkg/tasks"
"github.com/nlpodyssey/cybertron/pkg/tasks/questionanswering"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"time"
)
func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
modelsDir := "models" //directory where the model will be downloaded
modelName := "deepset/bert-large-uncased-whole-word-masking-squad2" //model name for token classification in Hugging Face
m, err := tasks.Load[questionanswering.Interface](&tasks.Config{ModelsDir: modelsDir, ModelName: modelName})
if err != nil {
log.Fatal().Err(err).Send()
}
defer tasks.Finalize(m)
text := "My name is John and I live in Franc"
opts := &questionanswering.Options{
MaxCandidates: 1,
}
question := "What is the full name of the person mentioned?"
start := time.Now()
result, err := m.Answer(context.Background(), text, question, opts)
if err != nil {
fmt.Println("something are erro")
}
fmt.Println("time taken: ", time.Since(start))
//display the result in json format
fmt.Println(MarshalJSON(result))
}
func MarshalJSON(data any) string {
m, _ := json.MarshalIndent(data, "", " ")
return string(m)
}
When run the output is
{
"Answers": [
{
"Text": "full name of the person mentioned?",
"Start": 12,
"End": 46,
"Score": 1
}
]
}
I try use a questionanswering, but not work
When run the output is
but the correct is