sbertimbau large nli sts

ricardo-filho

SBERTIMBAU-LARGE-NLI-STS

Introduction

SBERTIMBAU-LARGE-NLI-STS is a sentence-transformers model that maps sentences and paragraphs to a 1024-dimensional dense vector space. It is useful for tasks such as clustering and semantic search.

Architecture

The model is based on the SentenceTransformer architecture, which includes:

  • A transformer model, specifically a BertModel, with a configuration of max_seq_length set to 64 and do_lower_case set to False.
  • A pooling layer that performs mean pooling on the token embeddings.

Training

The model was trained using a DataLoader with a batch size of 16, utilizing a random sampler. The training process involved:

  • A loss function: CosineSimilarityLoss.
  • Training for 4 epochs.
  • An optimizer: AdamW, with a learning rate of 2e-05.
  • A WarmupLinear scheduler with 143 warmup steps.
  • A weight decay of 0.01.

Guide: Running Locally

To use SBERTIMBAU-LARGE-NLI-STS locally, follow these steps:

Using Sentence-Transformers

  1. Install the library:
    pip install -U sentence-transformers
    
  2. Use the model:
    from sentence_transformers import SentenceTransformer
    
    model = SentenceTransformer('{MODEL_NAME}')
    sentences = ["This is an example sentence", "Each sentence is converted"]
    embeddings = model.encode(sentences)
    print(embeddings)
    

Using Hugging Face Transformers

  1. Install the transformers library and torch:
    pip install transformers torch
    
  2. Use the model:
    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)
    
    tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
    model = AutoModel.from_pretrained('{MODEL_NAME}')
    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)
    

Suggestion

For better performance, consider using cloud GPUs such as those available on AWS, Google Cloud, or Azure.

License

The specific licensing details for SBERTIMBAU-LARGE-NLI-STS should be checked on the model's homepage or repository for compliance and usage rights.

More Related APIs in Sentence Similarity