🚀 Siamese Network Model for Zero-Shot and Few-Shot Text Classification
This is a Siamese network model trained for zero-shot and few-shot text classification. It maps sentences and paragraphs to a 768-dimensional dense vector space, offering a powerful solution for text-related tasks.
🚀 Quick Start
Prerequisites
The base model is mpnet-base, and it was trained on SNLI and MNLI.
Model Features
- Sentence Embedding: It's a sentence-transformers model, capable of transforming sentences and paragraphs into 768-dimensional dense vectors.
- Versatile Use Cases: Suitable for zero-shot classification, sentence similarity, feature extraction, and more.
📦 Installation
To use this model, you need to install sentence-transformers. You can install it using the following command:
pip install -U sentence-transformers
💻 Usage Examples
Basic Usage with Sentence-Transformers
Once you have sentence-transformers installed, using the model is straightforward:
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('{MODEL_NAME}')
embeddings = model.encode(sentences)
print(embeddings)
Advanced Usage with HuggingFace Transformers
If you don't have sentence-transformers installed, you can still use the model. First, pass your input through the transformer model, and then apply the appropriate pooling operation on the contextualized word embeddings.
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('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
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)
📚 Documentation
Model Information
Property |
Details |
Model Type |
Siamese network model for zero-shot and few-shot text classification |
Training Data |
SNLI, MNLI |
Pipeline Tag |
sentence-similarity |
Tags |
zero-shot-classification, sentence-transformers, feature-extraction, sentence-similarity, transformers |