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
- Documentation: PyLate Documentation
- Repository: PyLate on GitHub
- Hugging Face: PyLate models on Hugging Face
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
, andnegative
- 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
, andnegative_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
: stepsper_device_train_batch_size
: 128per_device_eval_batch_size
: 128learning_rate
: 3e-06num_train_epochs
: 1warmup_ratio
: 0.1seed
: 12bf16
: Truedataloader_num_workers
: 12load_best_model_at_end
: True
All Hyperparameters
Click to expand
overwrite_output_dir
: Falsedo_predict
: Falseeval_strategy
: stepsprediction_loss_only
: Trueper_device_train_batch_size
: 128per_device_eval_batch_size
: 128per_gpu_train_batch_size
: Noneper_gpu_eval_batch_size
: Nonegradient_accumulation_steps
: 1eval_accumulation_steps
: Nonetorch_empty_cache_steps
: Nonelearning_rate
: 3e-06weight_decay
: 0.0adam_beta1
: 0.9adam_beta2
: 0.999adam_epsilon
: 1e-08max_grad_norm
: 1.0num_train_epochs
: 1max_steps
: -1lr_scheduler_type
: linearlr_scheduler_kwargs
: {}warmup_ratio
: 0.1warmup_steps
: 0log_level
: passivelog_level_replica
: warninglog_on_each_node
: Truelogging_nan_inf_filter
: Truesave_safetensors
: Truesave_on_each_node
: Falsesave_only_model
: Falserestore_callback_states_from_checkpoint
: Falseno_cuda
: Falseuse_cpu
: Falseuse_mps_device
: Falseseed
: 12data_seed
: Nonejit_mode_eval
: Falseuse_ipex
: Falsebf16
: Truefp16
: Falsefp16_opt_level
: O1half_precision_backend
: autobf16_full_eval
: Falsefp16_full_eval
: Falsetf32
: Nonelocal_rank
: 0ddp_backend
: Nonetpu_num_cores
: Nonetpu_metrics_debug
: Falsedebug
: []dataloader_drop_last
: Falsedataloader_num_workers
: 12dataloader_prefetch_factor
: Nonepast_index
: -1disable_tqdm
: Falseremove_unused_columns
: Truelabel_names
: Noneload_best_model_at_end
: Trueignore_data_skip
: Falsefsdp
: []fsdp_min_num_params
: 0fsdp_config
: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap
: Noneaccelerator_config
: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed
: Nonelabel_smoothing_factor
: 0.0optim
: adamw_torchoptim_args
: Noneadafactor
: Falsegroup_by_length
: Falselength_column_name
: lengthddp_find_unused_parameters
: Noneddp_bucket_cap_mb
: Noneddp_broadcast_buffers
: Falsedataloader_pin_memory
: Truedataloader_persistent_workers
: Falseskip_memory_metrics
: Trueuse_legacy_prediction_loop
: Falsepush_to_hub
: Falseresume_from_checkpoint
: Nonehub_model_id
: Nonehub_strategy
: every_savehub_private_repo
: Nonehub_always_push
: Falsegradient_checkpointing
: Falsegradient_checkpointing_kwargs
: Noneinclude_inputs_for_metrics
: Falseinclude_for_metrics
: []eval_do_concat_batches
: Truefp16_backend
: autopush_to_hub_model_id
: Nonepush_to_hub_organization
: Nonemp_parameters
:auto_find_batch_size
: Falsefull_determinism
: Falsetorchdynamo
: Noneray_scope
: lastddp_timeout
: 1800torch_compile
: Falsetorch_compile_backend
: Nonetorch_compile_mode
: Nonedispatch_batches
: Nonesplit_batches
: Noneinclude_tokens_per_second
: Falseinclude_num_input_tokens_seen
: Falseneftune_noise_alpha
: Noneoptim_target_modules
: Nonebatch_eval_metrics
: Falseeval_on_start
: Falseuse_liger_kernel
: Falseeval_use_gather_object
: Falseaverage_tokens_across_devices
: Falseprompts
: Nonebatch_sampler
: batch_samplermulti_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
Model tree for ayushexel/colbert-ModernBERT-base-2-neg-1-epoch-gooaq-1995000
Base model
answerdotai/ModernBERT-base