SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, '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()
)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("ictumuk/mul_legal_final")
5# Run inference
6sentences = [
7 'Chế độ giáo dục phạm nhân dưới 18 tuổi từ năm 2020 được quy định như thế nào?',
8 '1. Phạm nhân là người dưới 18 tuổi được giam giữ theo chế độ riêng phù hợp với sức khỏe, giới tính và đặc điểm nhân thân.\n2. Trại giam có trách nhiệm giáo dục phạm nhân là người dưới 18 tuổi về văn hóa, pháp luật và dạy nghề phù hợp với độ tuổi, học vấn, giới tính và sức khỏe, chuẩn bị điều kiện để họ hòa nhập cộng đồng sau khi chấp hành xong án phạt tù. Thực hiện phổ cập giáo dục tiểu học và giáo dục trung học cơ sở. Giáo dục tiểu học là bắt buộc đối với phạm nhân chưa học xong chương trình tiểu học.',
9 '1. Công tác nạo vét duy tu luồng hàng hải công cộng và luồng đường thủy nội địa sử dụng nguồn ngân sách nhà nước do Bộ Giao thông vận tải, Ủy ban nhân dân cấp tỉnh quản lý được nhà nước bảo đảm, bố trí từ nguồn vốn ngân sách hàng năm để thực hiện.\n2. Không thực hiện việc bảo hành và mua bảo hiểm thi công công trình nạo vét duy tu luồng hàng hải công cộng và luồng đường thủy nội địa.',
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 1024]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings, embeddings)
17print(similarities.shape)
18# [3, 3]BinaryClassificationEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.7746 |
| cosine_accuracy_threshold | 0.2383 |
| cosine_f1 | 0.7914 |
| cosine_f1_threshold | 0.1769 |
| cosine_precision | 0.7237 |
| cosine_recall | 0.873 |
| cosine_ap | 0.8358 |
| cosine_mcc | 0.5332 |
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
Gửi hồ sơ giả mạo đến kho bạc nhà nước để chi cho chương trình mục tiêu quốc gia phạt bao nhiêu? | 1. Phạt tiền từ 10.000.000 đồng đến 15.000.000 đồng đối với hành vi lập hồ sơ, chứng từ giả mạo gửi Kho bạc Nhà nước để thanh toán, chi trả các khoản chi thường xuyên, chi sự nghiệp có tính chất thường xuyên, chi chương trình mục tiêu quốc gia, chương trình mục tiêu sử dụng kinh phí sự nghiệp (loại trừ các khoản chi thực hiện các công trình sửa chữa, bảo trì, cải tạo, nâng cấp, mở rộng cơ sở vật chất từ nguồn kinh phí chi thường xuyên ngân sách nhà nước và nguồn phí được để lại theo chế độ quy định để chi thường xuyên có tổng mức đầu tư trên 500.000.000 đồng).[object Object]2. Phạt tiền từ 30.000.000 đồng đến 50.000.000 đồng đối với hành vi lập hồ sơ, chứng từ giả mạo gửi Kho bạc Nhà nước để thanh toán vốn đầu tư thuộc nguồn vốn ngân sách nhà nước và nguồn vốn đầu tư từ ngân sách nhà nước thực hiện các chương trình mục tiêu hoặc chi thực hiện các công trình sửa chữa, bảo trì, cải tạo, nâng cấp, mở rộng cơ sở vật chất từ nguồn kinh phí chi thường xuyên ngân sách nhà nước và nguồn phí được để lại theo... | 0 |
Điều kiện tham gia hoạt động điều tra, khảo sát, rà phá bom mìn vật nổ sau chiến tranh theo quy định hiện hành | 1. Việc quản lý chi phí dự án được thực hiện theo quy định của pháp luật về quản lý chi phí đầu tư xây dựng công trình và theo thỏa thuận với nhà tài trợ nước ngoài.[object Object]2. Chi phí nhân công trong hoạt động điều tra, khảo sát, rà phá bom mìn vật nổ sau chiến tranh thực hiện như sau:[object Object]a) Chi phí tiền công và các khoản phụ cấp đối với các đối tượng không hưởng lương từ ngân sách nhà nước khi tham gia hoạt động điều tra, khảo sát, rà phá bom mìn vật nổ sau chiến tranh;[object Object]b) Chi phí bồi dưỡng đối với các đối tượng hưởng lương từ ngân sách nhà nước khi tham gia hoạt động điều tra, khảo sát, rà phá bom mìn vật nổ sau chiến tranh theo quyết định của Thủ tướng Chính phủ. | 0 |
Hiệu lực pháp lý của di chúc miệng khi người lập di chúc phục hồi sức khỏe? | 1. Trường hợp tính mạng một người bị cái chết đe dọa và không thể lập di chúc bằng văn bản thì có thể lập di chúc miệng.[object Object]2. Sau 03 tháng, kể từ thời điểm di chúc miệng mà người lập di chúc còn sống, minh mẫn, sáng suốt thì di chúc miệng mặc nhiên bị hủy bỏ. | 1 |
CoSENTLoss with these parameters:
1{
2 "scale": 20.0,
3 "similarity_fct": "pairwise_cos_sim"
4}eval_strategy: stepsper_device_train_batch_size: 4per_device_eval_batch_size: 4learning_rate: 2e-05num_train_epochs: 4warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 4max_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: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_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: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | cosine_ap |
|---|---|---|---|
| -1 | -1 | - | 0.7745 |
| 0.1821 | 200 | 0.9978 | - |
| 0.3643 | 400 | 1.0744 | 0.8190 |
| 0.5464 | 600 | 1.1956 | - |
| 0.7286 | 800 | 1.4955 | 0.7235 |
| 0.9107 | 1000 | 1.2426 | - |
| 1.0929 | 1200 | 1.2702 | 0.7977 |
| 1.2750 | 1400 | 1.2558 | - |
| 1.4572 | 1600 | 1.056 | 0.7980 |
| 1.6393 | 1800 | 1.2258 | - |
| 1.8215 | 2000 | 1.2263 | 0.8113 |
| 2.0036 | 2200 | 1.4364 | - |
| 2.1858 | 2400 | 0.6514 | 0.8213 |
| 2.3679 | 2600 | 0.6806 | - |
| 2.5501 | 2800 | 0.7986 | 0.8362 |
| 2.7322 | 3000 | 0.759 | - |
| 2.9144 | 3200 | 0.7518 | 0.8382 |
| 3.0965 | 3400 | 0.4201 | - |
| 3.2787 | 3600 | 0.4148 | 0.8318 |
| 3.4608 | 3800 | 0.3349 | - |
| 3.6430 | 4000 | 0.3162 | 0.8415 |
| 3.8251 | 4200 | 0.3247 | - |
| -1 | -1 | - | 0.8358 |
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@online{kexuefm-8847,
2 title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
3 author={Su Jianlin},
4 year={2022},
5 month={Jan},
6 url={https://kexue.fm/archives/8847},
7}