Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 14
How to use TribalChiefBanana/Embedding_miniV2_upgrade with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("TribalChiefBanana/Embedding_miniV2_upgrade")
sentences = [
"Học gì trong khóa Deployment Strategy: Serving the SPA from Spring Boot? phù hợp cho sinh viên năm nhất",
"Deployment Strategy: Serving the SPA from Spring Boot | Explains the unified deployment approach: configuring Spring Boot to **serve the static SPA build files** (HTML, CSS, JS) from its resources folder, simplifying hosting and configuration. | Giải thích cách tiếp cận triển khai thống nhất: cấu hình Spring Boot để **phục vụ các tệp tĩnh của SPA** (HTML, CSS, JS) từ thư mục tài nguyên của nó, đơn giản hóa việc hosting và cấu hình. | Deployment, Triển khai, Static Files, Serving SPA, Spring Boot Deployment, Hosting, Unified Deployment",
"DOE: Introduction to AI for Science | Provides a clear introduction to how AI accelerates scientific discovery, including basic concepts of machine learning, data-driven scientific workflows, and examples from physics, chemistry, and biology. | Cung cấp giới thiệu rõ ràng về cách AI thúc đẩy khám phá khoa học, bao gồm khái niệm ML cơ bản, quy trình khoa học dựa trên dữ liệu và ví dụ từ vật lý, hóa học, sinh học. | AI for Science, Scientific Discovery, Machine Learning Basics, Data-Driven Research, Scientific Workflows",
"Deploying Machine Learning Models in Production - Udemy | Focuses specifically on the final stage of the ML lifecycle: deploying models into a live environment. The course explores various deployment patterns, from simple APIs to scalable serving infrastructure. | Tập trung vào giai đoạn cuối của vòng đời ML: triển khai mô hình vào môi trường thực tế. Khóa học trình bày nhiều mô hình triển khai khác nhau, từ API đơn giản đến hạ tầng phục vụ mô hình có khả năng mở rộng. | Deployment, Model Serving, Production Environment, Scalability, Cloud Deployment, Containerization"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2. It maps sentences & paragraphs to a 384-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': 'BertModel'})
(1): Pooling({'word_embedding_dimension': 384, '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()
)
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("sentence_transformers_model_id")
# Run inference
queries = [
"Cho t\u00f4i kh\u00f3a h\u1ecdc trung c\u1ea5p v\u1ec1 Software Architecture and Design c\u00f3 nhi\u1ec1u b\u00e0i t\u1eadp th\u1ef1c h\u00e0nh",
]
documents = [
"Architectural Styles (Monolith vs. Microservices) - (O'Reilly, YouTube) | Compares monolithic and microservices architectural styles. Explains trade-offs related to development speed, deployment complexity, scalability, and operational overhead to help teams choose an appropriate architecture. | So sánh hai phong cách kiến trúc phổ biến: monolith và microservices. Giải thích các trade-off về tốc độ phát triển, độ phức tạp triển khai, khả năng mở rộng và chi phí vận hành để giúp đội ngũ lựa chọn kiến trúc phù hợp. | Architectural Styles, Monolith, Microservices, System Design, Scalability, Trade-offs, Distributed Systems",
'Input Handling: Mouse, Keyboard, and Mobile Touch | Techniques for capturing player input in C#. Covers both the legacy Input Manager and the modern **Input System** package for handling keyboard, mouse clicks, and touch events on mobile platforms. | Các kỹ thuật thu thập **đầu vào (Input)** của người chơi trong C#. Đề cập đến cả Input Manager cũ và **Input System** hiện đại cho bàn phím, chuột và cảm ứng di động. | Input System, Xử lý đầu vào, Keyboard Input, Mouse Input, Touch Input, MonoBehaviour, C# Scripting',
'Academic Writing Style and Tone - Purdue OWL | Focuses on the mechanics of clear, formal academic writing. Covers concise sentences, correct terminology, objective tone, and coherent paragraph structure. | Tập trung vào kỹ thuật viết học thuật rõ ràng và trang trọng. Trình bày cách viết câu ngắn gọn, dùng thuật ngữ phù hợp, giữ giọng văn khách quan và cấu trúc đoạn văn mạch lạc. | academic style, writing tone, clarity, conciseness, formal writing, paragraph structure, objective tone, academic mechanics',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 384] [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.6604, -0.1001, 0.0158]])
query, positive, and negative| query | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| query | positive | negative |
|---|---|---|
Em muốn ôn lại kiến thức cơ bản Introduction to computing, nên xem khóa nào? |
edX – Computing in Python (Georgia Tech) | Covers program execution models, state changes, loops, functions, and the conceptual mechanics behind code execution. | Bao quát mô hình thực thi chương trình, thay đổi trạng thái, vòng lặp, hàm và cơ chế hoạt động của mã nguồn. | python programming, execution model, control flow, state changes, functions, intro Python course, lập trình Python cơ bản |
Performance Optimization: Image and Asset Loading | Techniques for optimizing website speed by properly sizing, compressing, and serving images (WebP, SVG) and other assets, including lazy loading and caching strategies. | Các kỹ thuật tối ưu hóa tốc độ trang web bằng cách định cỡ, nén và phân phát hình ảnh (WebP, SVG) và các tài sản khác một cách hợp lý, bao gồm chiến lược tải lười (lazy loading) và bộ nhớ đệm (caching). | Web Performance, Optimization, Image Compression, Lazy Loading, Caching, Tối ưu hiệu suất, Tốc độ tải, Bộ nhớ đệm |
Beginner friendly material to understand the basics of Database Systems |
Advanced SQL: MySQL Data Analysis & Business Intelligence on Udemy | Teaches advanced SQL techniques for data analysis and business intelligence reporting using MySQL. Learners master complex queries, window functions, and subqueries to extract meaningful insights from data. | Giảng dạy các kỹ thuật SQL nâng cao dành cho phân tích dữ liệu và báo cáo Business Intelligence với MySQL. Người học sẽ nắm vững truy vấn phức tạp, hàm cửa sổ và truy vấn lồng để khai thác insight ý nghĩa từ dữ liệu. | analytical SQL, business intelligence, window functions, CTEs, reporting queries, MySQL analysis |
Essence of linear algebra & Essence of calculus by 3Blue1Brown on YouTube | Develops a deep, visual intuition for the core ideas of linear algebra and calculus. This series helps learners understand the 'why' behind the formulas, focusing on concepts like vectors, matrices, and the geometric meaning of derivatives. | Phát triển trực giác hình học sâu sắc cho các ý tưởng cốt lõi của đại số tuyến tính và giải tích. Series này giúp người học hiểu được “vì sao” đằng sau các công thức, tập trung vào các khái niệm như vectơ, ma trận và ý nghĩa hình học của đạo hàm. | visual intuition, geometric thinking, vector spaces, matrix intuition, calculus intuition |
What will I learn in the course Introduction to Mobile Development: Native vs. Hybrid vs. Cross-Platform? |
Introduction to Mobile Development: Native vs. Hybrid vs. Cross-Platform | Defines the three main approaches to mobile development: Native (Swift/Kotlin), Hybrid (Web views), and Cross-Platform (single codebase for multiple OS). Highlights the pros and cons of each. | Định nghĩa ba cách tiếp cận chính trong phát triển di động: Native (bản địa), Hybrid (lai), và Cross-Platform (đa nền tảng). Nêu bật ưu và nhược điểm của từng phương pháp. | Cross-Platform, Đa nền tảng, Native, Hybrid, Mobile Development, Phát triển ứng dụng, Single Codebase |
Generics in C#: Defining Type-Safe Collections and Methods | Explains the concept of Generics in C# for creating reusable, type-safe data structures and methods without committing to a specific data type. Focuses on generic collections like |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false
}
learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1overwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 8per_device_eval_batch_size: 8per_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: 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: 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: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0123 | 50 | 1.16 |
| 0.0247 | 100 | 0.9162 |
| 0.0370 | 150 | 0.7569 |
| 0.0493 | 200 | 0.6174 |
| 0.0617 | 250 | 0.5075 |
| 0.0740 | 300 | 0.4455 |
| 0.0863 | 350 | 0.4044 |
| 0.0986 | 400 | 0.4089 |
| 0.1110 | 450 | 0.426 |
| 0.1233 | 500 | 0.3669 |
| 0.1356 | 550 | 0.3157 |
| 0.1480 | 600 | 0.3908 |
| 0.1603 | 650 | 0.2838 |
| 0.1726 | 700 | 0.2972 |
| 0.1850 | 750 | 0.2958 |
| 0.1973 | 800 | 0.3037 |
| 0.2096 | 850 | 0.3593 |
| 0.2219 | 900 | 0.2557 |
| 0.2343 | 950 | 0.2758 |
| 0.2466 | 1000 | 0.3339 |
| 0.2589 | 1050 | 0.2672 |
| 0.2713 | 1100 | 0.3247 |
| 0.2836 | 1150 | 0.3204 |
| 0.2959 | 1200 | 0.2364 |
| 0.3083 | 1250 | 0.2132 |
| 0.3206 | 1300 | 0.2417 |
| 0.3329 | 1350 | 0.2815 |
| 0.3453 | 1400 | 0.2677 |
| 0.3576 | 1450 | 0.2271 |
| 0.3699 | 1500 | 0.2083 |
| 0.3822 | 1550 | 0.2475 |
| 0.3946 | 1600 | 0.2006 |
| 0.4069 | 1650 | 0.2167 |
| 0.4192 | 1700 | 0.2538 |
| 0.4316 | 1750 | 0.1796 |
| 0.4439 | 1800 | 0.2479 |
| 0.4562 | 1850 | 0.2176 |
| 0.4686 | 1900 | 0.2082 |
| 0.4809 | 1950 | 0.2303 |
| 0.4932 | 2000 | 0.1672 |
| 0.5055 | 2050 | 0.2042 |
| 0.5179 | 2100 | 0.1664 |
| 0.5302 | 2150 | 0.159 |
| 0.5425 | 2200 | 0.1508 |
| 0.5549 | 2250 | 0.2056 |
| 0.5672 | 2300 | 0.1705 |
| 0.5795 | 2350 | 0.1747 |
| 0.5919 | 2400 | 0.124 |
| 0.6042 | 2450 | 0.251 |
| 0.6165 | 2500 | 0.1777 |
| 0.6289 | 2550 | 0.1611 |
| 0.6412 | 2600 | 0.1714 |
| 0.6535 | 2650 | 0.1842 |
| 0.6658 | 2700 | 0.2243 |
| 0.6782 | 2750 | 0.2016 |
| 0.6905 | 2800 | 0.1855 |
| 0.7028 | 2850 | 0.1639 |
| 0.7152 | 2900 | 0.2506 |
| 0.7275 | 2950 | 0.1663 |
| 0.7398 | 3000 | 0.2081 |
| 0.7522 | 3050 | 0.1653 |
| 0.7645 | 3100 | 0.1706 |
| 0.7768 | 3150 | 0.2046 |
| 0.7891 | 3200 | 0.1553 |
| 0.8015 | 3250 | 0.1659 |
| 0.8138 | 3300 | 0.1664 |
| 0.8261 | 3350 | 0.1824 |
| 0.8385 | 3400 | 0.1275 |
| 0.8508 | 3450 | 0.1528 |
| 0.8631 | 3500 | 0.1654 |
| 0.8755 | 3550 | 0.1825 |
| 0.8878 | 3600 | 0.1466 |
| 0.9001 | 3650 | 0.1581 |
| 0.9125 | 3700 | 0.189 |
| 0.9248 | 3750 | 0.1769 |
| 0.9371 | 3800 | 0.1264 |
| 0.9494 | 3850 | 0.1393 |
| 0.9618 | 3900 | 0.1481 |
| 0.9741 | 3950 | 0.1756 |
| 0.9864 | 4000 | 0.1675 |
| 0.9988 | 4050 | 0.1672 |
@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",
}
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
nreimers/MiniLM-L6-H384-uncased