It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
Fine-tined by
Bogdan Tewunalany
Based on
LaBSE
Using this model becomes easy when you have
sentence-transformers installed:
1 from sentence_transformers import SentenceTransformer
2 sentences = [ "This is an example sentence" , "Бу айтым юлгюдю" ]
3
4 model = SentenceTransformer ( 'TSjB/labse-qm' )
5 embeddings = model . encode ( sentences )
6 print ( embeddings )
1 library ( data.table )
2 library ( reticulate )
3 library ( ggplot2 )
4 library ( ggrepel )
5 library ( Rtsne )
6
7 py_install ( "sentence-transformers" , pip = TRUE )
8 st <- import ( "sentence_transformers" )
9
10 english_sentences = base :: c ( "dog" , "Puppies are nice." , "I enjoy taking long walks along the beach with my dog." )
11 italian_sentences = base :: c ( "cane" , "I cuccioli sono carini." , "Mi piace fare lunghe passeggiate lungo la spiaggia con il mio cane." )
12 qarachay_sentences = base :: c ( "ит" , "Итле джагъымлыдыла." , "Джагъа юсю бла итим бла айланыргъа сюеме." )
13
14 model = st $ SentenceTransformer ( 'TSjB/labse-qm' )
15
16 english_embeddings = model $ encode ( english_sentences )
17 italian_embeddings = model $ encode ( italian_sentences )
18 qarachay_embeddings = model $ encode ( qarachay_sentences )
19
20 m <- rbind ( english_embeddings ,
21 italian_embeddings ,
22 qarachay_embeddings ) %>% as.matrix
23
24 tsne <- Rtsne ( m , perplexity = floor ( ( nrow ( m ) - 1 ) / 3 ) )
25
26
27 tSNE_df <- tsne $ Y %>%
28 as.data.table ( ) %>%
29 setnames ( old = c ( "V1" , "V2" ) , new = c ( "tSNE1" , "tSNE2" ) ) %>%
30 . [ , ` : = ` ( sentence = c ( english_sentences , italian_sentences , qarachay_sentences ) ,
31 language = c ( rep ( "english" , length ( english_sentences ) ) ,
32 rep ( "italian" , length ( italian_sentences ) ) ,
33 rep ( "qarachay" , length ( qarachay_sentences ) ) ) ) ]
34
35
36 tSNE_df %>%
37 ggplot ( aes ( x = tSNE1 ,
38 y = tSNE2 ,
39 color = language ,
40 label = sentence
41 )
42 ) +
43 geom_label_repel ( ) +
44 geom_point ( )
For an automated evaluation of this model, see the
Sentence Embeddings Benchmark :
https://seb.sbert.net
{
"epochs": 1,
"evaluation_steps": 100,
"evaluator": "__main__.ChainScoreEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "warmupcosine",
"steps_per_epoch": null,
"warmup_steps": 1000,
"weight_decay": 0.01
}
SentenceTransformer(
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
(2): Dense({'in_features': 768, 'out_features': 768, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh'})
(3): Normalize()
)