Views
No views yet
trust_remote_code=True argument when loading it.
It is also recommended to use Flash Attention 2, which can be enabled with attn_implementation argument.
You can use the model like this with sentence-transformers:1from sentence_transformers import SentenceTransformer
2from sentence_transformers.util import cos_sim
3
4model = SentenceTransformer(
5 "sdadas/mmlw-retrieval-roberta-large-v2",
6 trust_remote_code=True,
7 device="cuda",
8 model_kwargs={"attn_implementation": "flash_attention_2", "trust_remote_code": True}
9)
10# Flash-Attention works only in 16-bit mode, so we need to cast the model to float16 or bfloat16
11model.bfloat16()
12
13# Retrieval example
14query_prefix = "[query]: "
15queries = [query_prefix + "Jak dożyć 100 lat?"]
16answers = [
17 "Trzeba zdrowo się odżywiać i uprawiać sport.",
18 "Trzeba pić alkohol, imprezować i jeździć szybkimi autami.",
19 "Gdy trwała kampania politycy zapewniali, że rozprawią się z zakazem niedzielnego handlu."
20]
21queries_emb = model.encode(queries, convert_to_tensor=True, show_progress_bar=False)
22answers_emb = model.encode(answers, convert_to_tensor=True, show_progress_bar=False)
23best_answer = cos_sim(queries_emb, answers_emb).argmax().item()
24print(answers[best_answer])
25
26# Semantic similarity example
27sim_prefix = "[sts]: "
28sentences = [
29 sim_prefix + "Trzeba zdrowo się odżywiać i uprawiać sport.",
30 sim_prefix + "Warto jest prowadzić zdrowy tryb życia, uwzględniający aktywność fizyczną i dietę.",
31 sim_prefix + "One should eat healthy and engage in sports.",
32 sim_prefix + "Zakupy potwierdzasz PINem, który bezpiecznie ustalisz podczas aktywacji."
33]
34emb = model.encode(sentences, convert_to_tensor=True, show_progress_bar=False)
35print(cos_sim(emb, emb))
361@inproceedings{dadas2024pirb,
2 title={PIRB: A Comprehensive Benchmark of Polish Dense and Hybrid Text Retrieval Methods},
3 author={Dadas, Slawomir and Pere{\l}kiewicz, Micha{\l} and Po{\'s}wiata, Rafa{\l}},
4 booktitle={Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)},
5 pages={12761--12774},
6 year={2024}
7}