-1

I am tring to build a Text Embedding function by BERT. It said that BERT can do text embedding. However, I cannot find the embedding function on BERT's tutorial. Here is the link I looked up: https://huggingface.co/docs/transformers/model_doc/bert Does anyone know the resource of BERT text embedding? Or are there other names that represents it? I know for OpenAI there is a function just call OpenAIEmbeddings(). I just want to find the similar function like that. Thank you!

I just want to find the similar function like OpenAIEmbeddings().

  • 1
    Welcome to Stackoverflow! Asking for recommendations might not be appropriate on the Stackoverflow (stackoverflow.com/help/how-to-ask) but it might be possible to ask the question on softwarerecs.stackexchange.com – alvas Aug 25 '23 at 16:22

1 Answers1

-1

Can you try the following:

Install the required package:

pip install -U sentence-transformers

CODE:

from sentence_transformers import SentenceTransformer
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')

# Sentences we want to encode. Example:
sentence = ['This framework generates embeddings for each input sentence']

# Sentences are encoded by calling model.encode()
embedding = model.encode(sentence)
Jeril
  • 7,858
  • 3
  • 52
  • 69