opensanctions / opensanctions/poliloom
Use multilingual labels for embeddings and LLM mapping prompts
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Once multilingual labels with language information are available (see #106), we can leverage them to improve both embedding quality and LLM mapping prompt context.
Context
Currently:
- Embeddings: Positions use
paraphrase-multilingual-MiniLM-L12-v2for semantic search, but only embed the primary entityname(single label) - LLM mapping prompts (Stage 2): Candidate entities show only
nameanddescription, not multilingual label variations - Labels: Stored in
wikidata_entity_labelstable, soon to includelanguage_idper #106
Proposed Enhancements
1. Multilingual Labels in Mapping Prompts (Stage 2)
Current state (poliloom/enrichment.py:288-296):
candidate_entities = [
{
"qid": entity.wikidata_id,
"name": entity.name,
"description": entity.description,
}
for entity in similar_entities
]
Enhancement: Include relevant language labels in candidate context:
candidate_entities = [
{
"qid": entity.wikidata_id,
"name": entity.name,
"description": entity.description,
"labels": {
lang.iso1_code: label.label
for label in entity.language_labels
}
}
for entity in similar_entities
]
Benefits:
- LLM can see entity names in multiple languages during mapping
- Better disambiguation for entities with similar English names but distinct local names
- Matches user's source language context (if source is in French, showing French labels helps)
2. Multilingual Embeddings
Current state (poliloom/enrichment.py:369-375):
texts = [free_item.name for free_item in free_form_results]
embeddings = generate_embeddings_batch(texts)
Enhancement: Include all language labels in embedding input:
texts = [
f"{entity.name} | {' | '.join(entity.labels)}"
for entity in entities
]
This allows the multilingual embedding model to capture semantic meaning across all language variations, improving cross-lingual matching.
Implementation Steps
- Depends on #106: Multilingual labels with language_id must be implemented first
- Update candidate entity serialization to include language-specific labels
- Modify mapping prompts to leverage multilingual context
- Update embedding generation to include all labels
- Consider re-generating embeddings for existing entities (migration)
Files to Modify
poliloom/enrichment.py- Update candidate serialization and embedding generationpoliloom/prompts.py- Update mapping prompts to show multilingual labelspoliloom/models/wikidata.py- Add method to get labels with language info
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dependency #106, then inspect poliloom/enrichment.py at the candidate serialization and embedding-generation sections, poliloom/prompts.py, and poliloom/models/wikidata.py. Confirm how language labels expose their language information before choosing the prompt and embedding inputs. Done means multilingual labels are included in Stage 2 mapping context and embedding generation, with existing embeddings and any migration implications addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, backend, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100