ℹ️ This replaces the previous generative approach (LoRA adapter onmeta-llama/Llama-3.1-8B-Instruct) with a dedicated retrieval model.
intfloat/multilingual-e5-baseMultipleNegativesRankingLossSentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'XLMRobertaModel'})
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_mean_tokens': True})
(2): Normalize()
)(document, keyword) samples built from a corpus of Ukrainian scientific/business documents (see dataset_full.jsonl used at training time — not included in this repo, only the resulting keyword index is).query: passage: MultipleNegativesRankingLoss (in-batch negatives, scale=20.0)| Epoch | Step | Training Loss | cosine_ndcg@10 |
|---|---|---|---|
| 1.0 | 410 | – | 0.9085 |
| 2.0 | 820 | – | 0.9157 |
| 3.0 | 1230 | – | 0.9184 |
InformationRetrievalEvaluator on held-out (document, keyword) pairs:| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.965 |
| cosine_accuracy@5 | 0.995 |
| cosine_accuracy@10 | 0.995 |
| cosine_precision@5 | 0.7835 |
| cosine_precision@10 | 0.464 |
| cosine_recall@5 | 0.8075 |
| cosine_recall@10 | 0.9143 |
| cosine_ndcg@10 | 0.9184 |
| cosine_mrr@10 | 0.9773 |
| cosine_map@10 | 0.8754 |
pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("ipsnan/keywordsextraction")
4
5sentences = [
6 "query: Штучний інтелект активно використовується у промисловості для автоматизації процесів...",
7 "passage: штучний інтелект",
8 "passage: автоматизація процесів",
9]
10embeddings = model.encode(sentences)
11print(embeddings.shape) # [3, 768]
12
13similarities = model.similarity(embeddings, embeddings)
14print(similarities)keyword_index.pkl — embeddings of every unique keyword seen during training — and infer_keywords.py, the retrieval script used to go from a raw PDF document straight to a ranked keyword list.1pip install -U sentence-transformers pymupdf numpy
2
3python infer_keywords.py /path/to/file.pdf
4python infer_keywords.py /path/to/file.pdf --top-k 10 --threshold 0.51fullsourcedata.py).query: .keyword_index.pkl by cosine similarity.--threshold.dataset_full.jsonl training corpus and can run python infer_keywords.py <pdf> --rebuild-index.keyword_index.pkl (it is a retrieval model, not a generative one) — rebuild the index on your own keyword set to extend coverage.model.safetensors, config.json, config_sentence_transformers.json, modules.json, sentence_bert_config.json, tokenizer.json, tokenizer_config.json, 1_Pooling/, 2_Normalize/ — the Sentence Transformers modelkeyword_index.pkl — pre-computed keyword embeddings used for retrievalinfer_keywords.py — end-to-end PDF → keywords inference script1fullsourcedata.py — PDF text extraction/cleaning helper used by infer_keywords.pyintfloat/multilingual-e5-base license (MIT)