Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,92 +1,157 @@
|
|
| 1 |
---
|
| 2 |
-
base_model:
|
|
|
|
|
|
|
| 3 |
library_name: model2vec
|
| 4 |
license: mit
|
| 5 |
-
model_name:
|
| 6 |
tags:
|
| 7 |
-
- embeddings
|
| 8 |
- static-embeddings
|
| 9 |
-
-
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of the unknown(https://huggingface.co/unknown) Sentence Transformer. It uses static embeddings, allowing text embeddings to be computed orders of magnitude faster on both GPU and CPU. It is designed for applications where computational resources are limited or where real-time performance is critical. Model2Vec models are the smallest, fastest, and most performant static embedders available. The distilled models are up to 50 times smaller and 500 times faster than traditional Sentence Transformers.
|
| 15 |
|
| 16 |
|
| 17 |
## Installation
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
pip install model2vec
|
| 22 |
```
|
| 23 |
|
| 24 |
## Usage
|
| 25 |
|
| 26 |
-
### Using Model2Vec
|
| 27 |
-
|
| 28 |
-
The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
|
| 29 |
-
|
| 30 |
-
Load this model using the `from_pretrained` method:
|
| 31 |
```python
|
| 32 |
-
from model2vec import
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
# Compute text embeddings
|
| 38 |
-
embeddings = model.encode(["Example sentence"])
|
| 39 |
-
```
|
| 40 |
-
|
| 41 |
-
### Using Sentence Transformers
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
# Load a pretrained Sentence Transformer model
|
| 49 |
-
model = SentenceTransformer("tmpq94ddmo_")
|
| 50 |
-
|
| 51 |
-
# Compute text embeddings
|
| 52 |
-
embeddings = model.encode(["Example sentence"])
|
| 53 |
```
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
You can distill a Model2Vec model from a Sentence Transformer model using the `distill` method. First, install the `distill` extra with `pip install model2vec[distill]`. Then, run the following code:
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
# Save the model
|
| 66 |
-
m2v_model.save_pretrained("m2v_model")
|
| 67 |
-
```
|
| 68 |
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
It works by passing a vocabulary through a sentence transformer model, then reducing the dimensionality of the resulting embeddings using PCA, and finally weighting the embeddings using [SIF weighting](https://openreview.net/pdf?id=SyK00v5xx). During inference, we simply take the mean of all token embeddings occurring in a sentence.
|
| 74 |
|
| 75 |
-
##
|
| 76 |
|
| 77 |
-
-
|
| 78 |
-
- [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)
|
| 79 |
-
- [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)
|
| 80 |
-
- [Model2Vec Docs](https://minish.ai/packages/model2vec/introduction)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
##
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
## Citation
|
| 88 |
|
| 89 |
-
|
|
|
|
| 90 |
```
|
| 91 |
@software{minishlab2024model2vec,
|
| 92 |
author = {Stephan Tulkens and {van Dongen}, Thomas},
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: minishlab/potion-base-2m
|
| 3 |
+
datasets:
|
| 4 |
+
- Intel/polite-guard
|
| 5 |
library_name: model2vec
|
| 6 |
license: mit
|
| 7 |
+
model_name: enguard/tiny-guard-2m-en-general-politeness-binary-intel
|
| 8 |
tags:
|
|
|
|
| 9 |
- static-embeddings
|
| 10 |
+
- text-classification
|
| 11 |
+
- model2vec
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# enguard/tiny-guard-2m-en-general-politeness-binary-intel
|
| 15 |
+
|
| 16 |
+
This model is a fine-tuned Model2Vec classifier based on [minishlab/potion-base-2m](https://huggingface.co/minishlab/potion-base-2m) for the general-politeness-binary found in the [Intel/polite-guard](https://huggingface.co/datasets/Intel/polite-guard) dataset.
|
| 17 |
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
## Installation
|
| 21 |
|
| 22 |
+
```bash
|
| 23 |
+
pip install model2vec[inference]
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
## Usage
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
```python
|
| 29 |
+
from model2vec.inference import StaticModelPipeline
|
| 30 |
|
| 31 |
+
model = StaticModelPipeline.from_pretrained(
|
| 32 |
+
"enguard/tiny-guard-2m-en-general-politeness-binary-intel"
|
| 33 |
+
)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Supports single texts. Format input as a single text:
|
| 37 |
+
text = "Example sentence"
|
| 38 |
|
| 39 |
+
model.predict([text])
|
| 40 |
+
model.predict_proba([text])
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
+
## Why should you use these models?
|
| 45 |
+
|
| 46 |
+
- Optimized for precision to reduce false positives.
|
| 47 |
+
- Extremely fast inference: up to x500 faster than SetFit.
|
| 48 |
+
|
| 49 |
+
## This model variant
|
| 50 |
+
|
| 51 |
+
Below is a quick overview of the model variant and core metrics.
|
| 52 |
+
|
| 53 |
+
| Field | Value |
|
| 54 |
+
|---|---|
|
| 55 |
+
| Classifies | general-politeness-binary |
|
| 56 |
+
| Base Model | [minishlab/potion-base-2m](https://huggingface.co/minishlab/potion-base-2m) |
|
| 57 |
+
| Precision | 0.9843 |
|
| 58 |
+
| Recall | 0.9889 |
|
| 59 |
+
| F1 | 0.9866 |
|
| 60 |
+
|
| 61 |
+
### Confusion Matrix
|
| 62 |
+
|
| 63 |
+
| True \ Predicted | FAIL | PASS |
|
| 64 |
+
| --- | --- | --- |
|
| 65 |
+
| **FAIL** | 2504 | 28 |
|
| 66 |
+
| **PASS** | 40 | 7628 |
|
| 67 |
+
|
| 68 |
+
<details>
|
| 69 |
+
<summary><b>Full metrics (JSON)</b></summary>
|
| 70 |
+
|
| 71 |
+
```json
|
| 72 |
+
{
|
| 73 |
+
"FAIL": {
|
| 74 |
+
"precision": 0.9842767295597484,
|
| 75 |
+
"recall": 0.9889415481832543,
|
| 76 |
+
"f1-score": 0.9866036249014972,
|
| 77 |
+
"support": 2532.0
|
| 78 |
+
},
|
| 79 |
+
"PASS": {
|
| 80 |
+
"precision": 0.9963427377220481,
|
| 81 |
+
"recall": 0.9947835159102765,
|
| 82 |
+
"f1-score": 0.9955625163142783,
|
| 83 |
+
"support": 7668.0
|
| 84 |
+
},
|
| 85 |
+
"accuracy": 0.9933333333333333,
|
| 86 |
+
"macro avg": {
|
| 87 |
+
"precision": 0.9903097336408982,
|
| 88 |
+
"recall": 0.9918625320467653,
|
| 89 |
+
"f1-score": 0.9910830706078877,
|
| 90 |
+
"support": 10200.0
|
| 91 |
+
},
|
| 92 |
+
"weighted avg": {
|
| 93 |
+
"precision": 0.9933475286370538,
|
| 94 |
+
"recall": 0.9933333333333333,
|
| 95 |
+
"f1-score": 0.9933386032694584,
|
| 96 |
+
"support": 10200.0
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
```
|
| 100 |
+
</details>
|
| 101 |
|
|
|
|
| 102 |
|
| 103 |
+
<details>
|
| 104 |
+
<summary><b>Sample Predictions</b></summary>
|
| 105 |
|
| 106 |
+
| Text | True Label | Predicted Label |
|
| 107 |
+
|------|------------|-----------------|
|
| 108 |
+
| I appreciate your interest in our vegetarian options. I can provide you with a list of our current dishes that cater to your dietary preferences. | PASS | PASS |
|
| 109 |
+
| I understand you're concerned about the ski lessons, and I'll look into the options for rescheduling. | PASS | PASS |
|
| 110 |
+
| Our technical skills course will cover the essential topics in data analysis, including data visualization and statistical modeling. The course materials will be available on our learning platform. | PASS | PASS |
|
| 111 |
+
| Our buffet hours are from 11 AM to 9 PM. Please note that we have a limited selection of options available during the lunch break. | PASS | PASS |
|
| 112 |
+
| I'll look into your policy details and see what options are available to you. | PASS | PASS |
|
| 113 |
+
| I appreciate your interest in our vegetarian options. I can provide you with a list of our current dishes that cater to your dietary preferences. | PASS | PASS |
|
| 114 |
+
</details>
|
| 115 |
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
<details>
|
| 118 |
+
<summary><b>Prediction Speed Benchmarks</b></summary>
|
| 119 |
|
| 120 |
+
| Dataset Size | Time (seconds) | Predictions/Second |
|
| 121 |
+
|--------------|----------------|---------------------|
|
| 122 |
+
| 1 | 0.0004 | 2478.9 |
|
| 123 |
+
| 1000 | 0.0557 | 17955.84 |
|
| 124 |
+
| 10000 | 0.6226 | 16062.81 |
|
| 125 |
+
</details>
|
| 126 |
|
|
|
|
| 127 |
|
| 128 |
+
## Other model variants
|
| 129 |
|
| 130 |
+
Below is a general overview of the best-performing models for each dataset variant.
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
| Classifies | Model | Precision | Recall | F1 |
|
| 133 |
+
| --- | --- | --- | --- | --- |
|
| 134 |
+
| general-politeness-binary | [enguard/tiny-guard-2m-en-general-politeness-binary-intel](https://huggingface.co/enguard/tiny-guard-2m-en-general-politeness-binary-intel) | 0.9843 | 0.9889 | 0.9866 |
|
| 135 |
+
| general-politeness-multiclass | [enguard/tiny-guard-2m-en-general-politeness-multiclass-intel](https://huggingface.co/enguard/tiny-guard-2m-en-general-politeness-multiclass-intel) | 0.9875 | 0.9704 | 0.9789 |
|
| 136 |
+
| general-politeness-binary | [enguard/tiny-guard-4m-en-general-politeness-binary-intel](https://huggingface.co/enguard/tiny-guard-4m-en-general-politeness-binary-intel) | 0.9831 | 0.9878 | 0.9854 |
|
| 137 |
+
| general-politeness-multiclass | [enguard/tiny-guard-4m-en-general-politeness-multiclass-intel](https://huggingface.co/enguard/tiny-guard-4m-en-general-politeness-multiclass-intel) | 0.9896 | 0.9783 | 0.9839 |
|
| 138 |
+
| general-politeness-binary | [enguard/tiny-guard-8m-en-general-politeness-binary-intel](https://huggingface.co/enguard/tiny-guard-8m-en-general-politeness-binary-intel) | 0.9828 | 0.9905 | 0.9866 |
|
| 139 |
+
| general-politeness-multiclass | [enguard/tiny-guard-8m-en-general-politeness-multiclass-intel](https://huggingface.co/enguard/tiny-guard-8m-en-general-politeness-multiclass-intel) | 0.9873 | 0.9795 | 0.9833 |
|
| 140 |
+
| general-politeness-binary | [enguard/small-guard-32m-en-general-politeness-binary-intel](https://huggingface.co/enguard/small-guard-32m-en-general-politeness-binary-intel) | 0.9858 | 0.9889 | 0.9874 |
|
| 141 |
+
| general-politeness-multiclass | [enguard/small-guard-32m-en-general-politeness-multiclass-intel](https://huggingface.co/enguard/small-guard-32m-en-general-politeness-multiclass-intel) | 0.9897 | 0.9862 | 0.9879 |
|
| 142 |
+
| general-politeness-binary | [enguard/medium-guard-128m-xx-general-politeness-binary-intel](https://huggingface.co/enguard/medium-guard-128m-xx-general-politeness-binary-intel) | 0.9831 | 0.9901 | 0.9866 |
|
| 143 |
+
| general-politeness-multiclass | [enguard/medium-guard-128m-xx-general-politeness-multiclass-intel](https://huggingface.co/enguard/medium-guard-128m-xx-general-politeness-multiclass-intel) | 0.9881 | 0.9870 | 0.9876 |
|
| 144 |
|
| 145 |
+
## Resources
|
| 146 |
|
| 147 |
+
- Awesome AI Guardrails: <https://github.com/enguard-ai/awesome-ai-guardails>
|
| 148 |
+
- Model2Vec: https://github.com/MinishLab/model2vec
|
| 149 |
+
- Docs: https://minish.ai/packages/model2vec/introduction
|
| 150 |
|
| 151 |
## Citation
|
| 152 |
|
| 153 |
+
If you use this model, please cite Model2Vec:
|
| 154 |
+
|
| 155 |
```
|
| 156 |
@software{minishlab2024model2vec,
|
| 157 |
author = {Stephan Tulkens and {van Dongen}, Thomas},
|