Views
No views yet
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'cls', 'include_prompt': True})
(2): Normalize({})
)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("davanstrien/iconclass-retriever-bge-ft")
5# Run inference
6queries = [
7 'An engraving depicts a dramatic nocturnal scene where a man in period clothing stands on a burning ladder, reaching up to assist a young boy who is climbing down from a high window. The ladder is engulfed in flames at its base, creating a sense of peril, while the boy looks down with a calm expression. In the background, a cityscape is visible under a night sky featuring a radiant sun or moon.',
8]
9documents = [
10 'burning',
11 'glowing (heat)',
12 'radiating (heat)',
13]
14query_embeddings = model.encode_query(queries)
15document_embeddings = model.encode_document(documents)
16print(query_embeddings.shape, document_embeddings.shape)
17# [1, 768] [3, 768]
18
19# Get the similarity scores for the embeddings
20similarities = model.similarity(query_embeddings, document_embeddings)
21print(similarities)
22# tensor([[0.5269, 0.3512, 0.3070]])iconclassInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.2669 |
| cosine_accuracy@5 | 0.5118 |
| cosine_accuracy@10 | 0.5929 |
| cosine_precision@1 | 0.2669 |
| cosine_precision@5 | 0.1537 |
| cosine_precision@10 | 0.1054 |
| cosine_precision@24 | 0.0588 |
| cosine_recall@1 | 0.0984 |
| cosine_recall@5 | 0.2548 |
| cosine_recall@10 | 0.3353 |
| cosine_recall@24 | 0.4297 |
| cosine_ndcg@10 | 0.2766 |
| cosine_mrr@10 | 0.3664 |
| cosine_map@100 | 0.2174 |
anchor, positive, negative_1, negative_2, negative_3, and negative_4| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 | |
|---|---|---|---|---|---|---|
| type | string | string | string | string | string | string |
| modality | text | text | text | text | text | text |
| details |
|
|
|
|
|
|
| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 |
|---|---|---|---|---|---|
A dimly lit interior scene depicts a group of horses and a donkey within a rustic stable or ruin. A white horse stands prominently in the center, flanked by a darker horse to its left and another dark horse to its right. In the foreground, a donkey stands near a pile of discarded tack and blankets on the ground, while a small arched window on the left provides a source of light. | barn | farm (building) - AA - civic architecture: inside | saints | imps, familiars of witches and sorcerers | horses (circus performance) |
A vibrant bouquet of various flowers, including roses, tulips, and a hanging crown imperial, is arranged in a dark vase on a wooden ledge. The composition is animated by several butterflies fluttering among the blooms and a small bird's nest with eggs resting on the ledge to the left. A single red tulip lies fallen on the ledge in the foreground, adding a sense of transience to the scene. | flowers | artificial plants and flowers | fabulous plants and herbs | bunch of flowers ~ ornament - AA - stylized | flowers ~ ornament |
A panoramic landscape painting depicts a wide river or lake reflecting the sky, flanked by dense clusters of trees and foliage. In the foreground on the left, a group of travelers walks along a dirt path, while a solitary figure stands nearby. In the background, a town with a prominent church spire and other buildings is visible across the water. | water course | canal | sea (seascape) | landscapes with waters, waterscapes, seascapes (in the temperate zone) - HH - ideal landscapes | heaven represented as paradisaical landscape |
MultipleNegativesRankingLoss with these parameters:
1{
2 "scale": 20.0,
3 "similarity_fct": "cos_sim",
4 "gather_across_devices": false,
5 "directions": [
6 "query_to_doc"
7 ],
8 "partition_mode": "joint",
9 "hardness_mode": null,
10 "hardness_strength": 0.0
11}anchor, positive, negative_1, negative_2, negative_3, and negative_4| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 | |
|---|---|---|---|---|---|---|
| type | string | string | string | string | string | string |
| modality | text | text | text | text | text | text |
| details |
|
|
|
|
|
|
| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 |
|---|---|---|---|---|---|
A muscular, nude male figure lies supine on a rocky outcrop, his body contorted in a dramatic pose with his head thrown back and his right arm raised toward the sky. A second figure, appearing to be a woman with flowing hair, stands beside him, leaning over and reaching out to touch or support his raised hand. The scene is set against a backdrop of heavy, swirling clouds and a distant landscape, creating a tense and theatrical atmosphere. | David thanks the Lord after he has slain the giant Goliath | David speaks with Goliath | David slings a stone at Goliath's forehead | David beheads Goliath with a sword | lying figure |
A seated female figure, representing the element of water, is depicted in profile facing left. She holds a long, slender vessel from which she pours a stream of water, while a large basket filled with reeds or rushes rests beside her on a rock. | island | dale, valley | coast | forest, wood | plain |
The Virgin Mary, wearing a blue mantle and red dress, sits enthroned holding the Christ Child on her lap. To the left, a Dominican nun and a Dominican friar kneel in prayer, looking up at the holy figures. Above them, a heavenly host of angels and cherubs gathers in a burst of golden light, while two putti at the base of the throne arrange a floral garland. | flowers | artificial plants and flowers | fabulous plants and herbs | standing figure | stand-in |
MultipleNegativesRankingLoss with these parameters:
1{
2 "scale": 20.0,
3 "similarity_fct": "cos_sim",
4 "gather_across_devices": false,
5 "directions": [
6 "query_to_doc"
7 ],
8 "partition_mode": "joint",
9 "hardness_mode": null,
10 "hardness_strength": 0.0
11}per_device_train_batch_size: 64learning_rate: 2e-05warmup_steps: 0.1weight_decay: 0.01bf16: Trueper_device_eval_batch_size: 128push_to_hub: Truehub_model_id: davanstrien/iconclass-retriever-bge-ftload_best_model_at_end: Trueseed: 12batch_sampler: no_duplicatesper_device_train_batch_size: 64num_train_epochs: 3.0max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 128prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Truehub_private_repo: Nonehub_model_id: davanstrien/iconclass-retriever-bge-fthub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 12data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | iconclass_cosine_ndcg@10 |
|---|---|---|---|---|
| -1 | -1 | - | - | 0.0791 |
| 0.0030 | 1 | 5.5045 | - | - |
| 0.0593 | 20 | 5.2547 | - | - |
| 0.1187 | 40 | 4.9180 | - | - |
| 0.1780 | 60 | 4.6572 | - | - |
| 0.2374 | 80 | 4.4856 | - | - |
| 0.2967 | 100 | 4.3476 | - | - |
| 0.3561 | 120 | 4.2496 | - | - |
| 0.4154 | 140 | 4.2427 | - | - |
| 0.4748 | 160 | 4.1129 | - | - |
| 0.5341 | 180 | 3.9719 | - | - |
| 0.5935 | 200 | 4.0231 | - | - |
| 0.6528 | 220 | 3.9212 | - | - |
| 0.7122 | 240 | 3.9147 | - | - |
| 0.7507 | 253 | - | 1.7970 | 0.2702 |
| 0.7715 | 260 | 3.9227 | - | - |
| 0.8309 | 280 | 3.8546 | - | - |
| 0.8902 | 300 | 3.3277 | - | - |
| 0.9496 | 320 | 1.9490 | - | - |
| 1.0089 | 340 | 2.1030 | - | - |
| 1.0682 | 360 | 3.6301 | - | - |
| 1.1276 | 380 | 3.5009 | - | - |
| 1.1869 | 400 | 3.6163 | - | - |
| 1.2463 | 420 | 3.5507 | - | - |
| 1.3056 | 440 | 3.5883 | - | - |
| 1.3650 | 460 | 3.5163 | - | - |
| 1.4243 | 480 | 3.5287 | - | - |
| 1.4837 | 500 | 3.4211 | - | - |
| 1.5015 | 506 | - | 1.6725 | 0.2785 |
| 1.5430 | 520 | 3.5846 | - | - |
| 1.6024 | 540 | 3.4772 | - | - |
| 1.6617 | 560 | 3.4992 | - | - |
| 1.7211 | 580 | 3.4459 | - | - |
| 1.7804 | 600 | 3.4747 | - | - |
| 1.8398 | 620 | 3.4815 | - | - |
| 1.8991 | 640 | 2.7377 | - | - |
| 1.9585 | 660 | 1.7949 | - | - |
| 2.0178 | 680 | 2.0796 | - | - |
| 2.0772 | 700 | 3.3525 | - | - |
| 2.1365 | 720 | 3.3296 | - | - |
| 2.1958 | 740 | 3.2522 | - | - |
| 2.2522 | 759 | - | 1.5502 | 0.2842 |
| 2.2552 | 760 | 3.2960 | - | - |
| 2.3145 | 780 | 3.2314 | - | - |
| 2.3739 | 800 | 3.2461 | - | - |
| 2.4332 | 820 | 3.2065 | - | - |
| 2.4926 | 840 | 3.1930 | - | - |
| 2.5519 | 860 | 3.2079 | - | - |
| 2.6113 | 880 | 3.2920 | - | - |
| 2.6706 | 900 | 3.2403 | - | - |
| 2.7300 | 920 | 3.2088 | - | - |
| 2.7893 | 940 | 3.3953 | - | - |
| 2.8487 | 960 | 3.2497 | - | - |
| 2.9080 | 980 | 2.5122 | - | - |
| 2.9674 | 1000 | 1.7967 | - | - |
| 3.0 | 1011 | - | 1.5537 | 0.2766 |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}1@misc{oord2019representationlearningcontrastivepredictive,
2 title={Representation Learning with Contrastive Predictive Coding},
3 author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
4 year={2019},
5 eprint={1807.03748},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/1807.03748},
9}