quora distilbert multilingual

sentence-transformers

QUORA-DISTILBERT-MULTILINGUAL Model Documentation

Introduction

The quora-distilbert-multilingual model is part of the sentence-transformers library. It maps sentences and paragraphs to a 768-dimensional dense vector space, ideal for tasks like clustering or semantic search.

Architecture

The model architecture consists of a Transformer component and a Pooling layer. The Transformer utilizes the DistilBertModel with a maximum sequence length of 128. The Pooling layer is configured for mean pooling, which averages token embeddings to generate sentence embeddings.

SentenceTransformer(
  (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: DistilBertModel 
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)

Training

The model was trained by sentence-transformers. It employs techniques from the Sentence-BERT framework, enhancing BERT models with Siamese networks for generating sentence embeddings.

Guide: Running Locally

To use this model locally, you can follow either of these methods:

Using sentence-transformers Library

  1. Install package:

    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/quora-distilbert-multilingual')
    embeddings = model.encode(sentences)
    print(embeddings)
    

Using transformers Library

  1. Import libraries:

    from transformers import AutoTokenizer, AutoModel
    import torch
    
  2. Define mean pooling function:

    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)
    
  3. Load model and tokenizer:

    tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/quora-distilbert-multilingual')
    model = AutoModel.from_pretrained('sentence-transformers/quora-distilbert-multilingual')
    
  4. Tokenize and compute embeddings:

    sentences = ['This is an example sentence', 'Each sentence is converted']
    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)
    

Cloud GPUs

For performance improvements, consider using cloud-based GPU services such as AWS, Google Cloud, or Azure. These platforms offer scalable resources to expedite model inference and training tasks.

License

The model is licensed under the Apache-2.0 License. More details can be found in the model documentation on the Hugging Face platform.

More Related APIs in Sentence Similarity