最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Can not load the safetensors huggingface model in DJL in Java - Stack Overflow

matteradmin8PV0评论

I tried a lot, but I want to read embeddings from the jina embeddings

this is my java code:

public static float[] getTextEmbedding(String text) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
        Criteria<String, float[]> criteria = Criteria.builder()
                .setTypes(String.class, float[].class)
                .optEngine("PyTorch")
                .optModelPath(Paths.get("/jina-embeddings-v2-base-de"))
                .optTranslator(
                    TextEmbeddingTranslator
                        .builder(HuggingFaceTokenizer.newInstance(Paths.get("/jina-embeddings-v2-base-de")))
                        .build()
                )
                .optProgress(new ProgressBar())
                .optOption("trust_remote_code", "true")
                .build();

        try (Predictor<String, float[]> predictor = ModelZoo.loadModel(criteria).newPredictor()) {
            return predictor.predict(text);
        }
    }

but I keept getting this error:

java.io.FileNotFoundException: jina-embeddings-v2-base-de.pt file not found in: /jina-embeddings-v2-base-de

I tried a lot, but I want to read embeddings from the jina embeddings

this is my java code:

public static float[] getTextEmbedding(String text) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
        Criteria<String, float[]> criteria = Criteria.builder()
                .setTypes(String.class, float[].class)
                .optEngine("PyTorch")
                .optModelPath(Paths.get("/jina-embeddings-v2-base-de"))
                .optTranslator(
                    TextEmbeddingTranslator
                        .builder(HuggingFaceTokenizer.newInstance(Paths.get("/jina-embeddings-v2-base-de")))
                        .build()
                )
                .optProgress(new ProgressBar())
                .optOption("trust_remote_code", "true")
                .build();

        try (Predictor<String, float[]> predictor = ModelZoo.loadModel(criteria).newPredictor()) {
            return predictor.predict(text);
        }
    }

but I keept getting this error:

java.io.FileNotFoundException: jina-embeddings-v2-base-de.pt file not found in: /jina-embeddings-v2-base-de
Share Improve this question asked Nov 16, 2024 at 0:04 Richard BurkhardtRichard Burkhardt 8839 silver badges25 bronze badges 2
  • What files are there in your /jina-embeddings-v2-base-de folder? Can you try to convert the model using djl-convert – Frank Liu Commented Dec 3, 2024 at 6:52
  • Converting would work, but since I want to experiment with different models, I hoped I could somehow get it to work like this. The base folder is basically the repo, which is linked in my post. – Richard Burkhardt Commented Dec 4, 2024 at 11:28
Add a comment  | 

1 Answer 1

Reset to default 0

djl-convert can convert local model into DJL format as well:

djl-convert -m /jina-embeddings-v2-base-de

Then you can point to model/jina-embeddings-v2-base-de folder in Java code. You will find the following files in the folder:

  • jina-embeddings-v2-base-de.pt
  • config.json
  • serving.properties
  • tokenizer_config.json
  • tokenizer.json
Post a comment

comment list (0)

  1. No comments so far