Integrate with Sentence Transformers (+ third parties like LlamaIndex/LangChain, etc.) (#1)
Browse files- Integrate with Sentence Transformers (c603fc8d0c3322d947d791daffe789508441b381)
- 1_Pooling/config.json +10 -0
- README.md +41 -0
- config_sentence_transformers.json +13 -0
- modules.json +14 -0
- sentence_bert_config.json +4 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
7 |
+
"pooling_mode_weightedmean_tokens": false,
|
8 |
+
"pooling_mode_lasttoken": false,
|
9 |
+
"include_prompt": true
|
10 |
+
}
|
README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2 |
license: mit
|
3 |
datasets:
|
4 |
- rokn/slovlo-dataset-v1
|
|
|
|
|
|
|
5 |
---
|
6 |
|
7 |
The SloVlo (**Slo**venske **Vlo**žitve) project brings purposefully built embeddings and semantic search capabilities to the Slovenian language.
|
@@ -15,6 +18,44 @@ The code is released in the [slovlo](https://github.com/novoselrok/slovlo) repos
|
|
15 |
|
16 |
## Usage
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
```py
|
19 |
import sys
|
20 |
from typing import List
|
|
|
2 |
license: mit
|
3 |
datasets:
|
4 |
- rokn/slovlo-dataset-v1
|
5 |
+
language:
|
6 |
+
- sl
|
7 |
+
library_name: sentence-transformers
|
8 |
---
|
9 |
|
10 |
The SloVlo (**Slo**venske **Vlo**žitve) project brings purposefully built embeddings and semantic search capabilities to the Slovenian language.
|
|
|
18 |
|
19 |
## Usage
|
20 |
|
21 |
+
### Via Sentence Transformers
|
22 |
+
|
23 |
+
```py
|
24 |
+
from sentence_transformers import SentenceTransformer
|
25 |
+
import torch
|
26 |
+
|
27 |
+
model = SentenceTransformer("rokn/slovlo-v1")
|
28 |
+
|
29 |
+
query = "Kam na pohod iz glavnega mesta Slovenije?"
|
30 |
+
|
31 |
+
# First, we define the documents we want to search over.
|
32 |
+
# In our case, that is a list of destination descriptions.
|
33 |
+
documents = [
|
34 |
+
"Triglav je najvišja gora v Sloveniji (2864 m) in simbol slovenske narodne identitete. Pohod je zahteven in običajno traja dva dni. Potrebna je dobra fizična pripravljenost in osnovno znanje plezanja. Priporočena je tudi uporaba vodnika za manj izkušene pohodnike.",
|
35 |
+
"Velika Planina je zelo priljubljena pohodniška destinacija z značilnimi pastirskimi kočami. Pohod je primeren za vse starosti in ponuja čudovite razglede na okoliške gore. Na vrh se lahko povzpnete peš ali z nihalko iz Kamniške Bistrice.",
|
36 |
+
"Bled je znan po kremnih rezinah. Če vas zanima pohod, so pa zraven še Ojstrica, ter Mala in Velika Osojnica.",
|
37 |
+
"Golica je znana po neskončnih poljih narcis v maju. Pohod se začne iz vasi Planina pod Golico in traja približno 2-3 ure. Pot je primerna za vse pohodnike in ponuja lepe razglede na Julijske Alpe in Avstrijo.",
|
38 |
+
"Šmarna Gora je najbolj priljubljena pohodniška destinacija v bližini Ljubljane. Pohod traja približno 1 uro iz Tacna. Na vrhu je koča, kjer lahko uživate v tradicionalni slovenski hrani in lepih razgledih na Ljubljansko kotlino.",
|
39 |
+
"Pohorje je pohodniško območje z različnimi potmi, primernimi za vse starosti in pripravljenosti. Posebej priljubljena je pot do Črnega jezera in Slivniškega jezera. Pozimi je Pohorje tudi priljubljena smučarska destinacija.",
|
40 |
+
]
|
41 |
+
|
42 |
+
# Embed the documents (destinations).
|
43 |
+
document_embeddings = model.encode(documents, prompt_name="document")
|
44 |
+
|
45 |
+
# Embed the user query.
|
46 |
+
query_embedding = model.encode(query, prompt_name="query")
|
47 |
+
|
48 |
+
# Compute dot product between the query and each document.
|
49 |
+
similarities = model.similarity(query_embedding, document_embeddings)
|
50 |
+
|
51 |
+
# Find the nearest neighbor.
|
52 |
+
nearest_index = torch.argmax(similarities).item()
|
53 |
+
|
54 |
+
print("Predlog za tvojo naslednjo avanturo:", documents[nearest_index])
|
55 |
+
```
|
56 |
+
|
57 |
+
### Via Transformers
|
58 |
+
|
59 |
```py
|
60 |
import sys
|
61 |
from typing import List
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "3.0.1",
|
4 |
+
"transformers": "4.41.2",
|
5 |
+
"pytorch": "2.3.1+cu121"
|
6 |
+
},
|
7 |
+
"prompts": {
|
8 |
+
"document": "document: ",
|
9 |
+
"query": "query: "
|
10 |
+
},
|
11 |
+
"default_prompt_name": null,
|
12 |
+
"similarity_fn_name": "cosine"
|
13 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|