Using jina-embeddings-v3 for zero-shot-classification task
#86
by
yrayegan
- opened
I'm new to this, but I need to use jina-embeddings-v3 in transformers.js to do zero-shot-classification task. But transformers.js currently doesn't support it. Beside this, this embedding model categorized as a feature extraction model not zero-shot-classification model!
How can I use this embedding model to do zero-shot-classification task using native pipeline in transformers.js?
Hi @yrayegan , I'm also not very familiar with transformers.js, but I guess one way you could do zero-shot classification is by embedding the text and the categories and calculating similarities between their embeddings. So something like this but in transformers.js:
from transformers import AutoModel
model = AutoModel.from_pretrained("jinaai/jina-embeddings-v3", trust_remote_code=True)
text = "I need help with a loan application."
labels = ["finance", "healthcare", "sports"]
text_embedding = model.encode(text, task='classification')
label_embeddings = torch.stack([model.encode(label, task='classification') for label in labels])
scores = cosine_similarity(text_embedding, label_embeddings).squeeze()
best_label = labels[torch.argmax(scores).item()]
Thanks for the solution ๐
I'll try that, it seems to work!