Structuring Semantic Embeddings for Principle Evaluation: A Prototype-Guided Contrastive Learning Approach
Organizations: Department of Computer Science The University of Hong Kong, Hong Kong, China · School of Artificial Intelligence and Data Science University of Science and Technology of China, Hefei, Anhui, China
Abstract
Reliable post-hoc evaluation asks whether already generated text satisfies a target criterion after generation. In this paper we study a focused frozen-embedding setting using principle-evaluation proxy tasks: toxicity detection, fine-grained emotion categorization, and ordinal review rating. General-purpose text embeddings are widely deployed for such tasks, but broad semantic similarity can place semantically similar yet task-distinct examples in overlapping regions of the representation space. We introduce Prototype-Guided Contrastive Learning (PGCL), a prototype-guided geometric regularization module built on top of frozen text embeddings. The module combines a semantic stream, a prototype-anchor attention stream, supervised contrastive learning, offset-based prototype-margin regularization, and stream regularization to produce a compact task-adapted representation without updating the base encoder. Controlled experiments show that PGCL improves over raw frozen embeddings on all three datasets and gives the clearest direct-baseline margin on AmazonReviews, while remaining competitive with strong direct frozen metric-learning baselines on GoEmotions and ToxicComment. We also add supervised residual-adapter, encoder-LoRA, full fine-tuning, objective ablation, sensitivity, and fully logged few-shot LLM protocol diagnostics to define the boundary of the claim. The theoretical analysis is revised as a sufficient-condition account for prototype-margin behavior under explicit assumptions in the prototype-mapping space, rather than as an unconditional training or final-embedding separation guarantee.
Figures & tables
| Dataset | Train | Validation | Test |
|---|---|---|---|
| GoEmotions | 5126 | 906 | 881 |
| AmazonReviews | 2271 | 487 | 487 |
| ToxicComment | 44256 | 15073 | 22609 |
| Metric | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| Precision | Raw Emb. | 0.748 0.049 | 0.733 0.059 | 0.737 0.031 | 0.747 0.020 | 0.785 0.031 |
| Opt. Emb. | 0.787 0.035 | 0.789 0.036 | 0.791 0.033 | 0.773 0.028 | 0.787 0.029 | |
| Recall | Raw Emb. | 0.721 0.045 | 0.737 0.031 | 0.722 0.031 | 0.741 0.014 | 0.763 0.024 |
| Opt. Emb. | 0.764 0.034 | 0.769 0.039 | 0.772 0.033 | 0.765 0.039 | 0.769 0.031 | |
| F1 | Raw Emb. | 0.729 0.046 | 0.722 0.035 | 0.726 0.031 | 0.737 0.018 | 0.764 0.036 |
| Opt. Emb. | 0.770 0.033 | 0.767 0.036 | 0.776 0.032 | 0.764 0.026 | 0.770 0.030 |
| Metric | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| MSE | Raw Emb. | 0.668 0.135 | 0.506 0.120 | 0.635 0.097 | 0.546 0.163 | 0.602 0.173 |
| Opt. Emb. | 0.365 0.158 | 0.392 0.143 | 0.394 0.149 | 0.377 0.097 | 0.359 0.086 | |
| RMSE | Raw Emb. | 0.813 0.083 | 0.706 0.083 | 0.795 0.059 | 0.731 0.111 | 0.768 0.110 |
| Opt. Emb. | 0.593 0.119 | 0.617 0.107 | 0.618 0.112 | 0.609 0.080 | 0.595 0.071 | |
| R 2 | Raw Emb. | 0.604 0.086 | 0.700 0.074 | 0.624 0.060 | 0.677 0.095 | 0.643 0.103 |
| Opt. Emb. | 0.785 0.089 | 0.770 0.080 | 0.768 0.083 | 0.777 0.055 | 0.788 0.047 |
| Method | Weighted F1 | MAE ( ) | QWK ( ) | Severe error ( ) |
|---|---|---|---|---|
| Raw embeddings | 0.589 | 0.4784 | 0.8175 | 0.0637 |
| SupCon projection | 0.628 | 0.4271 | 0.8319 | 0.0472 |
| PGCL | 0.727 | 0.3039 | 0.8904 | 0.0205 |
| Metric | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| Avg. F1 | Raw Emb. | 0.932 0.004 | 0.949 0.003 | 0.897 0.004 | 0.918 0.004 | 0.956 0.004 |
| Opt. Emb. | 0.938 0.004 | 0.949 0.004 | 0.936 0.003 | 0.943 0.004 | 0.959 0.004 | |
| Minority F1 | Raw Emb. | 0.497 0.025 | 0.405 0.044 | 0.396 0.018 | 0.433 0.024 | 0.574 0.027 |
| Opt. Emb. | 0.507 0.024 | 0.537 0.035 | 0.493 0.023 | 0.518 0.028 | 0.589 0.023 |
| Dataset | RAW | PGCL | SupCon | Center | Triplet | Prototype | ArcFace | CosFace |
|---|---|---|---|---|---|---|---|---|
| AmazonReviews | 0.589 | 0.727 | 0.628 | 0.597 | 0.592 | 0.599 | 0.588 | 0.566 |
| GoEmotions | 0.726 | 0.772 | 0.757 | 0.755 | 0.759 | 0.764 | 0.747 | 0.752 |
| ToxicComment | 0.915 | 0.953 | 0.949 | 0.951 | 0.943 | 0.947 | 0.948 | 0.949 |
| Dataset | Comparison | Difference | 95% CI |
|---|---|---|---|
| AmazonReviews | PGCL best direct SupCon | 0.0904 | [0.0443, 0.1377] |
| GoEmotions | PGCL best direct center loss | 0.0256 | [0.0011, 0.0473] |
| ToxicComment | PGCL best direct center loss | 0.0009 | [-0.0012, 0.0029] |
| Dataset | PGCL ref. | Frozen residual adapter | Encoder-LoRA | Full fine-tuning |
|---|---|---|---|---|
| AmazonReviews | 0.727 | 0.614 | 0.573 | 0.589 |
| GoEmotions | 0.772 | 0.786 | 0.831 | 0.820 |
| ToxicComment | 0.953 | 0.925 | 0.959 | 0.965 |
| Embedding | SVM | RF | LR | XGB | Trans. | Avg. F1 |
|---|---|---|---|---|---|---|
| Unsupervised SimCSE | 0.851 / 0.568 | 0.823 / 0.539 | 0.843 / 0.572 | 0.840 / 0.567 | 0.730 / 0.407 | 0.531 |
| Standard Supervised | 0.921 / 0.697 | 0.916 / 0.718 | 0.918 / 0.687 | 0.922 / 0.687 | 0.921 / 0.687 | 0.695 |
| PGCL (Ours) | 0.934 / 0.709 | 0.933 / 0.749 | 0.928 / 0.719 | 0.930 / 0.724 | 0.927 / 0.726 | 0.725 |
| Task | Calls | Invalid rate | Avg latency | P95 latency | LLM F1 | PGCL F1 |
|---|---|---|---|---|---|---|
| ToxicComment | 520/520 | 0.000 | 1.182s | 1.310s | 0.940 | 0.947 |
| GoEmotions | 881/881 | 0.000 | 0.793s | 0.859s | 0.680 | 0.772 |
| AmazonReviews | 500/500 | 0.000 | 1.310s | 1.576s | 0.648 | 0.727 |
| Embedding | W/B ratio ( ) | Silhouette ( ) | Class overlap ( ) | GQI ( ) |
|---|---|---|---|---|
| Raw Embeddings | 8.760 | 0.018 | 0.563 | < 0.000 |
| Unsupervised SimCSE | 1.010 | 0.010 | 0.491 | -0.0005 |
| Standard Supervised | 0.458 | 0.158 | 0.286 | 0.0614 |
| PGCL (Ours) | 0.358 | 0.203 | 0.253 | 0.0975 |
| Configuration | Disappt. | Sad. | Disapprv. | Grat. | Apprv. | Average |
|---|---|---|---|---|---|---|
| Only Contrastive Loss | 0.37 | 0.75 | 0.72 | 0.92 | 0.74 | 0.75 |
| Only Offset Loss | 0.40 | 0.75 | 0.72 | 0.94 | 0.77 | 0.77 |
| Without Contrastive Loss | 0.42 | 0.77 | 0.72 | 0.94 | 0.77 | 0.77 |
| Without Offset Loss | 0.44 | 0.71 | 0.73 | 0.93 | 0.76 | 0.77 |
| Raw Embeddings | 0.36 | 0.64 | 0.66 | 0.93 | 0.72 | 0.72 |
| PGCL (Full Model) | 0.49 | 0.77 | 0.72 | 0.94 | 0.76 | 0.78 |
| Dataset | Full | w/o offset | w/o contrast. | w/o orth. | Magnitude |
|---|---|---|---|---|---|
| AmazonReviews | 0.569 | 0.541 | 0.643 | 0.571 | 0.577 |
| GoEmotions | 0.748 | 0.753 | 0.748 | 0.756 | N/A |
| ToxicComment | 0.944 | 0.936 | 0.944 | 0.946 | N/A |
| Dataset | Full | Best interaction | ||||
|---|---|---|---|---|---|---|
| AmazonReviews | 0.584 | 0.525 | 0.664 | 0.578 | 0.577 | Class+offset: 0.637 |
| GoEmotions | 0.745 | 0.757 | 0.758 | 0.756 | 0.744 | Class+contrastive(+offset): 0.754 |
| ToxicComment | 0.945 | 0.941 | 0.947 | 0.949 | 0.945 | Class+contrastive+offset: 0.946 |
| Dataset | Full ref. | Attn. only | Sem./no-attn. | Fixed proto. | Fixed | w/o orth. |
|---|---|---|---|---|---|---|
| AmazonReviews | 0.6217 | 0.5073 | 0.6225 | 0.6170 | 0.6253 | 0.6148 |
| GoEmotions | 0.7519 | 0.7718 | 0.7371 | 0.7544 | 0.7481 | 0.7507 |
| ToxicComment | 0.9494 | 0.9146 | 0.9483 | 0.9469 | 0.9472 | 0.9500 |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Principle | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| Disappt. | Raw Emb. | 0.387 0.090 | 0.237 0.202 | 0.375 0.054 | 0.359 0.144 | 0.315 0.073 |
| Opt. Emb. | 0.482 0.102 | 0.410 0.087 | 0.479 0.106 | 0.439 0.099 | 0.386 0.117 | |
| Sad. | Raw Emb. | 0.643 0.059 | 0.728 0.069 | 0.672 0.081 | 0.711 0.082 | 0.711 0.087 |
| Opt. Emb. | 0.687 0.048 | 0.734 0.031 | 0.721 0.054 | 0.698 0.031 | 0.714 0.034 | |
| Disapprv. | Raw Emb. | 0.663 0.074 | 0.691 0.050 | 0.652 0.070 | 0.703 0.032 | 0.677 0.055 |
| Opt. Emb. | 0.720 0.074 | 0.740 0.064 | 0.728 0.063 | 0.724 0.082 | 0.733 0.059 |
| Ratings | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| 1 - S | Raw Emb. | 0.712 0.219 | 0.772 0.166 | 0.713 0.208 | 0.744 0.235 | 0.731 0.209 |
| Opt. Emb. | 0.869 0.112 | 0.874 0.085 | 0.875 0.084 | 0.894 0.093 | 0.888 0.090 | |
| 2 - S | Raw Emb. | 0.277 0.118 | 0.204 0.213 | 0.297 0.168 | 0.288 0.221 | 0.432 0.163 |
| Opt. Emb. | 0.691 0.187 | 0.708 0.315 | 0.667 0.176 | 0.760 0.170 | 0.711 0.141 | |
| 3 - S | Raw Emb. | 0.433 0.158 | 0.556 0.176 | 0.503 0.081 | 0.520 0.141 | 0.584 0.085 |
| Opt. Emb. | 0.669 0.106 | 0.697 0.073 | 0.662 0.112 | 0.657 0.076 | 0.696 0.143 |
| Metric | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| 1-S MSE | Raw Emb. | 0.483 0.531 | 0.750 1.207 | 0.567 0.533 | 0.957 1.145 | 0.350 0.449 |
| Opt. Emb. | 0.177 0.260 | 0.360 0.543 | 0.140 0.254 | 0.420 0.555 | 0.157 0.250 | |
| 2-S MSE | Raw Emb. | 1.080 0.867 | 1.415 0.880 | 1.250 0.972 | 1.465 0.912 | 1.025 1.072 |
| Opt. Emb. | 0.290 0.386 | 0.435 0.547 | 0.405 0.334 | 0.335 0.338 | 0.265 0.363 | |
| 3-S MSE | Raw Emb. | 0.726 0.431 | 0.623 0.235 | 0.804 0.378 | 0.712 0.269 | 0.539 0.236 |
| Opt. Emb. | 0.386 0.260 | 0.442 0.312 | 0.442 0.367 | 0.509 0.361 | 0.376 0.261 |
| Metric | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| Precision | Raw Emb. | 0.541 0.038 | 0.627 0.093 | 0.595 0.058 | 0.630 0.073 | 0.639 0.067 |
| Opt. Emb. | 0.728 0.077 | 0.726 0.094 | 0.716 0.084 | 0.718 0.077 | 0.725 0.062 | |
| Recall | Raw Emb. | 0.522 0.043 | 0.628 0.083 | 0.583 0.055 | 0.634 0.060 | 0.628 0.064 |
| Opt. Emb. | 0.721 0.073 | 0.729 0.080 | 0.715 0.078 | 0.713 0.069 | 0.723 0.056 | |
| Avg. F1 | Raw Emb. | 0.521 0.041 | 0.609 0.082 | 0.582 0.052 | 0.619 0.059 | 0.622 0.061 |
| Opt. Emb. | 0.717 0.074 | 0.721 0.085 | 0.710 0.081 | 0.708 0.069 | 0.718 0.058 |
| Ratings | Emb. Type | SVM | RF | LR | XGBoost | Transformer |
|---|---|---|---|---|---|---|
| 1 - S | Raw Emb. | 0.712 0.219 | 0.772 0.166 | 0.713 0.208 | 0.744 0.235 | 0.731 0.209 |
| Opt. Emb. | 0.869 0.112 | 0.874 0.085 | 0.875 0.084 | 0.894 0.093 | 0.888 0.090 | |
| 2 - S | Raw Emb. | 0.277 0.118 | 0.204 0.213 | 0.297 0.168 | 0.288 0.221 | 0.432 0.163 |
| Opt. Emb. | 0.691 0.187 | 0.708 0.315 | 0.667 0.176 | 0.760 0.170 | 0.711 0.141 | |
| 3 - S | Raw Emb. | 0.433 0.158 | 0.556 0.176 | 0.503 0.081 | 0.520 0.141 | 0.584 0.085 |
| Opt. Emb. | 0.669 0.106 | 0.697 0.073 | 0.662 0.112 | 0.657 0.076 | 0.696 0.143 |
| Task | Allowed output | Demonstrations | Evaluation subset |
|---|---|---|---|
| ToxicComment | Integer 0/1 or toxic/non-toxic, parsed to binary label | 3 toxic and 10 non-toxic examples, shuffled after class-stratified sampling | 520 examples: 20 toxic, 500 non-toxic |
| GoEmotions | One index from 0-4 for Disappointment, Sadness, Disapproval, Gratitude, Approval | 5 examples per emotion class from single-label training examples | 881 eligible test examples |
| AmazonReviews | One integer rating from 1-5 | 5 examples per rating class from the training split | 500 examples: 50/50/100/150/150 by ratings 1-5 |
| Task | Calls | Invalid | Avg lat. | P95 lat. | Prompt tok. | LLM F1 | PGCL F1 |
|---|---|---|---|---|---|---|---|
| ToxicComment | 520/520 | 0.000 | 1.182s | 1.310s | 1618.4 | 0.940 | 0.947 |
| GoEmotions | 881/881 | 0.000 | 0.793s | 0.859s | 842.6 | 0.680 | 0.772 |
| AmazonReviews | 500/500 | 0.000 | 1.310s | 1.576s | 7732.0 | 0.648 | 0.727 |
| Dataset | Method | Within/Between | Silhouette | Class Overlap | GQI |
|---|---|---|---|---|---|
| AmazonReviews | Raw | 12.4482 | -0.0009 | 0.5823 | 0.0045 |
| AmazonReviews | PGCL | 0.4287 | 0.1894 | 0.3366 | 0.0718 |
| AmazonReviews | Best direct SupCon | 0.5666 | 0.0489 | 0.4897 | 0.0108 |
| GoEmotions | Raw | 14.6009 | 0.0221 | 0.4692 | -0.1598 |
| GoEmotions | PGCL | 0.5202 | 0.2615 | 0.3138 | 0.0861 |
| GoEmotions | Best direct center | 0.7185 | 0.2266 | 0.3008 | 0.0446 |
Text Embedding Models
Text embedding models map words, sentences, or documents to vectors for semantic search, retrieval, clustering, and downstream prediction.
See all 126 papers