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extraction
|
| 6 |
+
- sentence-similarity
|
| 7 |
+
- transformers
|
| 8 |
+
- agent-routing
|
| 9 |
+
- conversation-matching
|
| 10 |
+
language: en
|
| 11 |
+
license: apache-2.0
|
| 12 |
+
datasets:
|
| 13 |
+
- custom
|
| 14 |
+
metrics:
|
| 15 |
+
- cosine_similarity
|
| 16 |
+
base_model: sentence-transformers/all-MiniLM-L12-v2
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# Gatekeeper Agent Responding Model
|
| 20 |
+
|
| 21 |
+
This is a fine-tuned [sentence-transformers](https://www.SBERT.net) model based on **all-MiniLM-L12-v2** that has been specifically trained for **agent routing and conversation matching**. The model determines whether agents should respond to conversations based on semantic similarity.
|
| 22 |
+
|
| 23 |
+
## Model Details
|
| 24 |
+
|
| 25 |
+
### Base Model
|
| 26 |
+
- **Base Model**: [sentence-transformers/all-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L12-v2)
|
| 27 |
+
- **Model Architecture**: MiniLM-L12 (Microsoft)
|
| 28 |
+
- **Embedding Dimensions**: 384
|
| 29 |
+
- **Max Sequence Length**: 256 tokens
|
| 30 |
+
|
| 31 |
+
### Training Data
|
| 32 |
+
The model was fine-tuned on two custom datasets using triplet training:
|
| 33 |
+
- **semantic_triplet_training_data_round1.pkl**: 469 samples
|
| 34 |
+
- **inverse_semantic_triplet_training_data.pkl**: 475 samples
|
| 35 |
+
|
| 36 |
+
Each sample contains:
|
| 37 |
+
- `anchor`: Conversation text or agent description
|
| 38 |
+
- `positive`: Similar/relevant text to the anchor
|
| 39 |
+
- `negative`: Dissimilar/irrelevant text to the anchor
|
| 40 |
+
|
| 41 |
+
### Training Configuration
|
| 42 |
+
- **Loss Function**: MultipleNegativesRankingLoss
|
| 43 |
+
- **Batch Size**: 16
|
| 44 |
+
- **Learning Rate**: 2e-5
|
| 45 |
+
- **Epochs**: 1
|
| 46 |
+
- **Warmup Ratio**: 0.1
|
| 47 |
+
- **Training Framework**: sentence-transformers v2.7.0+
|
| 48 |
+
|
| 49 |
+
### Performance
|
| 50 |
+
Evaluation results on held-out test sets:
|
| 51 |
+
- **Semantic Triplets Accuracy**: 97.87%
|
| 52 |
+
- **Inverse Semantic Triplets Accuracy**: 100.00%
|
| 53 |
+
|
| 54 |
+
## Usage
|
| 55 |
+
|
| 56 |
+
### Direct Usage (Sentence Transformers)
|
| 57 |
+
```python
|
| 58 |
+
from sentence_transformers import SentenceTransformer
|
| 59 |
+
|
| 60 |
+
# Load the model
|
| 61 |
+
model = SentenceTransformer('msugimura/gatekeeper_agent_responding')
|
| 62 |
+
|
| 63 |
+
# Example: Agent routing for conversation
|
| 64 |
+
conversation = "I've been feeling anxious and need help with stress management"
|
| 65 |
+
agent_descriptions = [
|
| 66 |
+
"Licensed therapist specializing in anxiety and stress management",
|
| 67 |
+
"Fitness trainer who creates workout routines for stress relief",
|
| 68 |
+
"Financial advisor who helps with investment planning"
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
# Get embeddings
|
| 72 |
+
conversation_embedding = model.encode(conversation)
|
| 73 |
+
agent_embeddings = model.encode(agent_descriptions)
|
| 74 |
+
|
| 75 |
+
# Calculate similarities
|
| 76 |
+
from sentence_transformers.util import cos_sim
|
| 77 |
+
similarities = cos_sim(conversation_embedding, agent_embeddings)
|
| 78 |
+
|
| 79 |
+
print("Similarity scores:", similarities)
|
| 80 |
+
# Expected: Highest similarity with the therapist
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### API Usage (Portcullis Service)
|
| 84 |
+
```python
|
| 85 |
+
import requests
|
| 86 |
+
|
| 87 |
+
# Example API call to Portcullis service
|
| 88 |
+
response = requests.post("http://localhost:8000/should_agents_respond", json={
|
| 89 |
+
"conversation": "I've been feeling anxious and need help",
|
| 90 |
+
"agent_descriptions": [
|
| 91 |
+
"Licensed therapist specializing in anxiety treatment",
|
| 92 |
+
"Fitness trainer for workout routines",
|
| 93 |
+
"Financial advisor for investments"
|
| 94 |
+
],
|
| 95 |
+
"threshold": 0.4
|
| 96 |
+
})
|
| 97 |
+
|
| 98 |
+
result = response.json()
|
| 99 |
+
print("Qualified agents:", result["qualified_agents"])
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
## Intended Use Cases
|
| 103 |
+
|
| 104 |
+
1. **Agent Routing**: Automatically route conversations to appropriate specialist agents
|
| 105 |
+
2. **Conversation Matching**: Match user queries with relevant service providers
|
| 106 |
+
3. **Semantic Search**: Find similar conversations or agent descriptions
|
| 107 |
+
4. **Content Recommendation**: Recommend agents based on conversation context
|
| 108 |
+
|
| 109 |
+
## Limitations
|
| 110 |
+
|
| 111 |
+
- **Domain Specific**: Optimized for agent-conversation matching scenarios
|
| 112 |
+
- **English Only**: Trained primarily on English text
|
| 113 |
+
- **Context Length**: Limited to 256 tokens per input
|
| 114 |
+
- **Training Data**: Performance depends on similarity to training domain
|
| 115 |
+
|
| 116 |
+
## Technical Details
|
| 117 |
+
|
| 118 |
+
### Model Architecture
|
| 119 |
+
```
|
| 120 |
+
SentenceTransformer(
|
| 121 |
+
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel
|
| 122 |
+
(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})
|
| 123 |
+
(2): Normalize()
|
| 124 |
+
)
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### Training Process
|
| 128 |
+
1. **Data Preprocessing**: Cleaned triplet datasets, removed extraneous columns
|
| 129 |
+
2. **Multi-Dataset Training**: Combined training on both semantic and inverse semantic data
|
| 130 |
+
3. **Loss Function**: MultipleNegativesRankingLoss with in-batch negatives
|
| 131 |
+
4. **Evaluation**: TripletEvaluator on held-out validation sets
|
| 132 |
+
|
| 133 |
+
## Citation
|
| 134 |
+
|
| 135 |
+
If you use this model, please cite:
|
| 136 |
+
|
| 137 |
+
```bibtex
|
| 138 |
+
@misc{gatekeeper_agent_responding_2024,
|
| 139 |
+
title={Gatekeeper Agent Responding Model},
|
| 140 |
+
author={Michael Sugimura},
|
| 141 |
+
year={2024},
|
| 142 |
+
publisher={Hugging Face},
|
| 143 |
+
url={https://huggingface.co/msugimura/gatekeeper_agent_responding}
|
| 144 |
+
}
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Contact
|
| 148 |
+
|
| 149 |
+
For questions or issues, please contact [your-email] or open an issue in the model repository.
|