SentenceTransformer based on Alibaba-NLP/gte-multilingual-base
This is a sentence-transformers model finetuned from Alibaba-NLP/gte-multilingual-base. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
Model Details
這是一個經台灣法律裁判書以及生成問句資料集所微調的一個embedding model,用於法律領域的RAG系統。 可能涉及到隱私資訊,因此這裡不放上微調的資料集。 具體上是使用sentence-transformers中的CacheMultipleNegativesLoss做訓練,使用32000筆(Anchor, Positive) paris, Anchor為台灣的裁判書Chunks,Positive則為gpt-4-nano所生成出來的Positive Query,以模仿使用者提問。
Model Description
- Model Type: Sentence Transformer
- Base model: Alibaba-NLP/gte-multilingual-base
- Maximum Sequence Length: 8192 tokens
- Output Dimensionality: 768 dimensions
- Similarity Function: Cosine Similarity
Model Sources
- Documentation: Sentence Transformers Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Sentence Transformers on Hugging Face
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 8192, 'do_lower_case': False}) with Transformer model: NewModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
(2): Normalize()
)
Usage
Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("Jackyee/gte-multilingual-base-finetuned-v1")
# Run inference
sentences = [
'裁判書內容...(略)',
'若聲請人依照程序完成了申報權利,則該證券是否仍然無效?',
'若聲請人未於收到裁定之日起7日內提交本案相關服務申請書,是否會導致其支付命令的請求被駁回?',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
Evaluation
Metrics
Information Retrieval
- Dataset:
val-ir-eval
- Evaluated with
InformationRetrievalEvaluator
Metric | Value |
---|---|
cosine_accuracy@1 | 0.4715 |
cosine_accuracy@3 | 0.615 |
cosine_accuracy@5 | 0.6795 |
cosine_accuracy@10 | 0.761 |
cosine_precision@1 | 0.4715 |
cosine_precision@3 | 0.205 |
cosine_precision@5 | 0.1359 |
cosine_precision@10 | 0.0761 |
cosine_recall@1 | 0.4715 |
cosine_recall@3 | 0.615 |
cosine_recall@5 | 0.6795 |
cosine_recall@10 | 0.761 |
cosine_ndcg@10 | 0.6077 |
cosine_mrr@10 | 0.5597 |
cosine_map@100 | 0.5673 |
Training Details
Training Dataset
Unnamed Dataset
- Size: 32,000 training samples
- Columns:
anchor
andpositive
- Approximate statistics based on the first 1000 samples:
anchor positive type string string details - min: 11 tokens
- mean: 491.94 tokens
- max: 917 tokens
- min: 18 tokens
- mean: 35.6 tokens
- max: 90 tokens
- Samples: 由Anchor(法律裁判書)、Positive(生成法律問句)組成 |
- Loss:
CachedMultipleNegativesRankingLoss
with these parameters:{ "scale": 20.0, "similarity_fct": "cos_sim", "mini_batch_size": 4 }
Training Hyperparameters
Non-Default Hyperparameters
eval_strategy
: stepsper_device_train_batch_size
: 256per_device_eval_batch_size
: 256learning_rate
: 2e-05num_train_epochs
: 2warmup_ratio
: 0.1fp16
: True
All Hyperparameters
Click to expand
overwrite_output_dir
: Falsedo_predict
: Falseeval_strategy
: stepsprediction_loss_only
: Trueper_device_train_batch_size
: 256per_device_eval_batch_size
: 256per_gpu_train_batch_size
: Noneper_gpu_eval_batch_size
: Nonegradient_accumulation_steps
: 1eval_accumulation_steps
: Nonetorch_empty_cache_steps
: Nonelearning_rate
: 2e-05weight_decay
: 0.0adam_beta1
: 0.9adam_beta2
: 0.999adam_epsilon
: 1e-08max_grad_norm
: 1.0num_train_epochs
: 2max_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
: 42data_seed
: Nonejit_mode_eval
: Falseuse_ipex
: Falsebf16
: Falsefp16
: Truefp16_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
: 0dataloader_prefetch_factor
: Nonepast_index
: -1disable_tqdm
: Falseremove_unused_columns
: Truelabel_names
: Noneload_best_model_at_end
: Falseignore_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
: Falsehub_revision
: Nonegradient_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
: Noneinclude_tokens_per_second
: Falseinclude_num_input_tokens_seen
: Falseneftune_noise_alpha
: Noneoptim_target_modules
: Nonebatch_eval_metrics
: Falseeval_on_start
: Falseuse_liger_kernel
: Falseliger_kernel_config
: Noneeval_use_gather_object
: Falseaverage_tokens_across_devices
: Falseprompts
: Nonebatch_sampler
: batch_samplermulti_dataset_batch_sampler
: proportional
Training Logs
Epoch | Step | Training Loss | val-ir-eval_cosine_ndcg@10 |
---|---|---|---|
0.08 | 10 | 3.097 | 0.4066 |
0.16 | 20 | 2.1587 | 0.4666 |
0.24 | 30 | 1.5683 | 0.5202 |
0.32 | 40 | 1.3655 | 0.5382 |
0.4 | 50 | 1.2251 | 0.5532 |
0.48 | 60 | 1.1604 | 0.5643 |
0.56 | 70 | 1.1186 | 0.5704 |
0.64 | 80 | 1.117 | 0.5788 |
0.72 | 90 | 1.0559 | 0.5861 |
0.8 | 100 | 1.0596 | 0.5885 |
0.88 | 110 | 1.0037 | 0.5884 |
0.96 | 120 | 1.0115 | 0.5923 |
1.04 | 130 | 1.0418 | 0.5971 |
1.12 | 140 | 0.9912 | 0.5971 |
1.2 | 150 | 0.9676 | 0.5989 |
1.28 | 160 | 0.9122 | 0.5992 |
1.3600 | 170 | 0.9466 | 0.6008 |
1.44 | 180 | 0.9521 | 0.6012 |
1.52 | 190 | 0.9608 | 0.6035 |
1.6 | 200 | 0.9532 | 0.6052 |
1.6800 | 210 | 0.9302 | 0.6068 |
1.76 | 220 | 0.9202 | 0.6060 |
1.8400 | 230 | 0.9831 | 0.6074 |
1.92 | 240 | 0.9279 | 0.6077 |
2.0 | 250 | 0.9461 | 0.6077 |
Framework Versions
- Python: 3.10.18
- Sentence Transformers: 4.1.0
- Transformers: 4.54.1
- PyTorch: 2.7.1+cu126
- Accelerate: 1.9.0
- Datasets: 4.0.0
- Tokenizers: 0.21.4
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",
}
CachedMultipleNegativesRankingLoss
@misc{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
- Downloads last month
- 5
Model tree for Jackyee/gte-multilingual-base-finetuned-v1
Base model
Alibaba-NLP/gte-multilingual-baseEvaluation results
- Cosine Accuracy@1 on val ir evalself-reported0.471
- Cosine Accuracy@3 on val ir evalself-reported0.615
- Cosine Accuracy@5 on val ir evalself-reported0.679
- Cosine Accuracy@10 on val ir evalself-reported0.761
- Cosine Precision@1 on val ir evalself-reported0.471
- Cosine Precision@3 on val ir evalself-reported0.205
- Cosine Precision@5 on val ir evalself-reported0.136
- Cosine Precision@10 on val ir evalself-reported0.076
- Cosine Recall@1 on val ir evalself-reported0.471
- Cosine Recall@3 on val ir evalself-reported0.615