quora distilbert base

sentence-transformers

Introduction

The Quora DistilBERT Base model is part of the Sentence-Transformers library, which maps sentences and paragraphs into a 768-dimensional dense vector space. This model can be utilized for various tasks, including clustering and semantic search. It offers seamless integration with the Sentence-Transformers library and can also be used with the Hugging Face Transformers library.

Architecture

The Quora DistilBERT Base model is built using the SentenceTransformer framework. It consists of two main components:

  • Transformer: Configured with a maximum sequence length of 128 and case-sensitive input.
  • Pooling: Utilizes mean token pooling with a word embedding dimension of 768 to generate sentence embeddings.

Training

The model is trained by Sentence-Transformers and is based on the DistilBERT architecture. It leverages the Sentence-BERT approach, which utilizes Siamese BERT-Networks for generating sentence embeddings.

Guide: Running Locally

To run the model locally, follow these steps:

  1. Install Sentence-Transformers Library:
    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-base')
    embeddings = model.encode(sentences)
    print(embeddings)
    

Alternatively, the model can be used with 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/quora-distilbert-base')
model = AutoModel.from_pretrained('sentence-transformers/quora-distilbert-base')

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)

Recommendation: Use cloud-based GPUs from providers like AWS or Google Cloud for faster inference and training.

License

The Quora DistilBERT Base model is released under the Apache 2.0 License. This permits usage, distribution, and modification, provided that the license terms are met.

More Related APIs in Sentence Similarity