Skip to content

Commit af7b04f

Browse files
committed
Updated example [skip ci]
1 parent 4998aa1 commit af7b04f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

examples/colpali/exact.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@
3737

3838
def generate_embeddings(processed):
3939
with torch.no_grad():
40-
return model(**processed.to(model.device)).to(device='cpu', dtype=torch.float32)
40+
return model(**processed.to(model.device))
4141

4242

4343
def binary_quantize(embedding):
44-
return Bit(embedding > 0)
44+
return Bit(embedding.gt(0).numpy(force=True))
4545

4646

4747
input = load_dataset('vidore/docvqa_test_subsampled', split='test[:3]')['image']
4848
for content in input:
49-
embeddings = [binary_quantize(e.numpy()) for e in generate_embeddings(processor.process_images([content]))[0]]
49+
embeddings = [binary_quantize(e) for e in generate_embeddings(processor.process_images([content]))[0]]
5050
conn.execute('INSERT INTO documents (embeddings) VALUES (%s)', (embeddings,))
5151

5252
query = 'dividend'
53-
query_embeddings = [binary_quantize(e.numpy()) for e in generate_embeddings(processor.process_queries([query]))[0]]
53+
query_embeddings = [binary_quantize(e) for e in generate_embeddings(processor.process_queries([query]))[0]]
5454
result = conn.execute('SELECT id, max_sim(embeddings, %s) AS max_sim FROM documents ORDER BY max_sim DESC LIMIT 5', (query_embeddings,)).fetchall()
5555
for row in result:
5656
print(row)

0 commit comments

Comments
 (0)