Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 14
How to use hungq/hust_sbert with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("hungq/hust_sbert")
sentences = [
"or 2 will be lowered by one level if the \\nnumber of failed credits in the semester is less than or equal to 4 . \\nđ) Students under academic probation level 3 will be lowered to level 2 if their total unearned \\ncredits since enrollment is less than or equal to 24 . This downgrade is applied regardless of the criteria \\nfor raising probation status in point a and b above. \\ne) Academic probation is not applicable for s ummer semesters. \\n2. Academic load limitation is enforced for students on level 2 probation or higher , requiring \\nthem to register for a reduced number of credits in the first semester of the academic year. Specific",
"3 academic probation for the second consecutive time. \\nb) A student exceeds the maximum study duration or is no longer able to meet graduation \\nrequirements within the permitted timeframe as specified in Clause 3, Article 3 of this document . \\nArticle 20. Disciplinary actions for student violations \\nViolations and corresponding disciplinary measures are handled in accordance with the current \\nregulations stipulated in the Regulation s on Student Affairs for Full -Time Undergraduate Students of \\nthe University. \\n 17 \\n \\n CHAPTER III \\nENGINEER PROGRAM S \\nArticle 21. Academic Registration for Engine er Program s \\n1. Academic",
"Chương V\nTỔ CHỨC THỰC HIỆN\nĐiều 12. Trách nhiệm của sinh viên được cấp học bổng\n1. Phối hợp với Ban Công tác sinh viên và các đơn vị, cơ quan chức năng liên\nquan làm thủ tục xuất cảnh.\n2. Chủ động liên hệ với đối tác nước ngoài lập kế hoạch học tập; chịu trách\nnhiệm đảm bảo các hoạt động ở nước ngoài và tiến độ học tập của bản thân.\n3. Tuân thủ các quy định của chương trình học bổng, quy định về việc cấp học\nbổng cho sinh viên đi học tại nước ngoài của ĐHBK Hà Nội, quy định của đơn vị đối\ntác nước ngoài.\n4. Nghiêm chỉnh chấp hành các quy định khác của pháp luật Việt Nam, pháp luật\nvà phong tục tập quán của nước sở tại.",
"thưởng;13\nc) Căn cứ vào đề xuất của Hội đồng khen thưởng sinh viên, Ban Công tác sinh\nviên báo cáo Giám đốc đại học ra quyết định khen thưởng sinh viên đủ điều kiện.\n3. Không xét khen thưởng đối với sinh viên đang trong thời gian xem xét kỷ luật\nhoặc đang trong thời gian thi hành kỷ luật, sinh viên học quá thời gian thiết kế chương\ntrình đào tạo chuẩn (không tính thời gian sinh viên nghỉ học để điều trị bệnh, thời gian\nsinh viên thực hiện nghĩa vụ quân sự theo quy định của Nhà nước).\nĐiều 31. Xử lý kỷ luật \n1. Hình thức kỷ luật:\na) Khiển trách: áp dụng đối với sinh viên có hành vi vi phạm lần đầu nhưng\nở mức độ nhẹ;"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from keepitreal/vietnamese-sbert. 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.
SentenceTransformer(
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': 'RobertaModel'})
(1): Pooling({'word_embedding_dimension': 768, '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})
)
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("hungq/hust_sbert")
# Run inference
sentences = [
'kiện bảo đảm chất lượng, hiệu quả học tập và sự hài lòng của người học đối với các lớp \nhọc phần. \n2. Kết quả học tập trong một học kỳ của sinh viên được đánh giá trên cơ sở điểm của \ncác học phần đã đăng ký học thuộc CTĐT nhưng không tính các học phần có điểm R và \n10 \n \n các học phần về ngoại ngữ cơ bản, Giáo dục thể chất, Giáo dục quốc phòng -an ninh, thể \nhiện bằng các chỉ số sau đây: \na) Tổng số TC của các học phần có điểm đạt trong học kỳ (số TC đạt). \nb) Tổng số TC của các học phần có điểm không đạt trong học kỳ (số TC không đạt). \nc) Điểm trung bình học kỳ (GPA).',
'c) Điểm trung bình học kỳ (GPA). \n3. Kết quả tiến bộ học tập của sinh viên từ đầu khóa được đánh giá trên cơ sở điểm \ncủa các học phần đã học thuộc CTĐT nhưng không tính các học phần về ngoại ngữ cơ bản, \nGiáo dục thể chất, Giáo dục quốc phòng -an ninh, thể hiện bằng các chỉ số sau đây: \na) Số TC tích lũy (số TCTL). \nb) Tổng số TC của các học phần đã học nhưng chưa đạt từ đầu khóa (số TC nợ đọng). \nc) Điểm trung bình tích lũy (CPA). \n4. Kết quả học tập học kỳ hè được đánh giá ở kỳ chính kế tiếp. \n5. Sinh viên được xếp hạng trình độ năm học căn cứ số TC tích lũy (TCTL) như sau: \nSố TCTL < 32 32 - 63 64 - 95 96 -127 ≥ 128',
'cho một học phần yêu cầu trong chương trình. \nb) Người học được phép học một học phần thay thế được chỉ định để lấy kết quả \nthay cho một học phần yêu cầ u trong chương trình nhưng không còn được giảng dạ y. \n6. Đề cương chi tiết của từng học ph ần thể hiện rõ khối lượng học tập, điều kiện \ntham dự học phần, mục tiêu và kết quả mong đợi, mức độ đáp ứng chuẩn đầu ra của \nchương trình, cách thức đánh giá học phần, nội d ung và kế hoạ ch học tập, phương thức \nvà ngôn ngữ giảng dạy, gi áo trình và tà i liệu tham khảo. \nĐiều 5. Đi ểm học phần \n1. Một học phần từ 2 TC trở lên được đánh giá từ hai điểm thành phần là điểm',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.9360, 0.6081],
# [0.9360, 1.0000, 0.5043],
# [0.6081, 0.5043, 1.0000]])
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
2. Nguồn tài trợ hợp pháp từ các tổ chức, cá nhân và doanh nghiệp. |
một văn bằng tốt nghiệp duy nhất. |
1.0 |
tắc như sau: |
Ngày ...... tháng ...... năm ............ |
0.0 |
2. Chương trình trao đổi đăng ký tham gia: |
học hình th ức chính quy và các CTĐT k ể từ khóa 70 tr ở về sau, tr ừ các quy đ ịnh sau: |
0.0 |
CosineSimilarityLoss with these parameters:{
"loss_fct": "torch.nn.modules.loss.MSELoss"
}
per_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 2multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 2max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: Falsebf16: Falsefp16: 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: 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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_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: noneftune_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: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.7246 | 500 | 0.0893 |
| 1.4493 | 1000 | 0.0563 |
@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",
}
Base model
keepitreal/vietnamese-sbert