Instructions to use NetworkIsLife/eu-policy-embedder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use NetworkIsLife/eu-policy-embedder with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("NetworkIsLife/eu-policy-embedder") 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
eu_policy passage embedder
A small (6-layer, 384-dim, 23M-parameter) English encoder trained from scratch on EU legal and policy text, for passage embeddings in topic modelling (BERTopic-style) and subject similarity.
Status: research preview, private. Evaluation is still in progress; see Limitations.
Usage
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("<user>/<repo>")
emb = model.encode(passages, batch_size=64, normalize_embeddings=True)
Embed passages of up to ~130 words (max 256 tokens; longer input is truncated), not whole documents.
With BERTopic, use topic-word settings that drop numbers and legal boilerplate, otherwise act numbers and OJ references dominate the topic words:
from bertopic import BERTopic
from bertopic.vectorizers import ClassTfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer, ENGLISH_STOP_WORDS
stop = sorted(ENGLISH_STOP_WORDS | set(["shall", "accordance", "regard", "having", "whereas", "thereof", "hereby", "pursuant", "referred", "laid", "article", "articles", "paragraph", "subparagraph", "point", "points", "annex", "annexes", "regulation", "regulations", "directive", "directives", "decision", "decisions", "commission", "council", "parliament", "european", "union", "community", "communities", "member", "states", "eec", "official", "journal", "amending", "amended", "amendment", "adopted", "adopting", "delegated", "implementing", "provisions", "provided", "necessary", "apply", "applies", "applied", "following"]))
vec = CountVectorizer(ngram_range=(1, 2), min_df=5, stop_words=stop, token_pattern=r"(?u)\b[^\W\d_]{3,}\b")
topic_model = BERTopic(embedding_model=model, vectorizer_model=vec,
ctfidf_model=ClassTfidfTransformer(reduce_frequent_words=True))
topics, _ = topic_model.fit_transform(passages)
Training
- Data: English EUR-Lex legal acts in force, plus adopted acts and Commission proposals linked to European Parliament procedures; ~66k documents, ~2.4M training passages. Documents that are copies or versions of each other were kept in the same train/dev/test split.
- Tokenizer: byte-level BPE, 32k vocabulary, trained on the training split.
- Stage A: masked-language modelling from random initialisation, 3 epochs (111k steps, batch 64).
- Stage B: contrastive fine-tuning (InfoNCE, temperature 0.05, batch 128, 5k steps); the positive for each passage is another passage of the same document, and passages from related documents are not used as negatives.
- No pretrained weights or labels were used in training.
Evaluation (dev split; test split not yet run)
| task | this model | TF-IDF + SVD | difference [95% CI] |
|---|---|---|---|
| Subject neighbours, passage (EuroVoc Jaccard@10) | 0.378 | 0.330 | +0.048 [+0.045, +0.052] |
| Subject neighbours, document | 0.410 | 0.397 | +0.012 [+0.009, +0.015] |
| Title β passages (MRR) | 0.682 | 0.490 | +0.192 [+0.169, +0.214] |
| Proposal β adopted act (MRR) | 0.627 | 0.898 | -0.271 [-0.309, -0.237] |
Subject neighbours: EuroVoc descriptor overlap between a passage and its 10 nearest passages from other documents (chance β 0.10). Proposal β act is a largely lexical task, where TF-IDF is stronger.
Limitations
- English EU legal/policy text only; not tested on other domains or languages.
- Encodes subject rather than wording: weaker than TF-IDF at finding a specific document (e.g. a proposal's own act).
- Some topics group passages by legal form (lists, tables, final provisions) rather than subject.
- Evaluation uses EuroVoc as a proxy for subject; human evaluation is in progress; no test-split figures yet.
Pooling
Standard sentence-transformers mean pooling (including [CLS]/[SEP]) + L2 normalisation. The training pipeline pooled without [CLS]/[SEP]; on 2,000 dev passages the two agree with mean cosine 0.9997 (1st percentile 0.994) and 98.6% identical 10 nearest neighbours.
Licence
Not yet decided. EUR-Lex content is reusable with attribution (Commission Decision 2011/833/EU); the licence of the European Parliament corpora used must be checked before any public release.
Exported from stage_b (selected Stage B step 5000).
- Downloads last month
- -