Views
No views yet
SparseEncoder(
(0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'DistilBertForMaskedLM'})
(1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)pip install -U sentence-transformers1from sentence_transformers import SparseEncoder
2
3# Download from the 🤗 Hub
4model = SparseEncoder("pulkitmehtawork/sparse-distilbert-base-uncased-python-code-lightening")
5# Run inference
6sentences = [
7 'The weather is lovely today.',
8 "It's so sunny outside!",
9 'He drove to the stadium.',
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 30522]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings, embeddings)
17print(similarities)
18# tensor([[2148.8340, 1376.2744, 850.4404],
19# [1376.2744, 2056.9260, 898.0439],
20# [ 850.4404, 898.0439, 2509.7507]])