PyLate model based on answerdotai/ModernBERT-base

This is a PyLate model finetuned from answerdotai/ModernBERT-base. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.

Model Details

Model Description

  • Model Type: PyLate model
  • Base model: answerdotai/ModernBERT-base
  • Document Length: 180 tokens
  • Query Length: 32 tokens
  • Output Dimensionality: 128 tokens
  • Similarity Function: MaxSim

Model Sources

Full Model Architecture

ColBERT(
  (0): Transformer({'max_seq_length': 179, 'do_lower_case': False}) with Transformer model: ModernBertModel 
  (1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
)

Usage

First install the PyLate library:

pip install -U pylate

Retrieval

PyLate provides a streamlined interface to index and retrieve documents using ColBERT models. The index leverages the Voyager HNSW index to efficiently handle document embeddings and enable fast retrieval.

Indexing documents

First, load the ColBERT model and initialize the Voyager index, then encode and index your documents:

from pylate import indexes, models, retrieve

# Step 1: Load the ColBERT model
model = models.ColBERT(
    model_name_or_path=ayushexel/colbert-ModernBERT-base-2-neg-1-epoch-gooaq-1995000,
)

# Step 2: Initialize the Voyager index
index = indexes.Voyager(
    index_folder="pylate-index",
    index_name="index",
    override=True,  # This overwrites the existing index if any
)

# Step 3: Encode the documents
documents_ids = ["1", "2", "3"]
documents = ["document 1 text", "document 2 text", "document 3 text"]

documents_embeddings = model.encode(
    documents,
    batch_size=32,
    is_query=False,  # Ensure that it is set to False to indicate that these are documents, not queries
    show_progress_bar=True,
)

# Step 4: Add document embeddings to the index by providing embeddings and corresponding ids
index.add_documents(
    documents_ids=documents_ids,
    documents_embeddings=documents_embeddings,
)

Note that you do not have to recreate the index and encode the documents every time. Once you have created an index and added the documents, you can re-use the index later by loading it:

# To load an index, simply instantiate it with the correct folder/name and without overriding it
index = indexes.Voyager(
    index_folder="pylate-index",
    index_name="index",
)

Retrieving top-k documents for queries

Once the documents are indexed, you can retrieve the top-k most relevant documents for a given set of queries. To do so, initialize the ColBERT retriever with the index you want to search in, encode the queries and then retrieve the top-k documents to get the top matches ids and relevance scores:

# Step 1: Initialize the ColBERT retriever
retriever = retrieve.ColBERT(index=index)

# Step 2: Encode the queries
queries_embeddings = model.encode(
    ["query for document 3", "query for document 1"],
    batch_size=32,
    is_query=True,  #  # Ensure that it is set to False to indicate that these are queries
    show_progress_bar=True,
)

# Step 3: Retrieve top-k documents
scores = retriever.retrieve(
    queries_embeddings=queries_embeddings,
    k=10,  # Retrieve the top 10 matches for each query
)

Reranking

If you only want to use the ColBERT model to perform reranking on top of your first-stage retrieval pipeline without building an index, you can simply use rank function and pass the queries and documents to rerank:

from pylate import rank, models

queries = [
    "query A",
    "query B",
]

documents = [
    ["document A", "document B"],
    ["document 1", "document C", "document B"],
]

documents_ids = [
    [1, 2],
    [1, 3, 2],
]

model = models.ColBERT(
    model_name_or_path=ayushexel/colbert-ModernBERT-base-2-neg-1-epoch-gooaq-1995000,
)

queries_embeddings = model.encode(
    queries,
    is_query=True,
)

documents_embeddings = model.encode(
    documents,
    is_query=False,
)

reranked_documents = rank.rerank(
    documents_ids=documents_ids,
    queries_embeddings=queries_embeddings,
    documents_embeddings=documents_embeddings,
)

Evaluation

Metrics

Col BERTTriplet

  • Evaluated with pylate.evaluation.colbert_triplet.ColBERTTripletEvaluator
Metric Value
accuracy 0.4942

Training Details

Training Dataset

Unnamed Dataset

  • Size: 3,787,119 training samples
  • Columns: question, answer, and negative
  • Approximate statistics based on the first 1000 samples:
    question answer negative
    type string string string
    details
    • min: 9 tokens
    • mean: 13.19 tokens
    • max: 21 tokens
    • min: 18 tokens
    • mean: 31.78 tokens
    • max: 32 tokens
    • min: 13 tokens
    • mean: 31.68 tokens
    • max: 32 tokens
  • Samples:
    question answer negative
    how is sickle cell anemia beneficial? Having two copies of the mutated genes cause sickle cell anemia, but having just one copy does not, and can actually protect against malaria - an example of how mutations are sometimes beneficial. Description. Sickle cell disease is a group of disorders that affects hemoglobin, the molecule in red blood cells that delivers oxygen to cells throughout the body. People with this disorder have atypical hemoglobin molecules called hemoglobin S, which can distort red blood cells into a sickle, or crescent, shape.
    how is sickle cell anemia beneficial? Having two copies of the mutated genes cause sickle cell anemia, but having just one copy does not, and can actually protect against malaria - an example of how mutations are sometimes beneficial. Sickle cell anemia is caused by a mutation in the gene that tells your body to make the iron-rich compound that makes blood red and enables red blood cells to carry oxygen from your lungs throughout your body (hemoglobin).
    can you get pregnant naturally if you have pcos? Polycystic ovarian syndrome (PCOS) is one of the most common causes of female infertility, affecting an estimated 5 million women. 1 But you can get pregnant with PCOS. There are a number of effective fertility treatments available, from Clomid to gonadotropins to IVF. One in every 10 women in India has polycystic ovary syndrome (PCOS), a common endocrinal system disorder among women of reproductive age, according to a study by PCOS Society. And out of every 10 women diagnosed with PCOS, six are teenage girls. PCOS was described as early as 1935.
  • Loss: pylate.losses.contrastive.Contrastive

Evaluation Dataset

Unnamed Dataset

  • Size: 5,000 evaluation samples
  • Columns: question, answer, and negative_1
  • Approximate statistics based on the first 1000 samples:
    question answer negative_1
    type string string string
    details
    • min: 9 tokens
    • mean: 13.11 tokens
    • max: 22 tokens
    • min: 16 tokens
    • mean: 31.72 tokens
    • max: 32 tokens
    • min: 14 tokens
    • mean: 31.37 tokens
    • max: 32 tokens
  • Samples:
    question answer negative_1
    what are gharial related to? What is a gharial? Gharials, sometimes called gavials, are a type of Asian crocodilian distinguished by their long, thin snouts. Crocodilians are a group of reptiles that includes crocodiles, alligators, caimans, and more. false Gharials live in South America. true Gharials are an endangered species.
    what is electron transport chain and chemiosmosis? The electron transport chain consists of a series of electron carriers that eventually transfer electrons from NADH and FADH2 to oxygen. The chemiosmotic theory states that the transfer of electrons down an electron transport system through a series of oxidation-reduction reactions releases energy. The electron transport chain is a series of proteins and organic molecules found in the inner membrane of the mitochondria. ... Together, the electron transport chain and chemiosmosis make up oxidative phosphorylation.
    how to transfer pictures from icloud to usb? ["Manually download all the files from Apple's iCloud website to a folder on your PC and then copy/paste or move them to your USB drive.", "Download iCloud for Windows and find the iCloud folder in your File Explorer. Then, copy the photos from your PCs' iCloud folder and paste them to your USB Drive."] ["Manually download all the files from Apple's iCloud website to a folder on your PC and then copy/paste or move them to your USB drive.", "Download iCloud for Windows and find the iCloud folder in your File Explorer. Then, copy the photos from your PCs' iCloud folder and paste them to your USB Drive."]
  • Loss: pylate.losses.contrastive.Contrastive

Training Hyperparameters

Non-Default Hyperparameters

  • eval_strategy: steps
  • per_device_train_batch_size: 128
  • per_device_eval_batch_size: 128
  • learning_rate: 3e-06
  • num_train_epochs: 1
  • warmup_ratio: 0.1
  • seed: 12
  • bf16: True
  • dataloader_num_workers: 12
  • load_best_model_at_end: True

All Hyperparameters

Click to expand
  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: steps
  • prediction_loss_only: True
  • per_device_train_batch_size: 128
  • per_device_eval_batch_size: 128
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 3e-06
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1.0
  • num_train_epochs: 1
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.1
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 12
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: True
  • fp16: False
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 12
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: True
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: False
  • resume_from_checkpoint: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_private_repo: None
  • hub_always_push: False
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • include_for_metrics: []
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • dispatch_batches: None
  • split_batches: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • use_liger_kernel: False
  • eval_use_gather_object: False
  • average_tokens_across_devices: False
  • prompts: None
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: proportional

Training Logs

Click to expand
Epoch Step Training Loss Validation Loss accuracy
0 0 - - 0.4482
0.0000 1 19.1821 - -
0.0068 200 14.4411 - -
0.0135 400 7.9989 - -
0.0203 600 5.6695 - -
0.0270 800 4.0985 - -
0.0338 1000 2.121 - -
0.0406 1200 1.3478 - -
0.0473 1400 1.0677 - -
0.0541 1600 0.9243 - -
0.0608 1800 0.8415 - -
0.0676 2000 0.7807 - -
0.0744 2200 0.7055 - -
0.0811 2400 0.6782 - -
0.0879 2600 0.6443 - -
0.0946 2800 0.6028 - -
0.1014 3000 0.5886 - -
0.1082 3200 0.5484 - -
0.1149 3400 0.5236 - -
0.1217 3600 0.5049 - -
0.1284 3800 0.4855 - -
0.1352 4000 0.4565 - -
0.1420 4200 0.4545 - -
0.1487 4400 0.4313 - -
0.1555 4600 0.4221 - -
0.1622 4800 0.4102 - -
0.1690 5000 0.4086 - -
0.1758 5200 0.3935 - -
0.1825 5400 0.3808 - -
0.1893 5600 0.3768 - -
0.1960 5800 0.3663 - -
0.2028 6000 0.3625 - -
0.2096 6200 0.3587 - -
0.2163 6400 0.3429 - -
0.2231 6600 0.3414 - -
0.2298 6800 0.3359 - -
0.2366 7000 0.322 - -
0.2434 7200 0.3192 - -
0.2501 7400 0.317 - -
0.2569 7600 0.3137 - -
0.2636 7800 0.3073 - -
0.2704 8000 0.3103 - -
0.2771 8200 0.3058 - -
0.2839 8400 0.2998 - -
0.2907 8600 0.294 - -
0.2974 8800 0.2902 - -
0.3042 9000 0.2907 - -
0.3109 9200 0.2858 - -
0.3177 9400 0.2802 - -
0.3245 9600 0.2788 - -
0.3312 9800 0.2725 - -
0.3380 10000 0.2765 - -
0.3447 10200 0.2722 - -
0.3515 10400 0.2603 - -
0.3583 10600 0.2712 - -
0.3650 10800 0.2609 - -
0.3718 11000 0.2637 - -
0.3785 11200 0.2562 - -
0.3853 11400 0.2511 - -
0.3921 11600 0.2552 - -
0.3988 11800 0.2494 - -
0.4056 12000 0.2557 - -
0.4123 12200 0.2459 - -
0.4191 12400 0.2442 - -
0.4259 12600 0.2471 - -
0.4326 12800 0.2499 - -
0.4394 13000 0.2417 - -
0.4461 13200 0.246 - -
0.4529 13400 0.2423 - -
0.4597 13600 0.2361 - -
0.4664 13800 0.2395 - -
0.4732 14000 0.2347 - -
0.4799 14200 0.2433 - -
0.4867 14400 0.2353 - -
0.4935 14600 0.2316 - -
0.5002 14800 0.2305 - -
0.5070 15000 0.2321 - -
0.5137 15200 0.2322 - -
0.5205 15400 0.2292 - -
0.5273 15600 0.2204 - -
0.5340 15800 0.2248 - -
0.5408 16000 0.2223 - -
0.5475 16200 0.2226 - -
0.5543 16400 0.2245 - -
0.5611 16600 0.222 - -
0.5678 16800 0.2133 - -
0.5746 17000 0.2222 - -
0.5813 17200 0.2147 - -
0.5881 17400 0.2192 - -
0.5949 17600 0.2109 - -
0.6016 17800 0.2164 - -
0.6084 18000 0.2145 - -
0.6151 18200 0.2107 - -
0.6219 18400 0.2172 - -
0.6287 18600 0.2132 - -
0.6354 18800 0.2049 - -
0.6422 19000 0.2125 - -
0.6489 19200 0.211 - -
0.6557 19400 0.2141 - -
0.6625 19600 0.2073 - -
0.6692 19800 0.2095 - -
0.676 20000 0.2082 - -
0 0 - - 0.4942
0.676 20000 - 0.9978 -
0.6827 20200 0.2118 - -
0.6895 20400 0.208 - -
0.6963 20600 0.2092 - -
0.7030 20800 0.2138 - -
0.7098 21000 0.1991 - -
0.7165 21200 0.2027 - -
0.7233 21400 0.204 - -
0.7301 21600 0.2065 - -
0.7368 21800 0.1986 - -
0.7436 22000 0.2008 - -
0.7503 22200 0.201 - -
0.7571 22400 0.2042 - -
0.7638 22600 0.2004 - -
0.7706 22800 0.1988 - -
0.7774 23000 0.1997 - -
0.7841 23200 0.2066 - -
0.7909 23400 0.2012 - -
0.7976 23600 0.1976 - -
0.8044 23800 0.1975 - -
0.8112 24000 0.1969 - -
0.8179 24200 0.202 - -
0.8247 24400 0.1978 - -
0.8314 24600 0.2033 - -
0.8382 24800 0.1964 - -
0.8450 25000 0.2046 - -
0.8517 25200 0.2002 - -
0.8585 25400 0.1987 - -
0.8652 25600 0.1945 - -
0.8720 25800 0.1973 - -
0.8788 26000 0.197 - -
0.8855 26200 0.194 - -
0.8923 26400 0.1965 - -
0.8990 26600 0.2025 - -
0.9058 26800 0.1913 - -
0.9126 27000 0.1964 - -
0.9193 27200 0.1949 - -
0.9261 27400 0.194 - -
0.9328 27600 0.1964 - -
0.9396 27800 0.1954 - -
0.9464 28000 0.1924 - -
0.9531 28200 0.1948 - -
0.9599 28400 0.1963 - -
0.9666 28600 0.1929 - -
0.9734 28800 0.1993 - -
0.9802 29000 0.1926 - -
0.9869 29200 0.1874 - -
0.9937 29400 0.1976 - -
  • The bold row denotes the saved checkpoint.

Framework Versions

  • Python: 3.11.0
  • Sentence Transformers: 4.0.1
  • PyLate: 1.1.7
  • Transformers: 4.48.2
  • PyTorch: 2.6.0+cu124
  • Accelerate: 1.6.0
  • Datasets: 3.5.0
  • Tokenizers: 0.21.1

Citation

BibTeX

Sentence Transformers

@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084"
}

PyLate

@misc{PyLate,
title={PyLate: Flexible Training and Retrieval for Late Interaction Models},
author={Chaffin, Antoine and Sourty, Raphaël},
url={https://github.com/lightonai/pylate},
year={2024}
}
Downloads last month
9
Safetensors
Model size
149M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for ayushexel/colbert-ModernBERT-base-2-neg-1-epoch-gooaq-1995000

Finetuned
(554)
this model

Evaluation results