Views
No views yet
sentence_transformers library to rerank paragraphs based on relevance to a query.1from sentence_transformers import CrossEncoder
2
3# Load the model
4model = CrossEncoder('oddadmix/arabic-reranker', max_length=512)
5
6# Define the query and candidate paragraphs
7Query = 'كيف يمكن استخدام التعلم العميق في معالجة الصور الطبية؟'
8Paragraph1 = 'التعلم العميق يساعد في تحليل الصور الطبية وتشخيص الأمراض'
9Paragraph2 = 'الذكاء الاصطناعي يستخدم في تحسين الإنتاجية في الصناعات'
10
11# Score the paragraphs based on relevance to the query
12scores = model.predict([(Query, Paragraph1), (Query, Paragraph2)])
13
14# Output scores
15print("Score for Paragraph 1:", scores[0])
16print("Score for Paragraph 2:", scores[1])