distilbert multilingual nli stsb quora ranking

sentence-transformers

Introduction
The DistilBERT-Multilingual-NLI-STSB-Quora-Ranking model is part of the Sentence-Transformers library, designed to map sentences and paragraphs to a 768-dimensional dense vector space. This enables tasks such as clustering and semantic search.

Architecture
The model is structured with a SentenceTransformer that includes a Transformer model based on DistilBertModel, configured with a maximum sequence length of 128. It utilizes mean pooling for generating sentence embeddings, with a word embedding dimension of 768. Pooling operations are adjustable, but the current configuration employs mean token pooling.

Training
This model was developed by the Sentence-Transformers group. For training insights and methodologies, refer to their publication "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks."

Guide: Running Locally
To run the model locally, you can use the Sentence-Transformers library or Hugging Face's Transformers library.

  1. Install Sentence-Transformers

    pip install -U sentence-transformers
    
  2. Load and Use the Model

    from sentence_transformers import SentenceTransformer
    sentences = ["This is an example sentence", "Each sentence is converted"]
    model = SentenceTransformer('sentence-transformers/distilbert-multilingual-nli-stsb-quora-ranking')
    embeddings = model.encode(sentences)
    print(embeddings)
    
  3. Using Hugging Face Transformers

    from transformers import AutoTokenizer, AutoModel
    import torch
    
    def mean_pooling(model_output, attention_mask):
        token_embeddings = model_output[0] 
        input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
        return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
    
    sentences = ['This is an example sentence', 'Each sentence is converted']
    tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/distilbert-multilingual-nli-stsb-quora-ranking')
    model = AutoModel.from_pretrained('sentence-transformers/distilbert-multilingual-nli-stsb-quora-ranking')
    encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
    
    with torch.no_grad():
        model_output = model(**encoded_input)
    
    sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
    print("Sentence embeddings:")
    print(sentence_embeddings)
    

Consider utilizing cloud GPU services such as AWS, Google Cloud, or Azure for efficient model execution.

License
This model is licensed under the Apache-2.0 License, allowing for both personal and commercial use.

More Related APIs in Sentence Similarity