Sentence Similarity
sentence-transformers
Safetensors
English
bert
retrieval
legal
agriculture
eu-law
cap
text-embeddings-inference
Instructions to use stonarini/grepac-e5-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use stonarini/grepac-e5-small with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("stonarini/grepac-e5-small") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
File size: 2,025 Bytes
1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 1ccfff1 8940247 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ---
language: [en]
license: mit
library_name: sentence-transformers
pipeline_tag: sentence-similarity
base_model: intfloat/multilingual-e5-small
tags: [sentence-transformers, retrieval, legal, agriculture, eu-law, cap]
---
# grepac-e5-small
[`intfloat/multilingual-e5-small`](https://huggingface.co/intfloat/multilingual-e5-small)
fine-tuned on CPU to find the right article of the EU Common Agricultural Policy (CAP)
regulations for a question. It powers [grePAC](https://huggingface.co/spaces/stonarini/grepac).
Code and training pipeline: [github.com/stonarini/grepac](https://github.com/stonarini/grepac).
## Usage
Same `query: ` / `passage: ` prefixes as the base model.
```python
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("stonarini/grepac-e5-small")
q = model.encode(["query: When will I receive my CAP payments?"], normalize_embeddings=True)
p = model.encode(["passage: Article 44 Payment to beneficiaries\n..."], normalize_embeddings=True)
print(q @ p.T)
```
## Training
The training data is generated, with no hand-written examples:
- a local LLM (Mistral 7B Instruct v0.3) writes questions for each paragraph, plus rule-based queries from titles and definitions
- each question gets a hard negative, a paragraph from another article that looks similar
~3000 training examples over +200 articles. MultipleNegativesRankingLoss, 2 epochs, batch 32, learning rate 2e-5, 73 minutes on a 4-core laptop CPU.
## Evaluation
60 hand-written and hand-checked questions, each with the articles that answer it. Scored per article.
| | right article first | in top 3 | in top 5 | MRR@10 |
|---|---|---|---|---|
| base model | 0.667 | 0.833 | 0.867 | 0.750 |
| grepac-e5-small | 0.717 | 0.900 | 0.900 | 0.797 |
The test is too small to be conclusive: 11 questions improved and 8 got worse. Real searches from the site will be the next test set.
## License
MIT, like the base model. Regulation texts: EUR-Lex, © European Union, reused under the Commission's reuse policy.
|