Spaces:
Paused
Paused
File size: 777 Bytes
f392320 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from sentence_transformers import SentenceTransformer
class SentenceBertEncoder:
def __init__(self):
self.model = SentenceTransformer('all-MiniLM-L6-v2')
def encode(self, sentences):
#Our sentences we like to encode
# sentences = ['This framework generates embeddings for each input sentence',
# 'Sentences are passed as a list of string.',
# 'The quick brown fox jumps over the lazy dog.']
#Sentences are encoded by calling model.encode()
embeddings = self.model.encode(sentences)
# print(embeddings.shape)
return embeddings
if __name__ == "__main__":
sentence_encoder = SentenceBertEncoder()
embedding = sentence_encoder.encode(["this is cool!"])
print(embedding.shape) |