davidberenstein1957 / classy-classification

This repository contains an easy and intuitive approach to few-shot classification using sentence-transformers or spaCy models, or zero-shot classification with Huggingface.
MIT License
209 stars 15 forks source link

Hugginng face models #6

Closed nsankar closed 2 years ago

nsankar commented 2 years ago

@davidberenstein1957 Thanks for developing this interesting and great library.

I was able to test the working with the sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 model.

Can you recommend any other smaller models that works faster as well as with a good accuracy?

Thanks in advance.

davidberenstein1957 commented 2 years ago

Depends on the usecase and language. However, you can also download my package fast-sentence-transformers and use it in combination with classy-classification. I will release this implementation later.

from classy_classification import classyClassifier

from fast_sentence_transformers import FastSentenceTransformer as SentenceTransformer

__all__ = ["SentenceTransformer"]

class FastClassyClassifier(classyClassifier):
    def __init__(self, embedding_model, *args, **kwargs):
        self.embedding_model = embedding_model
        super().__init__(*args, **kwargs)

    def set_embedding_model(self, model: str = None, device: str = "cpu"):
        self.model = model
        self.device = device
        pass
davidberenstein1957 commented 2 years ago

This should result in a x5 speedup on CPU.

nsankar commented 2 years ago

@davidberenstein1957 appreciate your response.

davidberenstein1957 commented 2 years ago

@nsankar note that you should initialize the classifier with the fast_sentence_transformer embedding model.

davidberenstein1957 commented 2 years ago

Also, you can find a model overview here. https://www.sbert.net/docs/pretrained_models.html

nsankar commented 2 years ago

Ok. Thanks

davidberenstein1957 commented 2 years ago

@nsankar I added the speed feature.