xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
11.01k stars 672 forks source link

PLEASE provide examples of how to use for vector/embeddings using non-"pipeline" syntax. #869

Closed BBC-Esq closed 1 month ago

BBC-Esq commented 1 month ago

I'm accustomed (and most people use) non-"pipeline" syntax with transformers - e.g. AutoModelFromCausalLM and from_pretained and so on?

Also, is there a way to use the sentence-transformers library with transformers.js in a similar fashion. You'll notice at this link that there's the straight transformers approach but also a way to use sentence-transformers.

Lastly, can you please provide more examples of how to use webgpu specifically with vector/embedding models like bge-small, ``allmpnet``` etc.? My goal is to create basic vector database creation/search all from within ```

SCRIPT 2 ``` Transformers.js Retrieval Example

Retrieve Relevant Passages



    


```

xenova commented 1 month ago

Here's the source code for the WebGPU embedding benchmark: https://github.com/xenova/transformers.js/blob/38a3bf6dab2265d9f0c2f613064535863194e6b9/examples/webgpu-embedding-benchmark/main.js#L166-L170

You can use the AutoModel.from_pretrained API too, and then pass the tokenized inputs in the same way as the python library. Hope that helps!