🚀 Sentence Transformer based on HooshvareLab/bert-base-parsbert-uncased
This model is a fine - tuned sentence - transformers model derived from [HooshvareLab/bert - base - parsbert - uncased](https://huggingface.co/HooshvareLab/bert - base - parsbert - uncased). It aims to enhance Retrieval - Augmented Generation (RAG) systems. By mapping sentences and paragraphs to a 768 - dimensional dense vector space, it can effectively retrieve contextually relevant information, facilitating accurate and coherent response generation in applications like QA systems, chatbots, and content generation.
✨ Features
- High - dimensional Vector Mapping: Maps sentences and paragraphs to a 768 - dimensional dense vector space.
- Enhanced RAG Systems: Ideal for improving the performance of Retrieval - Augmented Generation systems.
- Multilingual Compatibility: Capable of handling Persian text, as demonstrated by the provided examples.
📦 Installation
First, install the Sentence Transformers library:
pip install -U sentence-transformers
If you plan to use it in a RAG system, also install the transformers
library:
pip install -U sentence-transformers transformers
💻 Usage Examples
Basic Usage
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("myrkur/sentence-transformer-parsbert-fa")
sentences = [
'پرتغالی، در وطن اصلی خود، پرتغال، تقریباً توسط ۱۰ میلیون نفر جمعیت صحبت می\u200cشود. پرتغالی همچنین به عنوان زبان رسمی برزیل، بیش از ۲۰۰ میلیون نفر در آن کشور و همچنین کشورهای همسایه، در شرق پاراگوئه و در شمال اروگوئه، سخنگو دارد، که کمی بیش از نیمی از جمعیت آمریکای جنوبی را تشکیل می\u200cدهند؛ بنابراین پرتغالی پرسخنگوترین زبان رسمی رومی در یک کشور واحد است. این زبان در شش کشور آفریقایی زبان رسمی است (آنگولا، دماغه سبز، گینه بیسائو، موزامبیک، گینه استوایی و سائوتومه و پرنسیپ) و توسط ۳۰ میلیون نفر از ساکنان آن قاره به عنوان زبان نخست گویش می\u200cشود. در آسیا، پرتغالی با سایر زبان\u200cها در تیمور شرقی و ماکائو رسمی است، در حالی که بیشتر پرتغالی\u200cزبانان در آسیا - حدود ۴۰۰٫۰۰۰ نفر - به دلیل بازگشت مهاجرت ژاپنی\u200cهای برزیل ساکن ژاپن هستند. در آمریکای شمالی ۱٫۰۰۰٫۰۰۰ نفر به پرتغالی به عنوان زبان نخست خود صحبت می\u200cکنند. پرتغالی در اقیانوسیه به دلیل شمار سخنگویانش در تیمور شرقی، پس از فرانسوی، دومین زبان رومی است که بیش از همه گویش می\u200cشود. نزدیکترین خویشاوند آن، گالیسی، دارای وضعیت رسمی در جامعه خودمختار گالیسیا در اسپانیا، همراه با اسپانیایی است.',
'در حدود اواخر کدام قرن پیش از میلاد سکاهای کوچ\u200cنشین در مرزهای شرقی اشکانیان پیشروی کردند؟',
'عباس جدیدی که بود؟',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
Advanced Usage in RAG Systems
from sentence_transformers import SentenceTransformer, util
import torch
model = SentenceTransformer("myrkur/sentence-transformer-parsbert-fa")
corpus = [
'پرتغالی، در وطن اصلی خود، پرتغال، تقریباً توسط ۱۰ میلیون نفر جمعیت صحبت میشود...',
'اشکانیان حدود دو قرن بر ایران حکومت کردند...',
'عباس جدیدی، کشتیگیر سابق ایرانی است...',
]
corpus_embeddings = model.encode(corpus, convert_to_tensor=True)
query = "عباس جدیدی که بود؟"
query_embedding = model.encode(query, convert_to_tensor=True)
top_k = 5
hits = util.semantic_search(query_embedding, corpus_embeddings, top_k=top_k)
hits = hits[0]
for hit in hits:
print(f"Score: {hit['score']:.4f}")
print(corpus[hit['corpus_id']])
📚 Documentation
Model Details
Model Description
Property |
Details |
Model Type |
Sentence Transformer |
Base model |
[HooshvareLab/bert - base - parsbert - uncased](https://huggingface.co/HooshvareLab/bert - base - parsbert - uncased) |
Maximum Sequence Length |
512 tokens |
Output Dimensionality |
768 tokens |
Similarity Function |
Cosine Similarity |
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
📄 License
This model is licensed under the apache - 2.0
license.
🔗 Contact
For questions or further information, please contact: