最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论