Views
No views yet
fjmgAI/reason-colBERT-210M-EuroBERTEuroBERT/EuroBERT-210mpylate.evaluation.colbert_triplet.ColBERTTripletEvaluator| Metric | Value |
|---|---|
| accuracy | 0.9732 |
pip install -U pylate1import torch
2from pylate import indexes, models, retrieve
3
4# Step 1: Load the ColBERT model and Move the model to GPU if available, otherwise use CPU
5model = models.ColBERT(
6 model_name_or_path=("fjmgAI/reason-colBERT-210M-EuroBERT", trust_remote_code=True)
7)
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
11model.to(device)
12
13# Step 2: Initialize the Voyager index
14index = indexes.Voyager(
15 index_folder="pylate-index",
16 index_name="index",
17 override=True, # This overwrites the existing index if any
18)
19
20# Step 3: Encode the documents
21documents_ids = ["1", "2", "3"]
22documents = ["document 1 text", "document 2 text", "document 3 text"]
23
24documents_embeddings = model.encode(
25 documents,
26 batch_size=32,
27 is_query=False, # Ensure that it is set to False to indicate that these are documents, not queries
28 show_progress_bar=True,
29)
30
31# Step 4: Add document embeddings to the index by providing embeddings and corresponding ids
32index.add_documents(
33 documents_ids=documents_ids,
34 documents_embeddings=documents_embeddings,
35)1# To load an index, simply instantiate it with the correct folder/name and without overriding it
2index = indexes.Voyager(
3 index_folder="pylate-index",
4 index_name="index",
5)1# Step 1: Initialize the ColBERT retriever
2retriever = retrieve.ColBERT(index=index)
3
4# Step 2: Encode the queries
5queries_embeddings = model.encode(
6 ["query for document 3", "query for document 1"],
7 batch_size=32,
8 is_query=True, # # Ensure that it is set to False to indicate that these are queries
9 show_progress_bar=True,
10)
11
12# Step 3: Retrieve top-k documents
13scores = retriever.retrieve(
14 queries_embeddings=queries_embeddings,
15 k=10, # Retrieve the top 10 matches for each query
16)1import torch
2from pylate import rank, models
3
4queries = [
5 "query A",
6 "query B",
7]
8
9documents = [
10 ["document A", "document B"],
11 ["document 1", "document C", "document B"],
12]
13
14documents_ids = [
15 [1, 2],
16 [1, 3, 2],
17]
18
19model = models.ColBERT(
20 model_name_or_path=("fjmgAI/reason-colBERT-210M-EuroBERT", trust_remote_code=True),
21)
22
23device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
24
25model.to(device)
26
27queries_embeddings = model.encode(
28 queries,
29 is_query=True,
30)
31
32documents_embeddings = model.encode(
33 documents,
34 is_query=False,
35)
36
37reranked_documents = rank.rerank(
38 documents_ids=documents_ids,
39 queries_embeddings=queries_embeddings,
40 documents_embeddings=documents_embeddings,
41)