Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Cybertron compatible with nomic-ai models? #44

Open
faelp22 opened this issue Oct 31, 2024 · 0 comments
Open

Is Cybertron compatible with nomic-ai models? #44

faelp22 opened this issue Oct 31, 2024 · 0 comments

Comments

@faelp22
Copy link

faelp22 commented Oct 31, 2024

Hello everyone, how are you?

Cybertron is compatible with the nomic-ai/nomic-embed-text-v1.5 model. Does anyone have an example of how I can use it?

I adapted this example to use the model


import (
	"bufio"
	"context"
	"fmt"
	"io"
	"os"

	"github.com/nlpodyssey/cybertron/pkg/models/bert"
	"github.com/nlpodyssey/cybertron/pkg/tasks"
	"github.com/nlpodyssey/cybertron/pkg/tasks/textencoding"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

const limit = 10 // number of dimensions to show

// https://github.com/nlpodyssey/cybertron/tree/main/examples/textencoding

func main() {

	zerolog.SetGlobalLevel(zerolog.DebugLevel)

	modelsDir := "llms"
	modelName := "nomic-ai/nomic-embed-text-v1.5"

	m, err := tasks.Load[textencoding.Interface](&tasks.Config{ModelsDir: modelsDir, ModelName: modelName})
	if err != nil {
		log.Fatal().Err(err).Send()
	}

	fn := func(text string) error {
		result, err := m.Encode(context.Background(), text, int(bert.MeanPooling))
		if err != nil {
			return err
		}
		fmt.Println(result.Vector.Data().F64()[:limit])
		return nil
	}

	err = ForEachInput(os.Stdin, fn)
	if err != nil {
		log.Fatal().Err(err).Send()
	}
}

// ForEachInput calls the given callback function for each line of input.
func ForEachInput(r io.Reader, callback func(text string) error) error {
	scanner := bufio.NewScanner(r)
	for {
		fmt.Print("> ")
		scanner.Scan()
		text := scanner.Text()
		if text == "" {
			break
		}
		if err := callback(text); err != nil {
			return err
		}
	}
	return nil
}

Logs

{"level":"debug","file":"llms/nomic-ai/nomic-embed-text-v1.5/config.json","time":"2024-10-31T16:21:52-03:00","message":"model file already exists, skipping download"}
{"level":"fatal","error":"unsupported model type for download: \"nomic_bert\"","time":"2024-10-31T16:21:52-03:00"}

However, it is giving an error, I don't understand very well.

thank you for your attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant