Skip to content

Commit

Permalink
Expose show_progress_bar (#236)
Browse files Browse the repository at this point in the history
Address #232

Now **kwargs are being passed from `hf.embed()` and `hf.embed_many()` to
the underlying `model.encode()`

```
from redisvl.utils.vectorize import HFTextVectorizer
from tqdm.auto import tqdm
hf = HFTextVectorizer(model="sentence-transformers/all-MiniLM-L6-v2")
# Embed a sentence
test = hf.embed("This is a test sentence.", show_progress_bar=True) #progress bar would show
test = hf.embed("This is a test sentence.") #progress bar would show (default behavior as before)
test = hf.embed("This is a test sentence.", show_progress_bar=False) #progress bar would NOT show

# Uncomment to see vector embedding output
print(test[:10])
```
  • Loading branch information
antonum authored Oct 11, 2024
1 parent 376742a commit bdef909
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions redisvl/utils/vectorize/text/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def embed(

if preprocess:
text = preprocess(text)
embedding = self._client.encode([text])[0]
embedding = self._client.encode([text], **kwargs)[0]
return self._process_embedding(embedding.tolist(), as_buffer, **kwargs)

def embed_many(
Expand Down Expand Up @@ -135,7 +135,7 @@ def embed_many(

embeddings: List = []
for batch in self.batchify(texts, batch_size, preprocess):
batch_embeddings = self._client.encode(batch)
batch_embeddings = self._client.encode(batch, **kwargs)
embeddings.extend(
[
self._process_embedding(embedding.tolist(), as_buffer, **kwargs)
Expand Down

0 comments on commit bdef909

Please sign in to comment.