Add new SentenceTransformer model
Browse files- 1_Pooling/config.json +10 -0
- README.md +1073 -0
- config_sentence_transformers.json +14 -0
- configuration_eurobert.py +216 -0
- model.safetensors +1 -1
- modeling_eurobert.py +1094 -0
- modules.json +20 -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": false,
|
| 5 |
+
"pooling_mode_max_tokens": false,
|
| 6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
| 7 |
+
"pooling_mode_weightedmean_tokens": false,
|
| 8 |
+
"pooling_mode_lasttoken": true,
|
| 9 |
+
"include_prompt": true
|
| 10 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,1073 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- sentence-transformers
|
| 4 |
+
- sentence-similarity
|
| 5 |
+
- feature-extraction
|
| 6 |
+
- dense
|
| 7 |
+
- generated_from_trainer
|
| 8 |
+
- dataset_size:13980
|
| 9 |
+
- loss:MatryoshkaLoss
|
| 10 |
+
- loss:CachedMultipleNegativesRankingLoss
|
| 11 |
+
base_model: jinaai/jina-embeddings-v5-text-nano-retrieval
|
| 12 |
+
widget:
|
| 13 |
+
- source_sentence: 'Query: عُضْوِيَّة كَائِن حَيّ مُتَعَضٍّ'
|
| 14 |
+
sentences:
|
| 15 |
+
- 'Document: # خَثْرَةٌ مُتَعَضِّيَة (جذر: خثر)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## المعجم الطبي الموحد (2009)
|
| 19 |
+
|
| 20 |
+
EN: organized thrombus
|
| 21 |
+
|
| 22 |
+
'
|
| 23 |
+
- 'Document: # كليات وظيفية (جذر: كلل)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## مسرد الإعلام والتواصل، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)
|
| 27 |
+
|
| 28 |
+
EN: functional universals
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
ما تشترك فيه اللغات الطبيعية من جهة الاستعمال.
|
| 32 |
+
|
| 33 |
+
'
|
| 34 |
+
- 'Document: # خَثْرَةٌ مُتَعَضِّيَة (جذر: خثر)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
## المعجم الطبي الموحد (2009)
|
| 38 |
+
|
| 39 |
+
EN: organized thrombus
|
| 40 |
+
|
| 41 |
+
'
|
| 42 |
+
- source_sentence: 'Query: عُضْوِيَّة كَائِن حَيّ مُتَعَضٍّ'
|
| 43 |
+
sentences:
|
| 44 |
+
- 'Document: # كائن حي متعض، متعضية (جذر: كن)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
## المعجم الموحد لمصطلحات الجيولوجيا (2000)
|
| 48 |
+
|
| 49 |
+
EN: organism
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## المعجم الموحد لمصطلحات علوم الزلازل (1999)
|
| 53 |
+
|
| 54 |
+
EN: organism
|
| 55 |
+
|
| 56 |
+
'
|
| 57 |
+
- 'Document: # تربية وظيفية (جذر: رب)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
## مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)
|
| 61 |
+
|
| 62 |
+
EN: functional education
|
| 63 |
+
|
| 64 |
+
'
|
| 65 |
+
- "Document: # الجوهر (جذر: جهر)\n\n## Al-Munāwī, al-Tawqīf ʿalā Muhimmāt al-Taʿārīf\
|
| 66 |
+
\ (d. 1622 CE)\n*التوقيف على مهمات التعاريف للمناوي*\n\nالجوهر: ماهية إذا وجدت\
|
| 67 |
+
\ في الأعيان كانت لا في موضع وهو منحصر في خمسة: هيولى وصورة وجسم ونفس وعقل، لأنه\
|
| 68 |
+
\ إما أن يكون مجردا أو لا، والأول إما أن لا يتعلق بالبدن تعلق تدبير وتصرف أو يتعلق.\
|
| 69 |
+
\ والأول العقل والثاني النفس، وغير المجرد إما مركب أولا، والأول الجسم والثاني\
|
| 70 |
+
\ إما حال أو محل، الأول الصورة والثاني الهيولى وتسمى الحقيقة.فالجوهر ينقسم إلى\
|
| 71 |
+
\ بسيط روحاني كالعقول، والنفوس المجردة، وإلى بسيط جسماني كالعناصر، وإلى مركب في\
|
| 72 |
+
\ العقل دون الخارج كالماهيات الجوهرية المركبة من الجنس والفصل، وإلى مركب منهما\
|
| 73 |
+
\ كالمولدات الثلاثة.\n\n## Al-Tahānawī, Kashshāf Iṣṭilāḥāt al-Funūn wa-l-ʿUlūm\
|
| 74 |
+
\ (d. 1777 CE)\n*كشّاف اصطلاحات الفنون والعلوم للتهانوي*\n\nالجوهر:[في الانكليزية]\
|
| 75 |
+
\ Substance ،essence [ في الفرنسية] Substance ،essence \nيطلق على معان: منها الموجود\
|
| 76 |
+
\ القائم بنفسه حادثا كان أو قديما ويقابله العرض بمعنى ما ليس كذلك. ومنها الحقيقة\
|
| 77 |
+
\ والذات، وبهذا المعنى يقال أي شيء هو في جوهره أي ذاته وحقيقته، ويقابله العرض\
|
| 78 |
+
\ بمعنى الخارج من الحقيقة. والجوهر بهذين المعنيين لا شكّ في جوازه في حقّ الله\
|
| 79 |
+
\ تعالى وإن لم يرد الإذن بالإطلاق. ومنها ما هو من أقسام الموجود الممكن، فهو عند\
|
| 80 |
+
\ المتكلمين لا يكون إلّا حادثا إذ كل ممكن حادث عندهم. وأما عند الحكماء فقد يكون\
|
| 81 |
+
\ قديما كالجوهر المجرّد وقد يكون حادثا كالجوهر المادي. وعند كلا الفريقين لا يجوز\
|
| 82 |
+
\ إطلاقه بهذا المعنى على الله تعالى بناء على أنّه قسم من الممكن. فتعريفه عند المتكلّمين\
|
| 83 |
+
\ الحادث المتحيز بالذات، والمتحيز بالذات هو القابل للإشارة الحسّية بالذات بأنه\
|
| 84 |
+
\ هنا أو هناك، ويقابله العرض. فقال الأشاعرة:العرض هو الحادث القائم بالمتحيّز بالذات\
|
| 85 |
+
\ فخرج الإعدام والسّلوب لعدم حدوثها لأنّ الحادث من أقسام الموجود. وخرج أيضا ذات\
|
| 86 |
+
\ الربّ وصفاته لعدم كونها حادثة ولا قائمة بالمتحيّز بالذات، فإنّ الربّ تعالى ليس\
|
| 87 |
+
\ بمتحيّز أصلا. وبالجملة فذات الربّ تعالى وصفاته ليست بأعراض ولا جواهر. وقال بعض\
|
| 88 |
+
\ الأشاعرة العرض ما كان صفة لغيره وينبغي أن يراد بما الحادث بناء على أنّ العرض\
|
| 89 |
+
\ من أقسام الحادث وألّا ينتقض بالصفات السلبية وبصفات الله تعالى إذا قيل بالتغاير\
|
| 90 |
+
\ بين الذات والصفات كما هو مذهب بعض المتكلمين، وإن لم يكن بالتغاير بينهما فصفات\
|
| 91 |
+
\ الله تعالى تخرج بقيد الغيرية. وقال المعتزلة العرض هو ما لو وجد لقام بالمتحيّز.\
|
| 92 |
+
\ وإنما اختاروا هذا لأنّ العرض ثابت عندهم في العدم منفكا عن الوجود الذي هو زائد\
|
| 93 |
+
\ على الماهية ولا يقوم بالمتحيّز حال العدم، بل إذا وجد العرض قام به. وهذا بناء\
|
| 94 |
+
\ على قولهم بأنّ الثابت في العدم ذوات المعدومات من غير قيام بعضها ببعض، فإنّ القيام\
|
| 95 |
+
\ من خواص الوجود إلّا عند بعضهم، فإنّهم قالوا باتصاف المعدومات بالصفات المعدومة\
|
| 96 |
+
\ الثابتة. ويردّ عليهم فناء الجواهر فإنه عرض عندهم وليس على تقدير وجوده قائما\
|
| 97 |
+
\ بالمتحيّز الذي هو الجوهر عندهم لكونه منافيا للجواهر، ولا ينعكس أيضا على من أثبت\
|
| 98 |
+
\ منهم عرضا لا في محل كأبي هذيل العلّاف، فإنه قال: إنّ بعض أنواع كلام الله لا\
|
| 99 |
+
\ في محل، وكبعض البصريين القائلين بإرادة قائمة لا في محل. وأما ما قيل من أنّ خروجها\
|
| 100 |
+
\ لا يضر [...]\n\n## Academy of the Arabic Language in Cairo, al-Muʿjam al-Wasīṭ\
|
| 101 |
+
\ (1998)\n*المعجم الوسيط لمجموعة من المؤلفين*\n\n(الْجَوْهَر) (انْظُر جَوْهَر)\n\
|
| 102 |
+
\n## Academy of the Arabic Language in Cairo, al-Muʿjam al-Wasīṭ (1998)\n*المعجم\
|
| 103 |
+
\ الوسيط لمجموعة من المؤلفين*\n\n(الْجَوْهَر)جَوْهَر الشَّيْء حَقِيقَته وذاته\
|
| 104 |
+
\ وَمن الْأَحْجَار كل مَا يسْتَخْرج مِنْهُ شَيْء ينْتَفع بِهِ والنفيس الَّذِي\
|
| 105 |
+
\ تتَّخذ مِنْهُ الفصوص وَنَحْوهَا و (فِي الفلسفة) مَا قَامَ بِنَفسِهِ ويقابله\
|
| 106 |
+
\ الْعرض وَهُوَ مَا يقوم بِغَيْرِهِ واحدته جَوْهَرَة (ج) جَوَاهِر\n\n## Aḥmadnagarī,\
|
| 107 |
+
\ Dastūr al-ʿUlamāʾ, or Jāmiʿ al-ʿUlūm fī Iṣṭilāḥāt al-Funūn (d. 18th Century\
|
| 108 |
+
\ CE)\n*دستور العلماء للأحمدنكري*\n\nالْجَوْهَر: الأَصْل: وَفِي عرف الْحُكَمَاء\
|
| 109 |
+
\ هُوَ الْمَوْجُود لَا فِي مَوْضُوع. وَبِعِبَارَة أُخْرَى مَاهِيَّة إِذا وجدت\
|
| 110 |
+
\ فِي الْأَعْيَان كَانَت لَا فِي مَوْضُوع. وَأَيْضًا قَالُوا الْجَوْهَر هُوَ المتحيز\
|
| 111 |
+
\ بِالذَّاتِ فَإِن كَانَ محلا فَهُوَ الهيولى والمادة. وَإِن كَانَ حَالا فَهُوَ\
|
| 112 |
+
\ الصُّورَة الجسمية أَو النوعية. وَإِن لم يكن حَالا وَلَا محلا فَإِن كَانَ مركبا\
|
| 113 |
+
\ مِنْهُمَا فَهُوَ الْجِسْم الطبيعي. وَإِن لم يكن كَذَلِك. فَإِن كَانَ مُتَعَلقا\
|
| 114 |
+
\ بالأجسام تعلق التَّدْبِير وَالتَّصَرُّف فَهُوَ النَّفس الإنسانية أَو الفلكية.\
|
| 115 |
+
\ وَإِلَّا فَهُوَ الْعقل. فأقسام الْجَوْهَر خَمْسَة. ثمَّ إِن الْجَوْهَر منقسم\
|
| 116 |
+
\ إِلَى بسيط روحاني كالعقول والنفوس الْمُجَرَّدَة. وَإِلَى بسيط جسماني كالعناصر.\
|
| 117 |
+
\ وَإِلَى مركب فِي الْعقل دون الْخَارِج كالماهية البسيطة الجوهرية المركبة من الْجِنْس\
|
| 118 |
+
\ والفصل. وَإِلَى مركب مِنْهُمَا كالمواليد الثَّلَاثَة. قيل إِن الْمُلَازمَة فِي\
|
| 119 |
+
\ قَوْلهم ثمَّ الْجَوْهَر إِن كَانَ محلا فَهُوَ الهيولى مَمْنُوع فَإِن الْجِسْم\
|
| 120 |
+
\ مَحل للأعراض مَعَ أَنه لَيْسَ بهيولى وَأجِيب بِأَن المُرَاد إِن كَانَ محلا لجوهر\
|
| 121 |
+
\ آخر فَهُوَ الهيولى بِخِلَاف الْجِسْم فَإِنَّهُ لَيْسَ محلا للجوهر بل للعرض.\
|
| 122 |
+
\ وَفِيه نظر إِذْ النَّفس مَحل للصورة الجوهرية مَعَ أَنَّهَا لَيست هيولى أَقُول\
|
| 123 |
+
\ فِي نظره نظر لِأَن الصُّور ال��وهرية مَا دَامَت فِي الذِّهْن لَا تكون إِلَّا\
|
| 124 |
+
\ اعراضا. فَإِن قلت هَذَا إِنَّمَا يَصح على مَذْهَب من قَالَ بِحُصُول الْأَشْيَاء\
|
| 125 |
+
\ فِي الذِّهْن يَا شباحها واظلالها. وَأما على مَذْهَب من يَقُول بحصولها فِي الذِّهْن\
|
| 126 |
+
\ بِأَعْيَانِهَا فَلَا قلت المُرَاد إِن كَانَ محلا لجوهر دائمي أَي فِي الوجودين\
|
| 127 |
+
\ الذهْنِي والخارجي فَهُوَ الهيولى.\n\n## Al-Mu'jam Al-Kabir\n*المعجم الكبير*\n\
|
| 128 |
+
POS: noun\n\nحجر كريم كالياقوت واللؤلؤ ونحوهما. أصل الشيء وحقيقته. (فارسية معربة).\n\
|
| 129 |
+
\n## Al-Mu'jam Al-Kabir\n*المعجم الكبير*\nPOS: noun\n\nانظره في رسمه\n\n## Al-Mu'jam\
|
| 130 |
+
\ Al-Kabir\n*المعجم الكبير*\nPOS: noun\n\nالدَّرّ : كُلُّ حَجَرٍ يُسْتَخْرج منه\
|
| 131 |
+
\ شيءٌ يُنْتَفَع به. وقيل : النَّفِيس الذى تُتَّخذ منه الفُصوص ونحوُها substance\
|
| 132 |
+
\ (فى المنطق): ما قام بنَفْسِه , فهو مُتَقَوِّمٌ بذاتِه ومُتَعَيِّنٌ بماهيَّتِه\
|
| 133 |
+
\ , وهو المَقُولَةُ الأولى من مَقُولات أرسطو , وبه تقومُ الأعراضُ والكَيْفِيَّات,\
|
| 134 |
+
\ ويقابله العَرَضُ من الشيء: ما كانت عليه جِبلَّتُه\n\n## Al-Mu'jam Al-Wasit\n\
|
| 135 |
+
*المعجم الوسيط*\nPOS: noun\n\n## Al-Mu'jam Al-Wasit\n*المعجم الوسيط*\nPOS: noun\n\
|
| 136 |
+
\nجوهر الشيء: حقيقته وذاته من الأحجار: كل ما يستخرج منه شيء ينتفع به النفيس الذي\
|
| 137 |
+
\ تتخذ منه الفصوص ونحوها (في الفلسفة): ما قام بنفسه. ويقابله العرض\n"
|
| 138 |
+
- source_sentence: 'Query: شَيْء مُسْتَقِلّ — كيان مستقلّ قائم بذاته ومنفصل عن غيره'
|
| 139 |
+
sentences:
|
| 140 |
+
- 'Document: # (1) منفردًا؛ بمَعْزِل to live apart
|
| 141 |
+
|
| 142 |
+
(2) على حدة Each argument was considered apart .
|
| 143 |
+
|
| 144 |
+
(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]
|
| 145 |
+
|
| 146 |
+
(4) بعيدًا بعضهم عن بعض Keep the children apart .
|
| 147 |
+
|
| 148 |
+
(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]
|
| 149 |
+
|
| 150 |
+
(6) مستقلّ؛ منفصل a class apart .
|
| 151 |
+
|
| 152 |
+
to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
## المورد الحديث (2008)
|
| 156 |
+
|
| 157 |
+
EN: apart
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
(1) منفردًا؛ بمَعْزِل to live apart
|
| 161 |
+
|
| 162 |
+
(2) على حدة Each argument was considered apart .
|
| 163 |
+
|
| 164 |
+
(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]
|
| 165 |
+
|
| 166 |
+
(4) بعيدًا بعضهم عن بعض Keep the children apart .
|
| 167 |
+
|
| 168 |
+
(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]
|
| 169 |
+
|
| 170 |
+
(6) مستقلّ؛ منفصل a class apart .
|
| 171 |
+
|
| 172 |
+
to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.
|
| 173 |
+
|
| 174 |
+
'
|
| 175 |
+
- 'Document: # كيان تقديم خدمة في منظومة المساعدة المعيشية النشطة (جذر: كن)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
## موسوعة الكهرباء (IEC 60050)
|
| 179 |
+
|
| 180 |
+
EN: AAL service provider personnel
|
| 181 |
+
|
| 182 |
+
'
|
| 183 |
+
- 'Document: # تَوَاصُلٌ (جذر: صل)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
## المعجم الموحد لمصطلحات الحكامة التربوية (2020)
|
| 187 |
+
|
| 188 |
+
EN: communication
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
## المعجم الموحد لمصطلحات اللسانيات (2002)
|
| 192 |
+
|
| 193 |
+
EN: communication
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
نقل الأخبار بواسطة العلامات والإشارات بين مرسل إلى متلقٍ عبر قناة ما، حيث يعمل
|
| 197 |
+
التواصل بشكل جيّد في وضعية تقاسم الشفرة وغياب التشويش، تنتُج وَظيفة التواصل في
|
| 198 |
+
تعارض مع وظيفة التعبير.
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
## مسرد الإعلام والتواصل، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)
|
| 202 |
+
|
| 203 |
+
EN: intercomminication
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
اتصال متبادل
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
## مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)
|
| 210 |
+
|
| 211 |
+
EN: communication
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
## مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة
|
| 215 |
+
والعلوم (موقع ArabTerm)
|
| 216 |
+
|
| 217 |
+
EN: communication
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
الحوار وتمكين الناس من فهم العوامل الرئيسية لبيئتهم المادية والاجتماعية والاقتصادية
|
| 221 |
+
والسياسية وترابطها بحيث يمكن حل المشكلات الطارئة بكفاءة. منذ أرسطو والعلماء يخوضون
|
| 222 |
+
في نقاش حول النموذج ''العمودي'' (المهيمن) و ''الأفقي'' (الديمقراطي). التواصل يتضمن
|
| 223 |
+
في تعريفه إعطاء المعلومة والحصول على رد الفعل. الإخبار لا يتضمن ذلك. وبالتالي،
|
| 224 |
+
فالتواصل هو حزام نقل بين نشر المعلومات وتخطيط العمل.
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
## مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم
|
| 228 |
+
(موقع ArabTerm)
|
| 229 |
+
|
| 230 |
+
EN: communication
|
| 231 |
+
|
| 232 |
+
'
|
| 233 |
+
- source_sentence: 'Query: كائن حيّ قادر على الفعل أو الأداء الوظيفيّ بشكل مستقلّ،
|
| 234 |
+
أو لديه القدرة على ذلك'
|
| 235 |
+
sentences:
|
| 236 |
+
- 'Document: # المُعَرَّفَةُ (جذر: عرف)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
## Yāqūt al-Ḥamawī, Muʿjam al-Buldān (d. 1229)
|
| 240 |
+
|
| 241 |
+
*معجم البلدان لياقوت الحموي*
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
المُعَرَّفَةُ:
|
| 245 |
+
|
| 246 |
+
منهل بينه وبين كاظمة يوم أو يومان، عن الحفصي.
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
## Al-Suyūṭī, Muʿjam Maqālīd al-ʿUlūm fī l-Ḥudūd wa-l-Rusūm (d. 1505 CE)
|
| 250 |
+
|
| 251 |
+
*معجم مقاليد العلوم للسيوطي*
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
المَعْرِفة: إِدْرَاك صور الموجودات.
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
## Al-Munāwī, al-Tawqīf ʿalā Muhimmāt al-Taʿārīf (d. 1622 CE)
|
| 258 |
+
|
| 259 |
+
*التوقيف على مهمات التعاريف للمناوي*
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
المعرفة: عند النحاة: ما وضع ليدل على شيء بعينه وهي المضمرات والأعلام والمبهمات،
|
| 263 |
+
وما عرف باللام، والمضاف إلى أحدهما.وعند أهل النظر: إدراك الشيء على ما هو عليه
|
| 264 |
+
وهي مسبوقة بنسيان حاصل بعد العلم، ولذلك يسمى الحق تعالى بالعالم دون العارف.المعرفة
|
| 265 |
+
عند القوم: سمو اليقين. وقيل سقوط الوهم لوضوح الاسم. وقيل زوال البرهان بكمال العيان.
|
| 266 |
+
وقيل دثور الريب لظهور الغيب. وقيل هجوم الأنوار على الأبرار.
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
## Al-Tahānawī, Kashshāf Iṣṭilāḥāt al-Funūn wa-l-ʿUlūm (d. 1777 CE)
|
| 270 |
+
|
| 271 |
+
*كشّاف اصطلاحات الفنون والعلوم للتهانوي*
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
المعرفة:[في الانكليزية] Knowledge [ في الفرنسية] Connaissance هي تطلق على معان.
|
| 275 |
+
منها العلم بمعنى الإدراك مطلقا تصوّرا كان أو تصديقا. ولهذا قيل كلّ معرفة وعلم
|
| 276 |
+
فإمّا تصوّر أو تصديق.ومنها التصوّر كما سبق وعلى هذا يسمّى التصديق علما كما مرّ
|
| 277 |
+
أيضا. ومنها إدراك البسيط سواء كان تصوّرا للماهية أو تصديقا بأحوالها، وإدراك المركّب
|
| 278 |
+
سواء كان تصوّرا أو تصديقا، على هذا الاصطلاح يخصّ بالعلم، فبين المعرفة والعلم تباين
|
| 279 |
+
بهذا المعنى، وكلاهما أخصّ من العلم بمعنى الإدراك مطلقا، وكذا الحال في المعنى الثاني
|
| 280 |
+
للمعرفة والعلم. وبهذا الاعتبار يقال عرفت الله دون علمته. ومناسبة هذا الاصطلاح
|
| 281 |
+
بما نسمعه من أئمة اللغة من حيث إنّ متعلّق المعرفة في هذا الاصطلاح وهو البسيط واحد
|
| 282 |
+
ومتعلّق العلم وهو المركّب متعدّد، كما أنّهما كذلك عند أهل اللغة وإن اختلف وجه
|
| 283 |
+
التعدّد والوحدة، فإنّ وجه التعدّد والوحدة في اللغوي يرجع إلى تقييد الاسم الأول
|
| 284 |
+
بإسناد أمر إليه وإطلاقه عنه، سواء كان مدخوله مركّبا أو بسيطا، وفي الاصطلاحي إلى
|
| 285 |
+
نفس المحكوم عليه. فإن كان مركّبا فهو متعلّق العلم وإن كان بسيطا فمتعلّق المعرفة.
|
| 286 |
+
ومنها إدراك الجزئي سواء كان مفهوما جزئيا أو حكما جزئيا، وإدراك الكلّي مفهوما كلّيا
|
| 287 |
+
كان أو حكما كلّيا على هذا الاصطلاح يخصّ بالعلم، وبالنظر إلى هذا يقال أيضا عرفت
|
| 288 |
+
الله دون علمته، والمراد بالحكم التصديق، والنسبة بينهما على هذا على قياس المعنى
|
| 289 |
+
الثاني والثالث، والنسبة بين تلك المعاني الثلاثة للمعرفة هي العموم من وجه، وكذا
|
| 290 |
+
بين تلك المعاني الثلاثة للعلم، وكذا بين المعرفة بالمعنى الثاني أي بمعنى التصوّر
|
| 291 |
+
وبين العلم بالمعنى الثالث الرابع، وكذا بي�� المعرفة بالمعنى الثالث والعلم بالمعنى
|
| 292 |
+
والرابع، وكذا بين المعرفة بالمعنى الرابع والعلم بالمعنى الثالث كما لا يخفى. قيل
|
| 293 |
+
الاصطلاح الثاني والرابع متفرّعان على الثالث لأنّ الجزئي والتصوّر أشبه بالبسيط
|
| 294 |
+
والكلّي والتصديق بالمركّب، هذا والأقرب أن يجعل استعمال المعرفة في التصوّرات والعلم
|
| 295 |
+
في التصديقات أصلا لأنّه عين المعنى اللغوي ثم يفرّع عليه المعنيان الآخران، هكذا
|
| 296 |
+
في شرح المطالع وحواشيه وحواشي المطول. ومنها إدراك الجزئي عن دليل كما في التوضيح
|
| 297 |
+
في تعريف الفقه ويسمّى معرفة استدلالية أيضا. ومنها الإدراك الأخير من الإدراكين
|
| 298 |
+
لشيء واحد إذا تخلّل بينهما عدم بأن أدرك أولا ثم ذهل عنه ثم أدرك ثانيا. قيل [...]
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
## Al-Barakatī, al-Taʿrīfāt al-Fiqhīya (d. 1975 CE)
|
| 302 |
+
|
| 303 |
+
*التعريفات الفقهيّة للبركتي*
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
المَعْرِفة: ما وضع ليدل على شيء بعينه والنَكِرَةُ بخلافه، وأيضاً المعرفة إدراك
|
| 307 |
+
الشيء عليه ما هو عليه، وهي مسبوقة بالجهل أو النسيان بعد العلم بخلاف العلم، ولذلك
|
| 308 |
+
يوصف الحق تعالى بالعالم لا بالعارف. وفي "الكليات": "والعلم يقال لإدراك الكلي أو
|
| 309 |
+
المركب، والمعرفة تقال لإدراك الجزئي أو البسيط ولهذا يقال: عرفت الله دون علمته"،
|
| 310 |
+
وفي "نفحات الأنس" للجامي "معرفت عبارت ست ازباز شاختن معلوم مجمَل در صُوَر تفاصيل".
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
## Academy of the Arabic Language in Cairo, al-Muʿjam al-Wasīṭ (1998)
|
| 314 |
+
|
| 315 |
+
*المعجم الوسيط لمجموعة من المؤلفين*
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
(الْمعرفَة) مَوضِع الْعرف من الطير وَالْخَيْل (ج) معارف
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
## Aḥmadnagarī, Dastūr al-ʿUlamāʾ, or Jāmiʿ al-ʿUlūm fī Iṣṭilāḥāt al-Funūn (d.
|
| 322 |
+
18th Century CE)
|
| 323 |
+
|
| 324 |
+
*دستور العلماء للأحمدنكري*
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
الْمعرفَة: إِدْرَاك الْأَمر الجزئي أَو البسيطة مُطلقًا أَي عَن دَلِيل. أَولا كَمَا
|
| 328 |
+
أَن الْعلم إِدْرَاك الْكُلِّي أَو الْمركب. وَلِهَذَا يُقَال عرفت الله وَلَا يُقَال
|
| 329 |
+
علمت الله. وَأَيْضًا يُقَال للإدراك الْمَسْبُوق بِالْعدمِ أَو للأخير من الإدراكين
|
| 330 |
+
بِشَيْء وَاحِد إِذا تخَلّل بَينهمَا عدم بِأَن أدْرك أَولا ثمَّ ذهل عَنهُ ثَانِيًا
|
| 331 |
+
- وَالْعلم يُقَال للإدراك الْمُجَرّد من هذَيْن الاعتبارين وَلذَا يُقَال الله عَالم
|
| 332 |
+
الأعارف - وَفسّر صدر الشَّرِيعَة الْمعرفَة بِإِدْرَاك الجزئيات عَن دَلِيل - وَاعْترض
|
| 333 |
+
عَلَيْهِ الْمُحَقق التَّفْتَازَانِيّ فِي التَّلْوِيح بقوله والقيد الْأَخير مِمَّا
|
| 334 |
+
لَا دلَالَة عَلَيْهِ أصلا لَا لُغَة وَلَا اصْطِلَاحا انْتهى. وَلَك أَن تَقول لَا
|
| 335 |
+
نسلم أَنه لَا دلَالَة للفظ على هَذَا الْقَيْد لُغَة لِأَن الْمعرفَة إِدْرَاك الشَّيْء
|
| 336 |
+
بتفكر وتدبر. وَلذَا يُقَال عرفت الله إِذْ معرفَة الله تَعَالَى إِنَّمَا هِيَ بتدبر
|
| 337 |
+
آثاره. قَالَ الْعَلامَة الطَّيِّبِيّ لَا يُقَال يعرف الله بل يُقَال يعلم لِأَن
|
| 338 |
+
الْمعرفَة تسْتَعْمل فِي الْعلم الْمَوْصُوف بتفكر وتدبر. وَأَيْضًا لم يطلقوا لفظ
|
| 339 |
+
الْمعرفَة على اعْتِقَاد الْمُقَلّد لِأَنَّهُ لَيْسَ لَهُ معرفَة على دَلِيل. فَلَمَّا
|
| 340 |
+
ثَبت عدم إِطْلَاقهم الْمعرفَة على اعْتِقَاد الْمُقَلّد ثَبت الِاصْطِلَاح أَيْضا
|
| 341 |
+
يَعْنِي أَنهم وَإِن لم يصرحوا بالاصطلاح إِلَّا أَنه وَقع مِنْهُم مَا يدل عَلَيْهِ
|
| 342 |
+
حَيْثُ لم يطلقوا لفظ الْمعرفَة على اعْتِقَاد الْمُقَلّد وَلَيْسَ بِلَازِم أَن
|
| 343 |
+
يصرحوا أَي المصطلحون باصطلاحهم إِذْ كثير من الاصطلاحات إِنَّمَا يعلم بموارد استعمالات
|
| 344 |
+
الْأَلْفَاظ.وَعند النُّحَاة الْمعرفَة مَا يشار بهَا إِلَى مُتَعَيّن أَي مَعْلُوم
|
| 345 |
+
عِنْد السَّامع من حَيْثُ إِنَّه كَذَلِك. والنكرة مَا يشار بهَا إِلَى أَمر مُتَعَيّن
|
| 346 |
+
من حَيْثُ ذَاته وَلَا يقْصد مُلَاحظَة تعينه وَإِن كَانَ مُتَعَيّنا معهودا فِي
|
| 347 |
+
نَفسه فَإِن بَين مصاحبة التَّعْيِين وملاحظته فرقا بَينا. وَذَلِكَ الْأَمر إِمَّا
|
| 348 |
+
فَرد منتشر أَو مَاهِيَّة من حَيْثُ هِيَ على اخْتِلَاف المذهبين كَمَا ذكرنَا فِي
|
| 349 |
+
التَّعْرِيف - والمعرفة خَمْسَة أَنْوَاع - الْمُضْمرَات. والأعلام. وَأَسْمَاء الإشارات.
|
| 350 |
+
والموصلات. وَذُو اللَّام والمضاف إِلَى أَحدهَا.وَتَحْقِيق الْمقَام أَن فهم الْمعَانِي
|
| 351 |
+
من الْأَلْفَاظ إِنَّمَا [...]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
## Aḥmadnagarī, Dastūr al-ʿUlamāʾ, or Jāmiʿ al-ʿUlūm fī Iṣṭilāḥāt al-Funūn (d.
|
| 355 |
+
18th Century CE)
|
| 356 |
+
|
| 357 |
+
*دستور العلماء للأحمدنكري*
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
الْمعرفَة: والمعرفة فِي اصْطِلَاح أَرْبَاب السلوك فِي هِيَ مَا قَالَه الْعَارِف
|
| 361 |
+
النامي قدوة العارفين نور الدّين الشَّيْخ عبد الرَّحْمَن الجامي قدس سره السَّامِي
|
| 362 |
+
فِي (نفحات الْأنس من حضرات الْقُدس) من أَن الْمعرفَة عبارَة عَن إِعَادَة الْمعرفَة
|
| 363 |
+
بالمعلوم الْمُجْمل فِي صور التفاصيل. كَمَا هُوَ فِي (علم النَّحْو) كل من العوامل
|
| 364 |
+
اللفظية والمعنوية وَمَا هُوَ عَملهَا، هَذَا النَّوْع من الْفَهم على سَبِيل الْإِجْمَال
|
| 365 |
+
(هُوَ النَّحْو) . وإعادة فهم كل عَامل مِنْهَا على التَّفْصِيل فِي وَقت قِرَاءَة
|
| 366 |
+
سَواد الْعَرَبيَّة بِلَا توقف وَلَا روية واستعمالها فِي محلهَا هُوَ معرفَة النَّحْو.
|
| 367 |
+
وإعادة الْفَهم بالفكر الْجيد وروية هُوَ التعرف على النَّحْو. إِذا معرفَة الربوبية
|
| 368 |
+
عبارَة عَن إِعَادَة فهم الذَّات وَالصِّفَات الإلهية فِي صور تفاصيل الْأَهْوَال
|
| 369 |
+
والحوادث والنوازل، بعد ذَلِك وعَلى سَبِيل الْإِجْمَال يصبح مَعْلُوما أَن الْمَوْجُود
|
| 370 |
+
الْحَقِيقِيّ وَالْفَاعِل الْمُطلق هُوَ سُبْحَانَهُ، وَحَتَّى تكون صُورَة التَّوْحِيد
|
| 371 |
+
الْمُجْمل مفصلة علميا وَلَا عيب فِيهَا فعلى صَاحب علم التَّوْحِيد أَلا يرى فِي
|
| 372 |
+
صور تفاصيل الوقائع وَالْأَحْوَال المتجددة والمتضادة من ضَرَر ونفع وَمنع وَعَطَاء
|
| 373 |
+
وثابت ومتحول وضار وَنَافِع ومعطي ومانع وقابض وباسط سوى الْحق سُبْحَانَهُ وَتَعَالَى،
|
| 374 |
+
وَأَن لَا يعلم من دون التَّوَقُّف والروية، فَإِذا لم يفعل لَا يُسمى عَارِفًا.
|
| 375 |
+
وَإِذا كَانَ لأوّل وهلة غافلا وحاضرا عَن قريب وَيعرف الْفَاعِل الْمُطلق جلّ ذكره
|
| 376 |
+
فِي صُورَة الوسائط والروابط، فَإِنَّهُ يُسمى متعرفا وَلَيْسَ عَارِفًا، وَإِذا
|
| 377 |
+
كَانَ غافلا كليا ويحول تأثيرات الْأَفْعَال إِلَى الوسائط فَإِنَّهُ يُسمى سَاهِيا
|
| 378 |
+
ولاهيا مُشْركًا خفِيا. مثلا إِذا قرر معنى التَّوْحِيد وَهُوَ مُسْتَغْرق فِي بَحر
|
| 379 |
+
التَّوْحِيد وَالْآخر وعَلى سَبِيل انكاره يعاوده وَيَقُول إِن هَذَا القَوْل لَيْسَ
|
| 380 |
+
عَفْو الخاطر بل نتيجة للفكر والروية، فَيُؤْخَذ فِي الْحَال بغضب وقسوة لِأَنَّهُ
|
| 381 |
+
لَا يعلم أَن جَزَاء هَذَا هُوَ عين مصداق قَول الْمُنكر، وَإِلَّا فالفاعل الْمُطلق
|
| 382 |
+
فِي صُورَة هَذَا الانكار إِعَادَة الْفَهم ويترفق بِهِ.
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
## Al-Mu''jam Al-Wasit
|
| 386 |
+
|
| 387 |
+
*المعجم الوسيط*
|
| 388 |
+
|
| 389 |
+
POS: noun
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
موضعُ العُرْفِ من الطير والخيل
|
| 393 |
+
|
| 394 |
+
'
|
| 395 |
+
- 'Document: # كائِنٌ حَيّ (جذر: كن)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
## The Unified Medical Dictionary
|
| 399 |
+
|
| 400 |
+
*المعجم الطبي الموحد (2009)*
|
| 401 |
+
|
| 402 |
+
EN: bion
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
## Civil Engineering
|
| 406 |
+
|
| 407 |
+
*المعجم الموحد لمصطلحات الهندسة المدنية (2012)*
|
| 408 |
+
|
| 409 |
+
EN: organism
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
## Climate, Environment and Solid Waste management
|
| 413 |
+
|
| 414 |
+
*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة
|
| 415 |
+
والعلوم (موقع ArabTerm)*
|
| 416 |
+
|
| 417 |
+
EN: organism
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
شكل من أشكال الحياة: نبات أو حيوان أو فطريات أو بكتيريا.
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
## Climate, Environment and Solid Waste management
|
| 424 |
+
|
| 425 |
+
*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة
|
| 426 |
+
والعلوم (موقع ArabTerm)*
|
| 427 |
+
|
| 428 |
+
EN: organism
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
نبات أو حيوان أو كائن وحيد الخلية أو أي شكل من أشكال الحياة، منظومة لها مكونات
|
| 432 |
+
مترابطة ومتكاملة تمكن من تحقيق الاستمرارية عن طريق النمو والتكاتر.
|
| 433 |
+
|
| 434 |
+
'
|
| 435 |
+
- 'Document: # الرِّيكِتسيّة: متعضّية مجهرية شبيهة بالبكتيريا.
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
## المورد الحديث (2008)
|
| 439 |
+
|
| 440 |
+
EN: rickettsia
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
الرِّيكِتسيّة: متعضّية مجهرية شبيهة بالبكتيريا.
|
| 444 |
+
|
| 445 |
+
'
|
| 446 |
+
- source_sentence: 'Query: شَيْء مُسْتَقِلّ'
|
| 447 |
+
sentences:
|
| 448 |
+
- 'Document: # قرار فرديّ (جذر: قر)
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
## المعجم الموحد لمصطلحات القانون (2017)
|
| 452 |
+
|
| 453 |
+
EN: individual act
|
| 454 |
+
|
| 455 |
+
'
|
| 456 |
+
- 'Document: # كائِنٌ حَيّ (جذر: كن)
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
## The Unified Medical Dictionary
|
| 460 |
+
|
| 461 |
+
*المعجم الطبي الموحد (2009)*
|
| 462 |
+
|
| 463 |
+
EN: bion
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
## Civil Engineering
|
| 467 |
+
|
| 468 |
+
*المعجم الموحد لمصطلحات الهندسة المدنية (2012)*
|
| 469 |
+
|
| 470 |
+
EN: organism
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
## Climate, Environment and Solid Waste management
|
| 474 |
+
|
| 475 |
+
*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة
|
| 476 |
+
والعلوم (موقع ArabTerm)*
|
| 477 |
+
|
| 478 |
+
EN: organism
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
شكل من أشكال الحياة: نبات أو حيوان أو فطريات أو بكتيريا.
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
## Climate, Environment and Solid Waste management
|
| 485 |
+
|
| 486 |
+
*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة
|
| 487 |
+
والعلوم (موقع ArabTerm)*
|
| 488 |
+
|
| 489 |
+
EN: organism
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
نبات أو حيوان أو كائن وحيد الخلية أو أي شكل من أشكال الحياة، منظومة لها مكونات
|
| 493 |
+
مترابطة ومتكاملة تمكن من تحقيق الاستمرارية عن طريق النمو والتكاتر.
|
| 494 |
+
|
| 495 |
+
'
|
| 496 |
+
- 'Document: # (1) منفردًا؛ بمَعْزِل to live apart
|
| 497 |
+
|
| 498 |
+
(2) على حدة Each argument was considered apart .
|
| 499 |
+
|
| 500 |
+
(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]
|
| 501 |
+
|
| 502 |
+
(4) بعيدًا بعضهم عن بعض Keep the children apart .
|
| 503 |
+
|
| 504 |
+
(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]
|
| 505 |
+
|
| 506 |
+
(6) مستقلّ؛ منفصل a class apart .
|
| 507 |
+
|
| 508 |
+
to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
## المورد الحديث (2008)
|
| 512 |
+
|
| 513 |
+
EN: apart
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
(1) منفردًا؛ بمَعْزِل to live apart
|
| 517 |
+
|
| 518 |
+
(2) على حدة Each argument was considered apart .
|
| 519 |
+
|
| 520 |
+
(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]
|
| 521 |
+
|
| 522 |
+
(4) بعيدًا بعضهم عن بعض Keep the children apart .
|
| 523 |
+
|
| 524 |
+
(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]
|
| 525 |
+
|
| 526 |
+
(6) مستقلّ؛ منفصل a class apart .
|
| 527 |
+
|
| 528 |
+
to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.
|
| 529 |
+
|
| 530 |
+
'
|
| 531 |
+
pipeline_tag: sentence-similarity
|
| 532 |
+
library_name: sentence-transformers
|
| 533 |
+
metrics:
|
| 534 |
+
- cosine_accuracy@1
|
| 535 |
+
- cosine_accuracy@3
|
| 536 |
+
- cosine_accuracy@5
|
| 537 |
+
- cosine_accuracy@10
|
| 538 |
+
- cosine_precision@1
|
| 539 |
+
- cosine_precision@3
|
| 540 |
+
- cosine_precision@5
|
| 541 |
+
- cosine_precision@10
|
| 542 |
+
- cosine_recall@1
|
| 543 |
+
- cosine_recall@3
|
| 544 |
+
- cosine_recall@5
|
| 545 |
+
- cosine_recall@10
|
| 546 |
+
- cosine_ndcg@10
|
| 547 |
+
- cosine_mrr@10
|
| 548 |
+
- cosine_map@100
|
| 549 |
+
model-index:
|
| 550 |
+
- name: SentenceTransformer based on jinaai/jina-embeddings-v5-text-nano-retrieval
|
| 551 |
+
results:
|
| 552 |
+
- task:
|
| 553 |
+
type: information-retrieval
|
| 554 |
+
name: Information Retrieval
|
| 555 |
+
dataset:
|
| 556 |
+
name: jina v5 nano eval
|
| 557 |
+
type: jina-v5-nano-eval
|
| 558 |
+
metrics:
|
| 559 |
+
- type: cosine_accuracy@1
|
| 560 |
+
value: 0.5357142857142857
|
| 561 |
+
name: Cosine Accuracy@1
|
| 562 |
+
- type: cosine_accuracy@3
|
| 563 |
+
value: 0.7380952380952381
|
| 564 |
+
name: Cosine Accuracy@3
|
| 565 |
+
- type: cosine_accuracy@5
|
| 566 |
+
value: 0.8333333333333334
|
| 567 |
+
name: Cosine Accuracy@5
|
| 568 |
+
- type: cosine_accuracy@10
|
| 569 |
+
value: 0.8690476190476191
|
| 570 |
+
name: Cosine Accuracy@10
|
| 571 |
+
- type: cosine_precision@1
|
| 572 |
+
value: 0.5357142857142857
|
| 573 |
+
name: Cosine Precision@1
|
| 574 |
+
- type: cosine_precision@3
|
| 575 |
+
value: 0.29761904761904756
|
| 576 |
+
name: Cosine Precision@3
|
| 577 |
+
- type: cosine_precision@5
|
| 578 |
+
value: 0.21904761904761902
|
| 579 |
+
name: Cosine Precision@5
|
| 580 |
+
- type: cosine_precision@10
|
| 581 |
+
value: 0.12976190476190477
|
| 582 |
+
name: Cosine Precision@10
|
| 583 |
+
- type: cosine_recall@1
|
| 584 |
+
value: 0.33214285714285713
|
| 585 |
+
name: Cosine Recall@1
|
| 586 |
+
- type: cosine_recall@3
|
| 587 |
+
value: 0.534920634920635
|
| 588 |
+
name: Cosine Recall@3
|
| 589 |
+
- type: cosine_recall@5
|
| 590 |
+
value: 0.6603174603174603
|
| 591 |
+
name: Cosine Recall@5
|
| 592 |
+
- type: cosine_recall@10
|
| 593 |
+
value: 0.7523809523809524
|
| 594 |
+
name: Cosine Recall@10
|
| 595 |
+
- type: cosine_ndcg@10
|
| 596 |
+
value: 0.6036435370028103
|
| 597 |
+
name: Cosine Ndcg@10
|
| 598 |
+
- type: cosine_mrr@10
|
| 599 |
+
value: 0.6491685563114135
|
| 600 |
+
name: Cosine Mrr@10
|
| 601 |
+
- type: cosine_map@100
|
| 602 |
+
value: 0.518297872265188
|
| 603 |
+
name: Cosine Map@100
|
| 604 |
+
---
|
| 605 |
+
|
| 606 |
+
# SentenceTransformer based on jinaai/jina-embeddings-v5-text-nano-retrieval
|
| 607 |
+
|
| 608 |
+
This is a [sentence-transformers](https://www.SBERT.net) model finetuned from [jinaai/jina-embeddings-v5-text-nano-retrieval](https://huggingface.co/jinaai/jina-embeddings-v5-text-nano-retrieval). It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
|
| 609 |
+
|
| 610 |
+
## Model Details
|
| 611 |
+
|
| 612 |
+
### Model Description
|
| 613 |
+
- **Model Type:** Sentence Transformer
|
| 614 |
+
- **Base model:** [jinaai/jina-embeddings-v5-text-nano-retrieval](https://huggingface.co/jinaai/jina-embeddings-v5-text-nano-retrieval) <!-- at revision f78e3eca89d031542d392ecba158b248caa1e8c7 -->
|
| 615 |
+
- **Maximum Sequence Length:** 512 tokens
|
| 616 |
+
- **Output Dimensionality:** 768 dimensions
|
| 617 |
+
- **Similarity Function:** Cosine Similarity
|
| 618 |
+
<!-- - **Training Dataset:** Unknown -->
|
| 619 |
+
<!-- - **Language:** Unknown -->
|
| 620 |
+
<!-- - **License:** Unknown -->
|
| 621 |
+
|
| 622 |
+
### Model Sources
|
| 623 |
+
|
| 624 |
+
- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
|
| 625 |
+
- **Repository:** [Sentence Transformers on GitHub](https://github.com/huggingface/sentence-transformers)
|
| 626 |
+
- **Hugging Face:** [Sentence Transformers on Hugging Face](https://huggingface.co/models?library=sentence-transformers)
|
| 627 |
+
|
| 628 |
+
### Full Model Architecture
|
| 629 |
+
|
| 630 |
+
```
|
| 631 |
+
SentenceTransformer(
|
| 632 |
+
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'EuroBertModel'})
|
| 633 |
+
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, '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': True, 'include_prompt': True})
|
| 634 |
+
(2): Normalize()
|
| 635 |
+
)
|
| 636 |
+
```
|
| 637 |
+
|
| 638 |
+
## Usage
|
| 639 |
+
|
| 640 |
+
### Direct Usage (Sentence Transformers)
|
| 641 |
+
|
| 642 |
+
First install the Sentence Transformers library:
|
| 643 |
+
|
| 644 |
+
```bash
|
| 645 |
+
pip install -U sentence-transformers
|
| 646 |
+
```
|
| 647 |
+
|
| 648 |
+
Then you can load this model and run inference.
|
| 649 |
+
```python
|
| 650 |
+
from sentence_transformers import SentenceTransformer
|
| 651 |
+
|
| 652 |
+
# Download from the 🤗 Hub
|
| 653 |
+
model = SentenceTransformer("SalahAbdoNLP/jina-v5-nano-arabic-dict-v2")
|
| 654 |
+
# Run inference
|
| 655 |
+
queries = [
|
| 656 |
+
"Query: \u0634\u064e\u064a\u0652\u0621 \u0645\u064f\u0633\u0652\u062a\u064e\u0642\u0650\u0644\u0651",
|
| 657 |
+
]
|
| 658 |
+
documents = [
|
| 659 |
+
'Document: # (1) منفردًا؛ بمَعْزِل to live apart\n(2) على حدة Each argument was considered apart .\n(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]\n(4) بعيدًا بعضهم عن بعض Keep the children apart .\n(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]\n(6) مستقلّ؛ منفصل a class apart .\nto know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.\n\n## المورد الحديث (2008)\nEN: apart\n\n(1) منفردًا؛ بمَعْزِل to live apart\n(2) على حدة Each argument was considered apart .\n(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]\n(4) بعيدًا بعضهم عن بعض Keep the children apart .\n(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]\n(6) مستقلّ؛ منفصل a class apart .\nto know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.\n',
|
| 660 |
+
'Document: # قرار فرديّ (جذر: قر)\n\n## المعجم الموحد لمصطلحات القانون (2017)\nEN: individual act\n',
|
| 661 |
+
'Document: # كائِنٌ حَيّ (جذر: كن)\n\n## The Unified Medical Dictionary\n*المعجم الطبي الموحد (2009)*\nEN: bion\n\n## Civil Engineering\n*المعجم الموحد لمصطلحات الهندسة المدنية (2012)*\nEN: organism\n\n## Climate, Environment and Solid Waste management\n*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*\nEN: organism\n\nشكل من أشكال الحياة: نبات أو حيوان أو فطريات أو بكتيريا.\n\n## Climate, Environment and Solid Waste management\n*مسرد المناخ والبيئة وإدارة النفايات الصلبة، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*\nEN: organism\n\nنبات أو حيوان أو كائن وحيد الخلية أو أي شكل من أشكال الحياة، منظومة لها مكونات مترابطة ومتكاملة تمكن من تحقيق الاستمرارية عن طريق النمو والتكاتر.\n',
|
| 662 |
+
]
|
| 663 |
+
query_embeddings = model.encode_query(queries)
|
| 664 |
+
document_embeddings = model.encode_document(documents)
|
| 665 |
+
print(query_embeddings.shape, document_embeddings.shape)
|
| 666 |
+
# [1, 768] [3, 768]
|
| 667 |
+
|
| 668 |
+
# Get the similarity scores for the embeddings
|
| 669 |
+
similarities = model.similarity(query_embeddings, document_embeddings)
|
| 670 |
+
print(similarities)
|
| 671 |
+
# tensor([[0.1914, 0.0386, 0.1167]])
|
| 672 |
+
```
|
| 673 |
+
|
| 674 |
+
<!--
|
| 675 |
+
### Direct Usage (Transformers)
|
| 676 |
+
|
| 677 |
+
<details><summary>Click to see the direct usage in Transformers</summary>
|
| 678 |
+
|
| 679 |
+
</details>
|
| 680 |
+
-->
|
| 681 |
+
|
| 682 |
+
<!--
|
| 683 |
+
### Downstream Usage (Sentence Transformers)
|
| 684 |
+
|
| 685 |
+
You can finetune this model on your own dataset.
|
| 686 |
+
|
| 687 |
+
<details><summary>Click to expand</summary>
|
| 688 |
+
|
| 689 |
+
</details>
|
| 690 |
+
-->
|
| 691 |
+
|
| 692 |
+
<!--
|
| 693 |
+
### Out-of-Scope Use
|
| 694 |
+
|
| 695 |
+
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
|
| 696 |
+
-->
|
| 697 |
+
|
| 698 |
+
## Evaluation
|
| 699 |
+
|
| 700 |
+
### Metrics
|
| 701 |
+
|
| 702 |
+
#### Information Retrieval
|
| 703 |
+
|
| 704 |
+
* Dataset: `jina-v5-nano-eval`
|
| 705 |
+
* Evaluated with [<code>InformationRetrievalEvaluator</code>](https://sbert.net/docs/package_reference/sentence_transformer/evaluation.html#sentence_transformers.evaluation.InformationRetrievalEvaluator)
|
| 706 |
+
|
| 707 |
+
| Metric | Value |
|
| 708 |
+
|:--------------------|:-----------|
|
| 709 |
+
| cosine_accuracy@1 | 0.5357 |
|
| 710 |
+
| cosine_accuracy@3 | 0.7381 |
|
| 711 |
+
| cosine_accuracy@5 | 0.8333 |
|
| 712 |
+
| cosine_accuracy@10 | 0.869 |
|
| 713 |
+
| cosine_precision@1 | 0.5357 |
|
| 714 |
+
| cosine_precision@3 | 0.2976 |
|
| 715 |
+
| cosine_precision@5 | 0.219 |
|
| 716 |
+
| cosine_precision@10 | 0.1298 |
|
| 717 |
+
| cosine_recall@1 | 0.3321 |
|
| 718 |
+
| cosine_recall@3 | 0.5349 |
|
| 719 |
+
| cosine_recall@5 | 0.6603 |
|
| 720 |
+
| cosine_recall@10 | 0.7524 |
|
| 721 |
+
| **cosine_ndcg@10** | **0.6036** |
|
| 722 |
+
| cosine_mrr@10 | 0.6492 |
|
| 723 |
+
| cosine_map@100 | 0.5183 |
|
| 724 |
+
|
| 725 |
+
<!--
|
| 726 |
+
## Bias, Risks and Limitations
|
| 727 |
+
|
| 728 |
+
*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
|
| 729 |
+
-->
|
| 730 |
+
|
| 731 |
+
<!--
|
| 732 |
+
### Recommendations
|
| 733 |
+
|
| 734 |
+
*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
|
| 735 |
+
-->
|
| 736 |
+
|
| 737 |
+
## Training Details
|
| 738 |
+
|
| 739 |
+
### Training Dataset
|
| 740 |
+
|
| 741 |
+
#### Unnamed Dataset
|
| 742 |
+
|
| 743 |
+
* Size: 13,980 training samples
|
| 744 |
+
* Columns: <code>anchor</code>, <code>positive</code>, and <code>negative</code>
|
| 745 |
+
* Approximate statistics based on the first 1000 samples:
|
| 746 |
+
| | anchor | positive | negative |
|
| 747 |
+
|:--------|:----------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------|
|
| 748 |
+
| type | string | string | string |
|
| 749 |
+
| details | <ul><li>min: 8 tokens</li><li>mean: 26.71 tokens</li><li>max: 47 tokens</li></ul> | <ul><li>min: 37 tokens</li><li>mean: 339.08 tokens</li><li>max: 512 tokens</li></ul> | <ul><li>min: 25 tokens</li><li>mean: 126.9 tokens</li><li>max: 512 tokens</li></ul> |
|
| 750 |
+
* Samples:
|
| 751 |
+
| anchor | positive | negative |
|
| 752 |
+
|:----------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 753 |
+
| <code>Query: كَيْنُونَة كِيَان — ما يُدرَك أو يُعرَف أو يُستدَلّ على وجوده المستقل، سواء أكان حيًّا أم غير حيّ</code> | <code>Document: # كيان (جذر: كن)<br><br>## Data and AI Glossary<br>*معجم البيانات والذكاء الاصطناعي (2024)*<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## Dictionary of Information Technology Terms<br>*معجم مصطلحات المعلوماتية (2000)*<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## Education<br>*مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## Philosophy and Psychology<br>*مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## Sociology and Anthropology<br>*مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## The Unified Medical Dictionary<br>*المعجم الطبي الموحد (2009)*<br>EN: entity<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>*معجم المصطلحات الطبية (ج.2، 2003)*<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br><br>## Ahmad Mukhtar Umar, Muʿjam ...</code> | <code>Document: # (1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br><br><br>## Al-Mawrid Al-Hadeeth<br>*المورد الحديث (2008)*<br>EN: existence<br><br>(1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br></code> |
|
| 754 |
+
| <code>Query: كَيْنُونَة كِيَان</code> | <code>Document: # كيان (جذر: كن)<br><br>## Data and AI Glossary<br>*معجم البيانات والذكاء الاصطناعي (2024)*<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## Dictionary of Information Technology Terms<br>*معجم مصطلحات المعلوماتية (2000)*<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## Education<br>*مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## Philosophy and Psychology<br>*مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## Sociology and Anthropology<br>*مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## The Unified Medical Dictionary<br>*المعجم الطبي الموحد (2009)*<br>EN: entity<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>*معجم المصطلحات الطبية (ج.2، 2003)*<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br><br>## Ahmad Mukhtar Umar, Muʿjam ...</code> | <code>Document: # (1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br><br><br>## Al-Mawrid Al-Hadeeth<br>*المورد الحديث (2008)*<br>EN: existence<br><br>(1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br></code> |
|
| 755 |
+
| <code>Query: ما يُدرَك أو يُعرَف أو يُستدَلّ على وجوده المستقل، سواء أكان حيًّا أم غير حيّ</code> | <code>Document: # كيان (جذر: كن)<br><br>## Data and AI Glossary<br>*معجم البيانات والذكاء الاصطناعي (2024)*<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## Dictionary of Information Technology Terms<br>*معجم مصطلحات المعلوماتية (2000)*<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## Education<br>*مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## Philosophy and Psychology<br>*مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## Sociology and Anthropology<br>*مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)*<br>EN: entity<br><br>## The Unified Medical Dictionary<br>*المعجم الطبي الموحد (2009)*<br>EN: entity<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>*معجم المصطلحات الطبية (ج.2، 2003)*<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br><br>## Ahmad Mukhtar Umar, Muʿjam ...</code> | <code>Document: # (1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br><br><br>## Al-Mawrid Al-Hadeeth<br>*المورد الحديث (2008)*<br>EN: existence<br><br>(1) كينونة؛ وجود<br>(2) الكائنات مجتمعةً<br>(3) كائن<br>(4) حياة؛ بقاء struggle for existence<br>(5) أسلوبُ حياةٍ.<br></code> |
|
| 756 |
+
* Loss: [<code>MatryoshkaLoss</code>](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#matryoshkaloss) with these parameters:
|
| 757 |
+
```json
|
| 758 |
+
{
|
| 759 |
+
"loss": "CachedMultipleNegativesRankingLoss",
|
| 760 |
+
"matryoshka_dims": [
|
| 761 |
+
768,
|
| 762 |
+
512,
|
| 763 |
+
256,
|
| 764 |
+
128,
|
| 765 |
+
64,
|
| 766 |
+
32
|
| 767 |
+
],
|
| 768 |
+
"matryoshka_weights": [
|
| 769 |
+
1.0,
|
| 770 |
+
1.0,
|
| 771 |
+
1.0,
|
| 772 |
+
1.0,
|
| 773 |
+
1.0,
|
| 774 |
+
1.0
|
| 775 |
+
],
|
| 776 |
+
"n_dims_per_step": -1
|
| 777 |
+
}
|
| 778 |
+
```
|
| 779 |
+
|
| 780 |
+
### Evaluation Dataset
|
| 781 |
+
|
| 782 |
+
#### Unnamed Dataset
|
| 783 |
+
|
| 784 |
+
* Size: 4,536 evaluation samples
|
| 785 |
+
* Columns: <code>anchor</code>, <code>positive</code>, and <code>negative</code>
|
| 786 |
+
* Approximate statistics based on the first 1000 samples:
|
| 787 |
+
| | anchor | positive | negative |
|
| 788 |
+
|:--------|:-----------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------|
|
| 789 |
+
| type | string | string | string |
|
| 790 |
+
| details | <ul><li>min: 12 tokens</li><li>mean: 26.65 tokens</li><li>max: 56 tokens</li></ul> | <ul><li>min: 41 tokens</li><li>mean: 283.31 tokens</li><li>max: 512 tokens</li></ul> | <ul><li>min: 27 tokens</li><li>mean: 129.24 tokens</li><li>max: 512 tokens</li></ul> |
|
| 791 |
+
* Samples:
|
| 792 |
+
| anchor | positive | negative |
|
| 793 |
+
|:-----------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 794 |
+
| <code>Query: شَيْء مُسْتَقِلّ — كيان مستقلّ قائم بذاته ومنفصل عن غيره</code> | <code>Document: # (1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br><br>## المورد الحديث (2008)<br>EN: apart<br><br>(1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br></code> | <code>Document: # كيان (جذر: كن)<br><br>## مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## معجم مصطلحات المعلوماتية (2000)<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## المعجم الطبي الموحد (2009)<br>EN: entity<br><br>## معجم البيانات والذكاء الاصطناعي (2024)<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br></code> |
|
| 795 |
+
| <code>Query: شَيْء مُسْتَقِلّ</code> | <code>Document: # (1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br><br>## المورد الحديث (2008)<br>EN: apart<br><br>(1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br></code> | <code>Document: # كيان (جذر: كن)<br><br>## مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## معجم مصطلحات المعلوماتية (2000)<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## المعجم الطبي الموحد (2009)<br>EN: entity<br><br>## معجم البيانات والذكاء الاصطناعي (2024)<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br></code> |
|
| 796 |
+
| <code>Query: كيان مستقلّ قائم بذاته ومنفصل عن غيره</code> | <code>Document: # (1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br><br>## المورد الحديث (2008)<br>EN: apart<br><br>(1) منفردًا؛ بمَعْزِل to live apart<br>(2) على حدة Each argument was considered apart .<br>(3) جانبًا [كقولك: joking apart أي: إذا وضعنا المُزاح جانبًا وتكلّمنا جدّيًّا]<br>(4) بعيدًا بعضهم عن بعض Keep the children apart .<br>(5) إلى أجزاء [كقولك to take a watch apart أي يفكِّك ساعة]<br>(6) مستقلّ؛ منفصل a class apart .<br>to know (or tell) apart : يميّز بين شيء وآخر.worlds apart : مختلف جدًا.<br></code> | <code>Document: # كيان (جذر: كن)<br><br>## مسرد التربية، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>شيء أو حدث يخزن عنه بيان في قاعدة البيانات.<br><br>## مسرد علم الاجتماع والأنثروبولوجيا، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## مسرد الفلسفة وعلم النفس، المنظمة العربية للتربية والثقافة والعلوم (موقع ArabTerm)<br>EN: entity<br><br>## معجم مصطلحات المعلوماتية (2000)<br>EN: entity<br><br>في التصميم بمعونة الحاسوب والتصميم الغرضي التوجه: بندٌ يمكِن أن يعامَلَ كوحدة مستقلة، وغالباً كعضو من نوع أو صنف معيَّن.<br><br>## المعجم الطبي الموحد (2009)<br>EN: entity<br><br>## معجم البيانات والذكاء الاصطناعي (2024)<br>EN: Entity<br><br>شيء مادي أو غير مادي يمكن التعرُّف عليه وتمييزه بوضوح.<br><br>## معجم المصطلحات الطبية (ج.2، 2003)<br>EN: entity<br><br>حقيقة الشيء أو وجوده المستقل.<br></code> |
|
| 797 |
+
* Loss: [<code>MatryoshkaLoss</code>](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#matryoshkaloss) with these parameters:
|
| 798 |
+
```json
|
| 799 |
+
{
|
| 800 |
+
"loss": "CachedMultipleNegativesRankingLoss",
|
| 801 |
+
"matryoshka_dims": [
|
| 802 |
+
768,
|
| 803 |
+
512,
|
| 804 |
+
256,
|
| 805 |
+
128,
|
| 806 |
+
64,
|
| 807 |
+
32
|
| 808 |
+
],
|
| 809 |
+
"matryoshka_weights": [
|
| 810 |
+
1.0,
|
| 811 |
+
1.0,
|
| 812 |
+
1.0,
|
| 813 |
+
1.0,
|
| 814 |
+
1.0,
|
| 815 |
+
1.0
|
| 816 |
+
],
|
| 817 |
+
"n_dims_per_step": -1
|
| 818 |
+
}
|
| 819 |
+
```
|
| 820 |
+
|
| 821 |
+
### Training Hyperparameters
|
| 822 |
+
#### Non-Default Hyperparameters
|
| 823 |
+
|
| 824 |
+
- `per_device_train_batch_size`: 32
|
| 825 |
+
- `num_train_epochs`: 5
|
| 826 |
+
- `learning_rate`: 2e-05
|
| 827 |
+
- `lr_scheduler_type`: cosine
|
| 828 |
+
- `warmup_steps`: 0.1
|
| 829 |
+
- `fp16`: True
|
| 830 |
+
- `eval_strategy`: epoch
|
| 831 |
+
- `per_device_eval_batch_size`: 32
|
| 832 |
+
- `push_to_hub`: True
|
| 833 |
+
- `hub_model_id`: SalahAbdoNLP/jina-v5-nano-arabic-dict-v2
|
| 834 |
+
- `load_best_model_at_end`: True
|
| 835 |
+
- `batch_sampler`: no_duplicates
|
| 836 |
+
|
| 837 |
+
#### All Hyperparameters
|
| 838 |
+
<details><summary>Click to expand</summary>
|
| 839 |
+
|
| 840 |
+
- `per_device_train_batch_size`: 32
|
| 841 |
+
- `num_train_epochs`: 5
|
| 842 |
+
- `max_steps`: -1
|
| 843 |
+
- `learning_rate`: 2e-05
|
| 844 |
+
- `lr_scheduler_type`: cosine
|
| 845 |
+
- `lr_scheduler_kwargs`: None
|
| 846 |
+
- `warmup_steps`: 0.1
|
| 847 |
+
- `optim`: adamw_torch_fused
|
| 848 |
+
- `optim_args`: None
|
| 849 |
+
- `weight_decay`: 0.0
|
| 850 |
+
- `adam_beta1`: 0.9
|
| 851 |
+
- `adam_beta2`: 0.999
|
| 852 |
+
- `adam_epsilon`: 1e-08
|
| 853 |
+
- `optim_target_modules`: None
|
| 854 |
+
- `gradient_accumulation_steps`: 1
|
| 855 |
+
- `average_tokens_across_devices`: True
|
| 856 |
+
- `max_grad_norm`: 1.0
|
| 857 |
+
- `label_smoothing_factor`: 0.0
|
| 858 |
+
- `bf16`: False
|
| 859 |
+
- `fp16`: True
|
| 860 |
+
- `bf16_full_eval`: False
|
| 861 |
+
- `fp16_full_eval`: False
|
| 862 |
+
- `tf32`: None
|
| 863 |
+
- `gradient_checkpointing`: False
|
| 864 |
+
- `gradient_checkpointing_kwargs`: None
|
| 865 |
+
- `torch_compile`: False
|
| 866 |
+
- `torch_compile_backend`: None
|
| 867 |
+
- `torch_compile_mode`: None
|
| 868 |
+
- `use_liger_kernel`: False
|
| 869 |
+
- `liger_kernel_config`: None
|
| 870 |
+
- `use_cache`: False
|
| 871 |
+
- `neftune_noise_alpha`: None
|
| 872 |
+
- `torch_empty_cache_steps`: None
|
| 873 |
+
- `auto_find_batch_size`: False
|
| 874 |
+
- `log_on_each_node`: True
|
| 875 |
+
- `logging_nan_inf_filter`: True
|
| 876 |
+
- `include_num_input_tokens_seen`: no
|
| 877 |
+
- `log_level`: passive
|
| 878 |
+
- `log_level_replica`: warning
|
| 879 |
+
- `disable_tqdm`: False
|
| 880 |
+
- `project`: huggingface
|
| 881 |
+
- `trackio_space_id`: trackio
|
| 882 |
+
- `eval_strategy`: epoch
|
| 883 |
+
- `per_device_eval_batch_size`: 32
|
| 884 |
+
- `prediction_loss_only`: True
|
| 885 |
+
- `eval_on_start`: False
|
| 886 |
+
- `eval_do_concat_batches`: True
|
| 887 |
+
- `eval_use_gather_object`: False
|
| 888 |
+
- `eval_accumulation_steps`: None
|
| 889 |
+
- `include_for_metrics`: []
|
| 890 |
+
- `batch_eval_metrics`: False
|
| 891 |
+
- `save_only_model`: False
|
| 892 |
+
- `save_on_each_node`: False
|
| 893 |
+
- `enable_jit_checkpoint`: False
|
| 894 |
+
- `push_to_hub`: True
|
| 895 |
+
- `hub_private_repo`: None
|
| 896 |
+
- `hub_model_id`: SalahAbdoNLP/jina-v5-nano-arabic-dict-v2
|
| 897 |
+
- `hub_strategy`: every_save
|
| 898 |
+
- `hub_always_push`: False
|
| 899 |
+
- `hub_revision`: None
|
| 900 |
+
- `load_best_model_at_end`: True
|
| 901 |
+
- `ignore_data_skip`: False
|
| 902 |
+
- `restore_callback_states_from_checkpoint`: False
|
| 903 |
+
- `full_determinism`: False
|
| 904 |
+
- `seed`: 42
|
| 905 |
+
- `data_seed`: None
|
| 906 |
+
- `use_cpu`: False
|
| 907 |
+
- `accelerator_config`: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
|
| 908 |
+
- `parallelism_config`: None
|
| 909 |
+
- `dataloader_drop_last`: False
|
| 910 |
+
- `dataloader_num_workers`: 0
|
| 911 |
+
- `dataloader_pin_memory`: True
|
| 912 |
+
- `dataloader_persistent_workers`: False
|
| 913 |
+
- `dataloader_prefetch_factor`: None
|
| 914 |
+
- `remove_unused_columns`: True
|
| 915 |
+
- `label_names`: None
|
| 916 |
+
- `train_sampling_strategy`: random
|
| 917 |
+
- `length_column_name`: length
|
| 918 |
+
- `ddp_find_unused_parameters`: None
|
| 919 |
+
- `ddp_bucket_cap_mb`: None
|
| 920 |
+
- `ddp_broadcast_buffers`: False
|
| 921 |
+
- `ddp_backend`: None
|
| 922 |
+
- `ddp_timeout`: 1800
|
| 923 |
+
- `fsdp`: []
|
| 924 |
+
- `fsdp_config`: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
|
| 925 |
+
- `deepspeed`: None
|
| 926 |
+
- `debug`: []
|
| 927 |
+
- `skip_memory_metrics`: True
|
| 928 |
+
- `do_predict`: False
|
| 929 |
+
- `resume_from_checkpoint`: None
|
| 930 |
+
- `warmup_ratio`: None
|
| 931 |
+
- `local_rank`: -1
|
| 932 |
+
- `prompts`: None
|
| 933 |
+
- `batch_sampler`: no_duplicates
|
| 934 |
+
- `multi_dataset_batch_sampler`: proportional
|
| 935 |
+
- `router_mapping`: {}
|
| 936 |
+
- `learning_rate_mapping`: {}
|
| 937 |
+
|
| 938 |
+
</details>
|
| 939 |
+
|
| 940 |
+
### Training Logs
|
| 941 |
+
| Epoch | Step | Training Loss | Validation Loss | jina-v5-nano-eval_cosine_ndcg@10 |
|
| 942 |
+
|:-------:|:-------:|:-------------:|:---------------:|:--------------------------------:|
|
| 943 |
+
| -1 | -1 | - | - | 0.4604 |
|
| 944 |
+
| 0.0913 | 20 | 12.2331 | - | - |
|
| 945 |
+
| 0.1826 | 40 | 4.3754 | - | - |
|
| 946 |
+
| 0.2740 | 60 | 2.4520 | - | - |
|
| 947 |
+
| 0.3653 | 80 | 2.0269 | - | - |
|
| 948 |
+
| 0.4566 | 100 | 2.1203 | - | - |
|
| 949 |
+
| 0.5479 | 120 | 1.7343 | - | - |
|
| 950 |
+
| 0.6393 | 140 | 1.7345 | - | - |
|
| 951 |
+
| 0.7306 | 160 | 1.8540 | - | - |
|
| 952 |
+
| 0.8219 | 180 | 1.5593 | - | - |
|
| 953 |
+
| 0.9132 | 200 | 1.7133 | - | - |
|
| 954 |
+
| **1.0** | **219** | **-** | **15.1943** | **0.6036** |
|
| 955 |
+
| 1.0046 | 220 | 1.4598 | - | - |
|
| 956 |
+
| 1.0959 | 240 | 1.6552 | - | - |
|
| 957 |
+
| 1.1872 | 260 | 1.5242 | - | - |
|
| 958 |
+
| 1.2785 | 280 | 1.5006 | - | - |
|
| 959 |
+
| 1.3699 | 300 | 1.4677 | - | - |
|
| 960 |
+
| 1.4612 | 320 | 1.6158 | - | - |
|
| 961 |
+
| 1.5525 | 340 | 1.6263 | - | - |
|
| 962 |
+
| 1.6438 | 360 | 1.6261 | - | - |
|
| 963 |
+
| 1.7352 | 380 | 1.7311 | - | - |
|
| 964 |
+
| 1.8265 | 400 | 1.5715 | - | - |
|
| 965 |
+
| 1.9178 | 420 | 1.4522 | - | - |
|
| 966 |
+
| 2.0 | 438 | - | 16.5972 | 0.5609 |
|
| 967 |
+
| 2.0091 | 440 | 1.3742 | - | - |
|
| 968 |
+
| 2.1005 | 460 | 1.7153 | - | - |
|
| 969 |
+
| 2.1918 | 480 | 1.5228 | - | - |
|
| 970 |
+
| 2.2831 | 500 | 1.4549 | - | - |
|
| 971 |
+
| 2.3744 | 520 | 1.6089 | - | - |
|
| 972 |
+
| 2.4658 | 540 | 1.6605 | - | - |
|
| 973 |
+
| 2.5571 | 560 | 1.3578 | - | - |
|
| 974 |
+
| 2.6484 | 580 | 1.6123 | - | - |
|
| 975 |
+
| 2.7397 | 600 | 1.4092 | - | - |
|
| 976 |
+
| 2.8311 | 620 | 1.4490 | - | - |
|
| 977 |
+
| 2.9224 | 640 | 1.4958 | - | - |
|
| 978 |
+
| 3.0 | 657 | - | 21.7325 | 0.5407 |
|
| 979 |
+
| 3.0137 | 660 | 1.3214 | - | - |
|
| 980 |
+
| 3.1050 | 680 | 1.4583 | - | - |
|
| 981 |
+
| 3.1963 | 700 | 1.4995 | - | - |
|
| 982 |
+
| 3.2877 | 720 | 1.4790 | - | - |
|
| 983 |
+
| 3.3790 | 740 | 1.3739 | - | - |
|
| 984 |
+
| 3.4703 | 760 | 1.3677 | - | - |
|
| 985 |
+
| 3.5616 | 780 | 1.4041 | - | - |
|
| 986 |
+
| 3.6530 | 800 | 1.3986 | - | - |
|
| 987 |
+
| 3.7443 | 820 | 1.3996 | - | - |
|
| 988 |
+
| 3.8356 | 840 | 1.4289 | - | - |
|
| 989 |
+
| 3.9269 | 860 | 1.5154 | - | - |
|
| 990 |
+
| 4.0 | 876 | - | 22.0813 | 0.5613 |
|
| 991 |
+
| 4.0183 | 880 | 1.3724 | - | - |
|
| 992 |
+
| 4.1096 | 900 | 1.5683 | - | - |
|
| 993 |
+
| 4.2009 | 920 | 1.3047 | - | - |
|
| 994 |
+
| 4.2922 | 940 | 1.3282 | - | - |
|
| 995 |
+
| 4.3836 | 960 | 1.3419 | - | - |
|
| 996 |
+
| 4.4749 | 980 | 1.3363 | - | - |
|
| 997 |
+
| 4.5662 | 1000 | 1.4189 | - | - |
|
| 998 |
+
| 4.6575 | 1020 | 1.4902 | - | - |
|
| 999 |
+
| 4.7489 | 1040 | 1.3306 | - | - |
|
| 1000 |
+
| 4.8402 | 1060 | 1.2475 | - | - |
|
| 1001 |
+
| 4.9315 | 1080 | 1.5482 | - | - |
|
| 1002 |
+
| 5.0 | 1095 | - | 23.6215 | 0.5360 |
|
| 1003 |
+
| -1 | -1 | - | - | 0.6036 |
|
| 1004 |
+
|
| 1005 |
+
* The bold row denotes the saved checkpoint.
|
| 1006 |
+
|
| 1007 |
+
### Framework Versions
|
| 1008 |
+
- Python: 3.12.12
|
| 1009 |
+
- Sentence Transformers: 5.3.0
|
| 1010 |
+
- Transformers: 5.2.0
|
| 1011 |
+
- PyTorch: 2.9.0+cu126
|
| 1012 |
+
- Accelerate: 1.12.0
|
| 1013 |
+
- Datasets: 4.7.0
|
| 1014 |
+
- Tokenizers: 0.22.2
|
| 1015 |
+
|
| 1016 |
+
## Citation
|
| 1017 |
+
|
| 1018 |
+
### BibTeX
|
| 1019 |
+
|
| 1020 |
+
#### Sentence Transformers
|
| 1021 |
+
```bibtex
|
| 1022 |
+
@inproceedings{reimers-2019-sentence-bert,
|
| 1023 |
+
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
|
| 1024 |
+
author = "Reimers, Nils and Gurevych, Iryna",
|
| 1025 |
+
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
|
| 1026 |
+
month = "11",
|
| 1027 |
+
year = "2019",
|
| 1028 |
+
publisher = "Association for Computational Linguistics",
|
| 1029 |
+
url = "https://arxiv.org/abs/1908.10084",
|
| 1030 |
+
}
|
| 1031 |
+
```
|
| 1032 |
+
|
| 1033 |
+
#### MatryoshkaLoss
|
| 1034 |
+
```bibtex
|
| 1035 |
+
@misc{kusupati2024matryoshka,
|
| 1036 |
+
title={Matryoshka Representation Learning},
|
| 1037 |
+
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
|
| 1038 |
+
year={2024},
|
| 1039 |
+
eprint={2205.13147},
|
| 1040 |
+
archivePrefix={arXiv},
|
| 1041 |
+
primaryClass={cs.LG}
|
| 1042 |
+
}
|
| 1043 |
+
```
|
| 1044 |
+
|
| 1045 |
+
#### CachedMultipleNegativesRankingLoss
|
| 1046 |
+
```bibtex
|
| 1047 |
+
@misc{gao2021scaling,
|
| 1048 |
+
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
|
| 1049 |
+
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
|
| 1050 |
+
year={2021},
|
| 1051 |
+
eprint={2101.06983},
|
| 1052 |
+
archivePrefix={arXiv},
|
| 1053 |
+
primaryClass={cs.LG}
|
| 1054 |
+
}
|
| 1055 |
+
```
|
| 1056 |
+
|
| 1057 |
+
<!--
|
| 1058 |
+
## Glossary
|
| 1059 |
+
|
| 1060 |
+
*Clearly define terms in order to be accessible across audiences.*
|
| 1061 |
+
-->
|
| 1062 |
+
|
| 1063 |
+
<!--
|
| 1064 |
+
## Model Card Authors
|
| 1065 |
+
|
| 1066 |
+
*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
|
| 1067 |
+
-->
|
| 1068 |
+
|
| 1069 |
+
<!--
|
| 1070 |
+
## Model Card Contact
|
| 1071 |
+
|
| 1072 |
+
*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
|
| 1073 |
+
-->
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"sentence_transformers": "5.3.0",
|
| 4 |
+
"transformers": "5.2.0",
|
| 5 |
+
"pytorch": "2.9.0+cu126"
|
| 6 |
+
},
|
| 7 |
+
"prompts": {
|
| 8 |
+
"query": "Query: ",
|
| 9 |
+
"document": "Document: "
|
| 10 |
+
},
|
| 11 |
+
"default_prompt_name": null,
|
| 12 |
+
"similarity_fn_name": "cosine",
|
| 13 |
+
"model_type": "SentenceTransformer"
|
| 14 |
+
}
|
configuration_eurobert.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/eurobert/modular_eurobert.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_eurobert.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# coding=utf-8
|
| 8 |
+
# Copyright 2025 Nicolas Boizard, Duarte M. Alves, Hippolyte Gisserot-Boukhlef and the EuroBert team. All rights reserved.
|
| 9 |
+
#
|
| 10 |
+
#
|
| 11 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 12 |
+
# you may not use this file except in compliance with the License.
|
| 13 |
+
# You may obtain a copy of the License at
|
| 14 |
+
#
|
| 15 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 16 |
+
#
|
| 17 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 18 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 19 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 20 |
+
# See the License for the specific language governing permissions and
|
| 21 |
+
# limitations under the License.
|
| 22 |
+
|
| 23 |
+
from transformers.utils import logging
|
| 24 |
+
from transformers.models.llama import LlamaConfig
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
logger = logging.get_logger(__name__)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class EuroBertConfig(LlamaConfig):
|
| 31 |
+
r"""
|
| 32 |
+
This is the configuration class to store the configuration of a [`EuroBertModel`]. It is used to instantiate an EuroBert
|
| 33 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 34 |
+
defaults will yield a similar configuration to that of the EuroBERT-210m.
|
| 35 |
+
|
| 36 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 37 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
vocab_size (`int`, *optional*, defaults to 128256):
|
| 42 |
+
Vocabulary size of the EuroBert model. Defines the number of different tokens that can be represented by the
|
| 43 |
+
`inputs_ids` passed when calling [`EuroBertModel`]
|
| 44 |
+
hidden_size (`int`, *optional*, defaults to 768):
|
| 45 |
+
Dimensionality of the encoder layers and the pooler layer.
|
| 46 |
+
intermediate_size (`int`, *optional*, defaults to 3072):
|
| 47 |
+
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
|
| 48 |
+
num_hidden_layers (`int`, *optional*, defaults to 12):
|
| 49 |
+
Number of hidden layers in the Transformer encoder.
|
| 50 |
+
num_attention_heads (`int`, *optional*, defaults to 12):
|
| 51 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 52 |
+
num_key_value_heads (`int`, *optional*):
|
| 53 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 54 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 55 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 56 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 57 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 58 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 59 |
+
`num_attention_heads`.
|
| 60 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 61 |
+
The non-linear activation function (function or string) in the encoder and pooler.
|
| 62 |
+
max_position_embeddings (`int`, *optional*, defaults to 8192):
|
| 63 |
+
The maximum sequence length that this model might ever be used with. EuroBert supports up to 8192 tokens,
|
| 64 |
+
EuroBert-pretrained up to 2048.
|
| 65 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 66 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 67 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 68 |
+
The epsilon used by the rms normalization layers.
|
| 69 |
+
bos_token_id (`int`, *optional*, defaults to 128000):
|
| 70 |
+
Beginning of stream token id.
|
| 71 |
+
eos_token_id (`int`, *optional*, defaults to 128001):
|
| 72 |
+
End of stream token id.
|
| 73 |
+
pad_token_id (`int`, *optional*, defaults to 128001):
|
| 74 |
+
Padding token id.
|
| 75 |
+
mask_token_id (`int`, *optional*, defaults to 128002):
|
| 76 |
+
Mask token id.
|
| 77 |
+
pretraining_tp (`int`, *optional*, defaults to 1):
|
| 78 |
+
Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
|
| 79 |
+
document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to
|
| 80 |
+
understand more about it. This value is necessary to ensure exact reproducibility of the pretraining
|
| 81 |
+
results. Please refer to [this issue](https://github.com/pytorch/pytorch/issues/76232).
|
| 82 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 83 |
+
Whether to tie weight embeddings
|
| 84 |
+
rope_theta (`float`, *optional*, defaults to 250000.0):
|
| 85 |
+
The base period of the RoPE embeddings. EuroBert used base period of 250000.0,
|
| 86 |
+
EuroBert-pretrained 10000.0.
|
| 87 |
+
rope_scaling (`Dict`, *optional*):
|
| 88 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
| 89 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
| 90 |
+
accordingly.
|
| 91 |
+
Expected contents:
|
| 92 |
+
`rope_type` (`str`):
|
| 93 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
| 94 |
+
'eurobert3'], with 'default' being the original RoPE implementation.
|
| 95 |
+
`factor` (`float`, *optional*):
|
| 96 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
| 97 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
| 98 |
+
original maximum pre-trained length.
|
| 99 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
| 100 |
+
Used with 'dynamic', 'longrope' and 'eurobert3'. The original max position embeddings used during
|
| 101 |
+
pretraining.
|
| 102 |
+
`attention_factor` (`float`, *optional*):
|
| 103 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
| 104 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
| 105 |
+
`factor` field to infer the suggested value.
|
| 106 |
+
`beta_fast` (`float`, *optional*):
|
| 107 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
| 108 |
+
ramp function. If unspecified, it defaults to 32.
|
| 109 |
+
`beta_slow` (`float`, *optional*):
|
| 110 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
| 111 |
+
ramp function. If unspecified, it defaults to 1.
|
| 112 |
+
`short_factor` (`List[float]`, *optional*):
|
| 113 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
| 114 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 115 |
+
size divided by the number of attention heads divided by 2
|
| 116 |
+
`long_factor` (`List[float]`, *optional*):
|
| 117 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
| 118 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 119 |
+
size divided by the number of attention heads divided by 2
|
| 120 |
+
`low_freq_factor` (`float`, *optional*):
|
| 121 |
+
Only used with 'eurobert3'. Scaling factor applied to low frequency components of the RoPE
|
| 122 |
+
`high_freq_factor` (`float`, *optional*):
|
| 123 |
+
Only used with 'eurobert3'. Scaling factor applied to high frequency components of the RoPE
|
| 124 |
+
attention_bias (`bool`, *optional*, defaults to `False`):
|
| 125 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 126 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 127 |
+
The dropout ratio for the attention probabilities.
|
| 128 |
+
mlp_bias (`bool`, *optional*, defaults to `False`):
|
| 129 |
+
Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
|
| 130 |
+
head_dim (`int`, *optional*):
|
| 131 |
+
The attention head dimension. If None, it will default to hidden_size // num_attention_heads
|
| 132 |
+
classifier_pooling (`str`, *optional*, defaults to `"late"`):
|
| 133 |
+
The pooling strategy to use for the classifier. Can be one of ['bos', 'mean', 'late'].
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
>>> from transformers import EuroBertModel, EuroBertConfig
|
| 137 |
+
|
| 138 |
+
>>> # Initializing a EuroBert eurobert-base style configuration
|
| 139 |
+
>>> configuration = EuroBertConfig()
|
| 140 |
+
|
| 141 |
+
>>> # Initializing a model from the eurobert-base style configuration
|
| 142 |
+
>>> model = EuroBertModel(configuration)
|
| 143 |
+
|
| 144 |
+
>>> # Accessing the model configuration
|
| 145 |
+
>>> configuration = model.config
|
| 146 |
+
```"""
|
| 147 |
+
|
| 148 |
+
model_type = "eurobert"
|
| 149 |
+
|
| 150 |
+
def __init__(
|
| 151 |
+
self,
|
| 152 |
+
vocab_size=128256,
|
| 153 |
+
hidden_size=768,
|
| 154 |
+
intermediate_size=3072,
|
| 155 |
+
num_hidden_layers=12,
|
| 156 |
+
num_attention_heads=12,
|
| 157 |
+
num_key_value_heads=None,
|
| 158 |
+
hidden_act="silu",
|
| 159 |
+
max_position_embeddings=8192,
|
| 160 |
+
initializer_range=0.02,
|
| 161 |
+
rms_norm_eps=1e-05,
|
| 162 |
+
bos_token_id=128000,
|
| 163 |
+
eos_token_id=128001,
|
| 164 |
+
pad_token_id=128001,
|
| 165 |
+
mask_token_id=128002,
|
| 166 |
+
pretraining_tp=1,
|
| 167 |
+
tie_word_embeddings=False,
|
| 168 |
+
rope_theta=250000.0,
|
| 169 |
+
rope_scaling=None,
|
| 170 |
+
attention_bias=False,
|
| 171 |
+
attention_dropout=0.0,
|
| 172 |
+
mlp_bias=False,
|
| 173 |
+
head_dim=None,
|
| 174 |
+
classifier_pooling="late",
|
| 175 |
+
**kwargs,
|
| 176 |
+
):
|
| 177 |
+
# use_cache is specific to decoder models and should be set to False for encoder models
|
| 178 |
+
use_cache = kwargs.pop("use_cache", None)
|
| 179 |
+
if use_cache:
|
| 180 |
+
logger.warning_once(
|
| 181 |
+
"The `use_cache` argument to EuroBertConfig is set to `False`, as caching is never used for encoder models."
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
if num_key_value_heads is None:
|
| 185 |
+
num_key_value_heads = num_attention_heads
|
| 186 |
+
|
| 187 |
+
super().__init__(
|
| 188 |
+
vocab_size=vocab_size,
|
| 189 |
+
hidden_size=hidden_size,
|
| 190 |
+
intermediate_size=intermediate_size,
|
| 191 |
+
num_hidden_layers=num_hidden_layers,
|
| 192 |
+
num_attention_heads=num_attention_heads,
|
| 193 |
+
num_key_value_heads=num_key_value_heads,
|
| 194 |
+
hidden_act=hidden_act,
|
| 195 |
+
max_position_embeddings=max_position_embeddings,
|
| 196 |
+
initializer_range=initializer_range,
|
| 197 |
+
rms_norm_eps=rms_norm_eps,
|
| 198 |
+
use_cache=False,
|
| 199 |
+
bos_token_id=bos_token_id,
|
| 200 |
+
eos_token_id=eos_token_id,
|
| 201 |
+
pad_token_id=pad_token_id,
|
| 202 |
+
pretraining_tp=pretraining_tp,
|
| 203 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 204 |
+
rope_theta=rope_theta,
|
| 205 |
+
rope_scaling=rope_scaling,
|
| 206 |
+
attention_bias=attention_bias,
|
| 207 |
+
attention_dropout=attention_dropout,
|
| 208 |
+
mlp_bias=mlp_bias,
|
| 209 |
+
head_dim=head_dim,
|
| 210 |
+
**kwargs,
|
| 211 |
+
)
|
| 212 |
+
self.mask_token_id = mask_token_id
|
| 213 |
+
self.clf_pooling = classifier_pooling
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
__all__ = ["EuroBertConfig"]
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 847075632
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8ad199ececcb2e55f6d6ce7b60c80ce7bd53faff582477853e3ef2c1da18e790
|
| 3 |
size 847075632
|
modeling_eurobert.py
ADDED
|
@@ -0,0 +1,1094 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/eurobert/modular_eurobert.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_eurobert.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# coding=utf-8
|
| 8 |
+
# Copyright 2025 Nicolas Boizard, Duarte M. Alves, Hippolyte Gisserot-Boukhlef and the EuroBert team. All rights reserved.
|
| 9 |
+
#
|
| 10 |
+
#
|
| 11 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 12 |
+
# you may not use this file except in compliance with the License.
|
| 13 |
+
# You may obtain a copy of the License at
|
| 14 |
+
#
|
| 15 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 16 |
+
#
|
| 17 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 18 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 19 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 20 |
+
# See the License for the specific language governing permissions and
|
| 21 |
+
# limitations under the License.
|
| 22 |
+
|
| 23 |
+
from typing import Callable, Optional, Tuple, Union
|
| 24 |
+
|
| 25 |
+
import torch
|
| 26 |
+
from torch import nn
|
| 27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
from transformers import initialization as init
|
| 31 |
+
except ImportError: # transformers < v5
|
| 32 |
+
from transformers import modeling_utils as _modeling_utils
|
| 33 |
+
init = getattr(_modeling_utils, "init", torch.nn.init)
|
| 34 |
+
|
| 35 |
+
from transformers.activations import ACT2FN
|
| 36 |
+
from transformers.cache_utils import Cache, StaticCache
|
| 37 |
+
from transformers.modeling_attn_mask_utils import AttentionMaskConverter
|
| 38 |
+
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
|
| 39 |
+
from transformers.modeling_outputs import (
|
| 40 |
+
BaseModelOutput,
|
| 41 |
+
BaseModelOutputWithPast,
|
| 42 |
+
MaskedLMOutput,
|
| 43 |
+
QuestionAnsweringModelOutput,
|
| 44 |
+
SequenceClassifierOutput,
|
| 45 |
+
TokenClassifierOutput,
|
| 46 |
+
)
|
| 47 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
|
| 48 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 49 |
+
from transformers.processing_utils import Unpack
|
| 50 |
+
from transformers.utils import (
|
| 51 |
+
add_code_sample_docstrings,
|
| 52 |
+
add_start_docstrings,
|
| 53 |
+
add_start_docstrings_to_model_forward,
|
| 54 |
+
logging,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
from .configuration_eurobert import EuroBertConfig
|
| 59 |
+
except ImportError:
|
| 60 |
+
from configuration_eurobert import EuroBertConfig
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
logger = logging.get_logger(__name__)
|
| 64 |
+
|
| 65 |
+
_CHECKPOINT_FOR_DOC = "EuroBERT/EuroBERT-210m"
|
| 66 |
+
_CONFIG_FOR_DOC = "EuroBertConfig"
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class EuroBertRMSNorm(nn.Module):
|
| 70 |
+
def __init__(self, hidden_size, eps=1e-5):
|
| 71 |
+
"""
|
| 72 |
+
EuroBertRMSNorm is equivalent to T5LayerNorm
|
| 73 |
+
"""
|
| 74 |
+
super().__init__()
|
| 75 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 76 |
+
self.variance_epsilon = eps
|
| 77 |
+
|
| 78 |
+
def forward(self, hidden_states):
|
| 79 |
+
input_dtype = hidden_states.dtype
|
| 80 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 81 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 82 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 83 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 84 |
+
|
| 85 |
+
def extra_repr(self):
|
| 86 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def rotate_half(x):
|
| 90 |
+
"""Rotates half the hidden dims of the input."""
|
| 91 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 92 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 93 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 97 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 98 |
+
|
| 99 |
+
Args:
|
| 100 |
+
q (`torch.Tensor`): The query tensor.
|
| 101 |
+
k (`torch.Tensor`): The key tensor.
|
| 102 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 103 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 104 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 105 |
+
Deprecated and unused.
|
| 106 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 107 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 108 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 109 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 110 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 111 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 112 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 113 |
+
Returns:
|
| 114 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 115 |
+
"""
|
| 116 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 117 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 118 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 119 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 120 |
+
return q_embed, k_embed
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 124 |
+
"""
|
| 125 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 126 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 127 |
+
"""
|
| 128 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 129 |
+
if n_rep == 1:
|
| 130 |
+
return hidden_states
|
| 131 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 132 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def eager_attention_forward(
|
| 136 |
+
module: nn.Module,
|
| 137 |
+
query: torch.Tensor,
|
| 138 |
+
key: torch.Tensor,
|
| 139 |
+
value: torch.Tensor,
|
| 140 |
+
attention_mask: Optional[torch.Tensor],
|
| 141 |
+
scaling: float,
|
| 142 |
+
dropout: float = 0.0,
|
| 143 |
+
**kwargs,
|
| 144 |
+
):
|
| 145 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 146 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 147 |
+
|
| 148 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 149 |
+
if attention_mask is not None:
|
| 150 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 151 |
+
attn_weights = attn_weights + causal_mask
|
| 152 |
+
|
| 153 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 154 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 155 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 156 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 157 |
+
|
| 158 |
+
return attn_output, attn_weights
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class EuroBertAttention(nn.Module):
|
| 162 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 163 |
+
|
| 164 |
+
def __init__(self, config: EuroBertConfig, layer_idx: int):
|
| 165 |
+
super().__init__()
|
| 166 |
+
self.config = config
|
| 167 |
+
self.layer_idx = layer_idx
|
| 168 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 169 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 170 |
+
self.scaling = self.head_dim**-0.5
|
| 171 |
+
self.attention_dropout = config.attention_dropout
|
| 172 |
+
self.is_causal = False
|
| 173 |
+
|
| 174 |
+
self.q_proj = nn.Linear(
|
| 175 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 176 |
+
)
|
| 177 |
+
self.k_proj = nn.Linear(
|
| 178 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 179 |
+
)
|
| 180 |
+
self.v_proj = nn.Linear(
|
| 181 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 182 |
+
)
|
| 183 |
+
self.o_proj = nn.Linear(
|
| 184 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
def forward(
|
| 188 |
+
self,
|
| 189 |
+
hidden_states: torch.Tensor,
|
| 190 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 191 |
+
attention_mask: Optional[torch.Tensor],
|
| 192 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 193 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 194 |
+
input_shape = hidden_states.shape[:-1]
|
| 195 |
+
|
| 196 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 197 |
+
|
| 198 |
+
query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 199 |
+
key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 200 |
+
value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 201 |
+
|
| 202 |
+
cos, sin = position_embeddings
|
| 203 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 204 |
+
|
| 205 |
+
attention_interface: Callable = eager_attention_forward
|
| 206 |
+
if self.config._attn_implementation != "eager":
|
| 207 |
+
if self.config._attn_implementation == "sdpa" and kwargs.get("output_attentions", False):
|
| 208 |
+
logger.warning_once(
|
| 209 |
+
"`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to "
|
| 210 |
+
'eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
| 211 |
+
)
|
| 212 |
+
else:
|
| 213 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 214 |
+
attn_output, attn_weights = attention_interface(
|
| 215 |
+
self,
|
| 216 |
+
query_states,
|
| 217 |
+
key_states,
|
| 218 |
+
value_states,
|
| 219 |
+
attention_mask,
|
| 220 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 221 |
+
scaling=self.scaling,
|
| 222 |
+
is_causal=False,
|
| 223 |
+
**kwargs,
|
| 224 |
+
)
|
| 225 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 226 |
+
attn_output = self.o_proj(attn_output)
|
| 227 |
+
return attn_output, attn_weights
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
EUROBERT_START_DOCSTRING = r"""
|
| 231 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 232 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 233 |
+
etc.)
|
| 234 |
+
|
| 235 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 236 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 237 |
+
and behavior.
|
| 238 |
+
|
| 239 |
+
Parameters:
|
| 240 |
+
config ([`EuroBertConfig`]):
|
| 241 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 242 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 243 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 244 |
+
"""
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@add_start_docstrings(
|
| 248 |
+
"The bare EuroBERT Model outputting raw hidden-states without any specific head on top.",
|
| 249 |
+
EUROBERT_START_DOCSTRING,
|
| 250 |
+
)
|
| 251 |
+
class EuroBertPreTrainedModel(PreTrainedModel):
|
| 252 |
+
config_class = EuroBertConfig
|
| 253 |
+
base_model_prefix = "model"
|
| 254 |
+
supports_gradient_checkpointing = True
|
| 255 |
+
_no_split_modules = ["EuroBertDecoderLayer"]
|
| 256 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 257 |
+
_supports_flash_attn_2 = True
|
| 258 |
+
_supports_sdpa = True
|
| 259 |
+
_supports_flex_attn = True
|
| 260 |
+
_supports_cache_class = True
|
| 261 |
+
_supports_quantized_cache = True
|
| 262 |
+
_supports_static_cache = True
|
| 263 |
+
_supports_attention_backend = True
|
| 264 |
+
|
| 265 |
+
def _init_weights(self, module):
|
| 266 |
+
std = self.config.initializer_range
|
| 267 |
+
if isinstance(module, nn.Linear):
|
| 268 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 269 |
+
if module.bias is not None:
|
| 270 |
+
init.zeros_(module.bias)
|
| 271 |
+
elif isinstance(module, nn.Embedding):
|
| 272 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 273 |
+
if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False):
|
| 274 |
+
init.zeros_(module.weight[module.padding_idx])
|
| 275 |
+
elif isinstance(module, EuroBertRotaryEmbedding):
|
| 276 |
+
rope_fn = ROPE_INIT_FUNCTIONS[module.rope_type]
|
| 277 |
+
buffer_value, _ = rope_fn(module.config, device=module.inv_freq.device)
|
| 278 |
+
if hasattr(init, "copy_"):
|
| 279 |
+
init.copy_(module.inv_freq, buffer_value)
|
| 280 |
+
init.copy_(module.original_inv_freq, buffer_value)
|
| 281 |
+
else:
|
| 282 |
+
module.inv_freq.copy_(buffer_value)
|
| 283 |
+
module.original_inv_freq.copy_(buffer_value)
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
class EuroBertRotaryEmbedding(nn.Module):
|
| 287 |
+
def __init__(self, config: EuroBertConfig, device=None):
|
| 288 |
+
super().__init__()
|
| 289 |
+
# BC: "rope_type" was originally "type"
|
| 290 |
+
if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
|
| 291 |
+
self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
|
| 292 |
+
else:
|
| 293 |
+
self.rope_type = "default"
|
| 294 |
+
if self.rope_type == "default":
|
| 295 |
+
self.rope_type = "linear"
|
| 296 |
+
# Ensure rope_scaling is set up with factor=1.0 for linear (no scaling, equivalent to default)
|
| 297 |
+
if not hasattr(config, "rope_scaling") or config.rope_scaling is None:
|
| 298 |
+
config.rope_scaling = {"rope_type": "linear", "factor": 1.0}
|
| 299 |
+
elif "factor" not in config.rope_scaling:
|
| 300 |
+
config.rope_scaling["factor"] = 1.0
|
| 301 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 302 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 303 |
+
|
| 304 |
+
self.config = config
|
| 305 |
+
self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 306 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
|
| 307 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 308 |
+
self.original_inv_freq = self.inv_freq
|
| 309 |
+
|
| 310 |
+
def _dynamic_frequency_update(self, position_ids, device):
|
| 311 |
+
"""
|
| 312 |
+
dynamic RoPE layers should recompute `inv_freq` in the following situations:
|
| 313 |
+
1 - growing beyond the cached sequence length (allow scaling)
|
| 314 |
+
2 - the current sequence length is in the original scale (avoid losing precision with small sequences)
|
| 315 |
+
"""
|
| 316 |
+
seq_len = torch.max(position_ids) + 1
|
| 317 |
+
if seq_len > self.max_seq_len_cached: # growth
|
| 318 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device, seq_len=seq_len)
|
| 319 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False) # TODO joao: may break with compilation
|
| 320 |
+
self.max_seq_len_cached = seq_len
|
| 321 |
+
|
| 322 |
+
if seq_len < self.original_max_seq_len and self.max_seq_len_cached > self.original_max_seq_len: # reset
|
| 323 |
+
# This .to() is needed if the model has been moved to a device after being initialized (because
|
| 324 |
+
# the buffer is automatically moved, but not the original copy)
|
| 325 |
+
self.original_inv_freq = self.original_inv_freq.to(device)
|
| 326 |
+
self.register_buffer("inv_freq", self.original_inv_freq, persistent=False)
|
| 327 |
+
self.max_seq_len_cached = self.original_max_seq_len
|
| 328 |
+
|
| 329 |
+
@torch.no_grad()
|
| 330 |
+
def forward(self, x, position_ids):
|
| 331 |
+
if "dynamic" in self.rope_type:
|
| 332 |
+
self._dynamic_frequency_update(position_ids, device=x.device)
|
| 333 |
+
|
| 334 |
+
# Core RoPE block
|
| 335 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 336 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 337 |
+
# Force float32 (see https://github.com/huggingface/transformers/pull/29285)
|
| 338 |
+
device_type = x.device.type
|
| 339 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 340 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 341 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 342 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 343 |
+
cos = emb.cos()
|
| 344 |
+
sin = emb.sin()
|
| 345 |
+
|
| 346 |
+
# Advanced RoPE types (e.g. yarn) apply a post-processing scaling factor, equivalent to scaling attention
|
| 347 |
+
cos = cos * self.attention_scaling
|
| 348 |
+
sin = sin * self.attention_scaling
|
| 349 |
+
|
| 350 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
class EuroBertMLP(nn.Module):
|
| 354 |
+
def __init__(self, config):
|
| 355 |
+
super().__init__()
|
| 356 |
+
self.config = config
|
| 357 |
+
self.hidden_size = config.hidden_size
|
| 358 |
+
self.intermediate_size = config.intermediate_size
|
| 359 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
|
| 360 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
|
| 361 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.mlp_bias)
|
| 362 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 363 |
+
|
| 364 |
+
def forward(self, x):
|
| 365 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 366 |
+
return down_proj
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
class EuroBertDecoderLayer(nn.Module):
|
| 370 |
+
def __init__(self, config: EuroBertConfig, layer_idx: int):
|
| 371 |
+
super().__init__()
|
| 372 |
+
self.hidden_size = config.hidden_size
|
| 373 |
+
|
| 374 |
+
self.self_attn = EuroBertAttention(config=config, layer_idx=layer_idx)
|
| 375 |
+
|
| 376 |
+
self.mlp = EuroBertMLP(config)
|
| 377 |
+
self.input_layernorm = EuroBertRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 378 |
+
self.post_attention_layernorm = EuroBertRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 379 |
+
|
| 380 |
+
def forward(
|
| 381 |
+
self,
|
| 382 |
+
hidden_states: torch.Tensor,
|
| 383 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 384 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 385 |
+
past_key_value: Optional[Cache] = None,
|
| 386 |
+
output_attentions: Optional[bool] = False,
|
| 387 |
+
use_cache: Optional[bool] = False,
|
| 388 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 389 |
+
position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
|
| 390 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 391 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 392 |
+
residual = hidden_states
|
| 393 |
+
|
| 394 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 395 |
+
|
| 396 |
+
# Self Attention
|
| 397 |
+
hidden_states, self_attn_weights = self.self_attn(
|
| 398 |
+
hidden_states=hidden_states,
|
| 399 |
+
attention_mask=attention_mask,
|
| 400 |
+
position_ids=position_ids,
|
| 401 |
+
past_key_value=past_key_value,
|
| 402 |
+
output_attentions=output_attentions,
|
| 403 |
+
use_cache=use_cache,
|
| 404 |
+
cache_position=cache_position,
|
| 405 |
+
position_embeddings=position_embeddings,
|
| 406 |
+
**kwargs,
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
hidden_states = residual + hidden_states
|
| 410 |
+
|
| 411 |
+
# Fully Connected
|
| 412 |
+
residual = hidden_states
|
| 413 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 414 |
+
hidden_states = self.mlp(hidden_states)
|
| 415 |
+
hidden_states = residual + hidden_states
|
| 416 |
+
|
| 417 |
+
outputs = (hidden_states,)
|
| 418 |
+
if output_attentions:
|
| 419 |
+
outputs += (self_attn_weights,)
|
| 420 |
+
|
| 421 |
+
return outputs
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
EUROBERT_INPUTS_DOCSTRING = r"""
|
| 425 |
+
Args:
|
| 426 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 427 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 428 |
+
it.
|
| 429 |
+
|
| 430 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 431 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 432 |
+
|
| 433 |
+
[What are input IDs?](../glossary#input-ids)
|
| 434 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 435 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 436 |
+
|
| 437 |
+
- 1 for tokens that are **not masked**,
|
| 438 |
+
- 0 for tokens that are **masked**.
|
| 439 |
+
|
| 440 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 441 |
+
|
| 442 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 443 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 444 |
+
|
| 445 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
| 446 |
+
`past_key_values`).
|
| 447 |
+
|
| 448 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 449 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 450 |
+
information on the default strategy.
|
| 451 |
+
|
| 452 |
+
- 1 indicates the head is **not masked**,
|
| 453 |
+
- 0 indicates the head is **masked**.
|
| 454 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 455 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 456 |
+
config.n_positions - 1]`.
|
| 457 |
+
|
| 458 |
+
[What are position IDs?](../glossary#position-ids)
|
| 459 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 460 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 461 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 462 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 463 |
+
|
| 464 |
+
Two formats are allowed:
|
| 465 |
+
- a [`~cache_utils.Cache`] instance, see our
|
| 466 |
+
[kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
|
| 467 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 468 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 469 |
+
cache format.
|
| 470 |
+
|
| 471 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 472 |
+
legacy cache format will be returned.
|
| 473 |
+
|
| 474 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 475 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 476 |
+
of shape `(batch_size, sequence_length)`.
|
| 477 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 478 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 479 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 480 |
+
model's internal embedding lookup matrix.
|
| 481 |
+
use_cache (`bool`, *optional*):
|
| 482 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 483 |
+
`past_key_values`).
|
| 484 |
+
output_attentions (`bool`, *optional*):
|
| 485 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 486 |
+
tensors for more detail.
|
| 487 |
+
output_hidden_states (`bool`, *optional*):
|
| 488 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 489 |
+
more detail.
|
| 490 |
+
return_dict (`bool`, *optional*):
|
| 491 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 492 |
+
cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
|
| 493 |
+
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
|
| 494 |
+
this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
|
| 495 |
+
the complete sequence length.
|
| 496 |
+
"""
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
@add_start_docstrings(
|
| 500 |
+
"The bare EuroBert Model outputting raw hidden-states without any specific head on top.",
|
| 501 |
+
EUROBERT_START_DOCSTRING,
|
| 502 |
+
)
|
| 503 |
+
class EuroBertModel(EuroBertPreTrainedModel):
|
| 504 |
+
"""
|
| 505 |
+
Transformer encoder consisting of *config.num_hidden_layers* layers. Each layer is a [`EuroBertDecoderLayer`]
|
| 506 |
+
|
| 507 |
+
Args:
|
| 508 |
+
config: EuroBertConfig
|
| 509 |
+
"""
|
| 510 |
+
|
| 511 |
+
def __init__(self, config: EuroBertConfig):
|
| 512 |
+
super().__init__(config)
|
| 513 |
+
self.padding_idx = config.pad_token_id
|
| 514 |
+
self.vocab_size = config.vocab_size
|
| 515 |
+
|
| 516 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 517 |
+
self.layers = nn.ModuleList(
|
| 518 |
+
[EuroBertDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 519 |
+
)
|
| 520 |
+
self.norm = EuroBertRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 521 |
+
self.rotary_emb = EuroBertRotaryEmbedding(config=config)
|
| 522 |
+
self.gradient_checkpointing = False
|
| 523 |
+
self.mask_converter = AttentionMaskConverter(is_causal=False)
|
| 524 |
+
|
| 525 |
+
# Initialize weights and apply final processing
|
| 526 |
+
self.post_init()
|
| 527 |
+
|
| 528 |
+
def get_input_embeddings(self):
|
| 529 |
+
return self.embed_tokens
|
| 530 |
+
|
| 531 |
+
def set_input_embeddings(self, value):
|
| 532 |
+
self.embed_tokens = value
|
| 533 |
+
|
| 534 |
+
@add_start_docstrings_to_model_forward(EUROBERT_INPUTS_DOCSTRING)
|
| 535 |
+
@add_code_sample_docstrings(
|
| 536 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 537 |
+
output_type=BaseModelOutput,
|
| 538 |
+
config_class=_CONFIG_FOR_DOC,
|
| 539 |
+
)
|
| 540 |
+
def forward(
|
| 541 |
+
self,
|
| 542 |
+
input_ids: torch.LongTensor = None,
|
| 543 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 544 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 545 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 546 |
+
output_attentions: Optional[bool] = None,
|
| 547 |
+
output_hidden_states: Optional[bool] = None,
|
| 548 |
+
return_dict: Optional[bool] = None,
|
| 549 |
+
**flash_attn_kwargs: Unpack[FlashAttentionKwargs],
|
| 550 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 551 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 552 |
+
output_hidden_states = (
|
| 553 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 554 |
+
)
|
| 555 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 556 |
+
|
| 557 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 558 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 559 |
+
|
| 560 |
+
if inputs_embeds is None:
|
| 561 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 562 |
+
|
| 563 |
+
if attention_mask is not None and self.config._attn_implementation != "flash_attention_2":
|
| 564 |
+
mask = self.mask_converter.to_4d(attention_mask, attention_mask.shape[1], inputs_embeds.dtype)
|
| 565 |
+
else:
|
| 566 |
+
mask = attention_mask
|
| 567 |
+
|
| 568 |
+
hidden_states = inputs_embeds
|
| 569 |
+
|
| 570 |
+
# create position embeddings to be shared across the encoder layers
|
| 571 |
+
if position_ids is None:
|
| 572 |
+
position_ids = torch.arange(inputs_embeds.shape[1], device=inputs_embeds.device).unsqueeze(0)
|
| 573 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 574 |
+
|
| 575 |
+
# encoder layers
|
| 576 |
+
all_hidden_states = () if output_hidden_states else None
|
| 577 |
+
all_self_attns = () if output_attentions else None
|
| 578 |
+
|
| 579 |
+
for encoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 580 |
+
if output_hidden_states:
|
| 581 |
+
all_hidden_states += (hidden_states,)
|
| 582 |
+
|
| 583 |
+
if self.gradient_checkpointing and self.training:
|
| 584 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 585 |
+
encoder_layer.__call__,
|
| 586 |
+
hidden_states,
|
| 587 |
+
mask,
|
| 588 |
+
position_ids,
|
| 589 |
+
None,
|
| 590 |
+
output_attentions,
|
| 591 |
+
False,
|
| 592 |
+
None,
|
| 593 |
+
position_embeddings,
|
| 594 |
+
)
|
| 595 |
+
else:
|
| 596 |
+
layer_outputs = encoder_layer(
|
| 597 |
+
hidden_states,
|
| 598 |
+
attention_mask=mask,
|
| 599 |
+
position_ids=position_ids,
|
| 600 |
+
output_attentions=output_attentions,
|
| 601 |
+
position_embeddings=position_embeddings,
|
| 602 |
+
**flash_attn_kwargs,
|
| 603 |
+
)
|
| 604 |
+
|
| 605 |
+
hidden_states = layer_outputs[0]
|
| 606 |
+
|
| 607 |
+
if output_attentions:
|
| 608 |
+
all_self_attns += (layer_outputs[1],)
|
| 609 |
+
|
| 610 |
+
hidden_states = self.norm(hidden_states)
|
| 611 |
+
|
| 612 |
+
# add hidden states from the last encoder layer
|
| 613 |
+
if output_hidden_states:
|
| 614 |
+
all_hidden_states += (hidden_states,)
|
| 615 |
+
|
| 616 |
+
output = BaseModelOutput(
|
| 617 |
+
last_hidden_state=hidden_states,
|
| 618 |
+
hidden_states=all_hidden_states,
|
| 619 |
+
attentions=all_self_attns,
|
| 620 |
+
)
|
| 621 |
+
return output if return_dict else output.to_tuple()
|
| 622 |
+
|
| 623 |
+
def _update_causal_mask(
|
| 624 |
+
self,
|
| 625 |
+
attention_mask: torch.Tensor,
|
| 626 |
+
input_tensor: torch.Tensor,
|
| 627 |
+
cache_position: torch.Tensor,
|
| 628 |
+
past_key_values: Cache,
|
| 629 |
+
output_attentions: bool,
|
| 630 |
+
):
|
| 631 |
+
if self.config._attn_implementation == "flash_attention_2":
|
| 632 |
+
if attention_mask is not None and (attention_mask == 0.0).any():
|
| 633 |
+
return attention_mask
|
| 634 |
+
return None
|
| 635 |
+
|
| 636 |
+
# For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
|
| 637 |
+
# order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
|
| 638 |
+
# to infer the attention mask.
|
| 639 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 640 |
+
using_static_cache = isinstance(past_key_values, StaticCache)
|
| 641 |
+
|
| 642 |
+
# When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
|
| 643 |
+
if self.config._attn_implementation == "sdpa" and not using_static_cache and not output_attentions:
|
| 644 |
+
if AttentionMaskConverter._ignore_causal_mask_sdpa(
|
| 645 |
+
attention_mask,
|
| 646 |
+
inputs_embeds=input_tensor,
|
| 647 |
+
past_key_values_length=past_seen_tokens,
|
| 648 |
+
is_training=self.training,
|
| 649 |
+
):
|
| 650 |
+
return None
|
| 651 |
+
|
| 652 |
+
dtype, device = input_tensor.dtype, input_tensor.device
|
| 653 |
+
sequence_length = input_tensor.shape[1]
|
| 654 |
+
if using_static_cache:
|
| 655 |
+
target_length = past_key_values.get_max_cache_shape()
|
| 656 |
+
else:
|
| 657 |
+
target_length = (
|
| 658 |
+
attention_mask.shape[-1]
|
| 659 |
+
if isinstance(attention_mask, torch.Tensor)
|
| 660 |
+
else past_seen_tokens + sequence_length + 1
|
| 661 |
+
)
|
| 662 |
+
|
| 663 |
+
# In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
|
| 664 |
+
causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
|
| 665 |
+
attention_mask,
|
| 666 |
+
sequence_length=sequence_length,
|
| 667 |
+
target_length=target_length,
|
| 668 |
+
dtype=dtype,
|
| 669 |
+
device=device,
|
| 670 |
+
cache_position=cache_position,
|
| 671 |
+
batch_size=input_tensor.shape[0],
|
| 672 |
+
)
|
| 673 |
+
|
| 674 |
+
if (
|
| 675 |
+
self.config._attn_implementation == "sdpa"
|
| 676 |
+
and attention_mask is not None
|
| 677 |
+
and attention_mask.device.type in ["cuda", "xpu"]
|
| 678 |
+
and not output_attentions
|
| 679 |
+
):
|
| 680 |
+
# Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
|
| 681 |
+
# using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
|
| 682 |
+
# Details: https://github.com/pytorch/pytorch/issues/110213
|
| 683 |
+
min_dtype = torch.finfo(dtype).min
|
| 684 |
+
causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
|
| 685 |
+
|
| 686 |
+
return causal_mask
|
| 687 |
+
|
| 688 |
+
@staticmethod
|
| 689 |
+
def _prepare_4d_causal_attention_mask_with_cache_position(
|
| 690 |
+
attention_mask: torch.Tensor,
|
| 691 |
+
sequence_length: int,
|
| 692 |
+
target_length: int,
|
| 693 |
+
dtype: torch.dtype,
|
| 694 |
+
device: torch.device,
|
| 695 |
+
cache_position: torch.Tensor,
|
| 696 |
+
batch_size: int,
|
| 697 |
+
**kwargs,
|
| 698 |
+
):
|
| 699 |
+
"""
|
| 700 |
+
Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
|
| 701 |
+
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
|
| 702 |
+
|
| 703 |
+
Args:
|
| 704 |
+
attention_mask (`torch.Tensor`):
|
| 705 |
+
A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
|
| 706 |
+
`(batch_size, 1, query_length, key_value_length)`.
|
| 707 |
+
sequence_length (`int`):
|
| 708 |
+
The sequence length being processed.
|
| 709 |
+
target_length (`int`):
|
| 710 |
+
The target length: when generating with static cache, the mask should be as long as the static cache,
|
| 711 |
+
to account for the 0 padding, the part of the cache that is not filled yet.
|
| 712 |
+
dtype (`torch.dtype`):
|
| 713 |
+
The dtype to use for the 4D attention mask.
|
| 714 |
+
device (`torch.device`):
|
| 715 |
+
The device to plcae the 4D attention mask on.
|
| 716 |
+
cache_position (`torch.Tensor`):
|
| 717 |
+
Indices depicting the position of the input sequence tokens in the sequence.
|
| 718 |
+
batch_size (`torch.Tensor`):
|
| 719 |
+
Batch size.
|
| 720 |
+
"""
|
| 721 |
+
if attention_mask is not None and attention_mask.dim() == 4:
|
| 722 |
+
# In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
|
| 723 |
+
causal_mask = attention_mask
|
| 724 |
+
else:
|
| 725 |
+
min_dtype = torch.finfo(dtype).min
|
| 726 |
+
causal_mask = torch.full(
|
| 727 |
+
(sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
|
| 728 |
+
)
|
| 729 |
+
if sequence_length != 1:
|
| 730 |
+
causal_mask = torch.triu(causal_mask, diagonal=1)
|
| 731 |
+
causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
|
| 732 |
+
causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
|
| 733 |
+
if attention_mask is not None:
|
| 734 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
| 735 |
+
mask_length = attention_mask.shape[-1]
|
| 736 |
+
padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
|
| 737 |
+
causal_mask.device
|
| 738 |
+
)
|
| 739 |
+
padding_mask = padding_mask == 0
|
| 740 |
+
causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
|
| 741 |
+
padding_mask, min_dtype
|
| 742 |
+
)
|
| 743 |
+
|
| 744 |
+
return causal_mask
|
| 745 |
+
|
| 746 |
+
|
| 747 |
+
@add_start_docstrings(
|
| 748 |
+
"The EuroBert Model with a decoder head on top that is used for masked language modeling.",
|
| 749 |
+
EUROBERT_START_DOCSTRING,
|
| 750 |
+
)
|
| 751 |
+
class EuroBertForMaskedLM(EuroBertPreTrainedModel):
|
| 752 |
+
def __init__(self, config: EuroBertConfig):
|
| 753 |
+
super().__init__(config)
|
| 754 |
+
self.model = EuroBertModel(config)
|
| 755 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, config.mlp_bias)
|
| 756 |
+
self.post_init()
|
| 757 |
+
|
| 758 |
+
@add_start_docstrings_to_model_forward(EUROBERT_INPUTS_DOCSTRING)
|
| 759 |
+
@add_code_sample_docstrings(
|
| 760 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 761 |
+
output_type=BaseModelOutput,
|
| 762 |
+
config_class=_CONFIG_FOR_DOC,
|
| 763 |
+
)
|
| 764 |
+
def forward(
|
| 765 |
+
self,
|
| 766 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 767 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 768 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 769 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 770 |
+
labels: Optional[torch.LongTensor] = None,
|
| 771 |
+
output_attentions: Optional[bool] = None,
|
| 772 |
+
output_hidden_states: Optional[bool] = None,
|
| 773 |
+
return_dict: Optional[bool] = None,
|
| 774 |
+
) -> Union[Tuple[torch.Tensor], MaskedLMOutput]:
|
| 775 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 776 |
+
|
| 777 |
+
encoder_output = self.model(
|
| 778 |
+
input_ids,
|
| 779 |
+
attention_mask=attention_mask,
|
| 780 |
+
position_ids=position_ids,
|
| 781 |
+
inputs_embeds=inputs_embeds,
|
| 782 |
+
output_attentions=output_attentions,
|
| 783 |
+
output_hidden_states=output_hidden_states,
|
| 784 |
+
return_dict=return_dict,
|
| 785 |
+
)
|
| 786 |
+
|
| 787 |
+
prediction_scores = self.lm_head(encoder_output[0])
|
| 788 |
+
masked_lm_loss = None
|
| 789 |
+
if labels is not None:
|
| 790 |
+
labels = labels.to(prediction_scores.device)
|
| 791 |
+
masked_lm_loss = self.loss_function(prediction_scores, labels, vocab_size=self.config.vocab_size)
|
| 792 |
+
|
| 793 |
+
if not return_dict:
|
| 794 |
+
output = (prediction_scores,) + encoder_output[1:]
|
| 795 |
+
return ((masked_lm_loss,) + output) if masked_lm_loss is not None else output
|
| 796 |
+
|
| 797 |
+
return MaskedLMOutput(
|
| 798 |
+
loss=masked_lm_loss,
|
| 799 |
+
logits=prediction_scores,
|
| 800 |
+
hidden_states=encoder_output.hidden_states,
|
| 801 |
+
attentions=encoder_output.attentions,
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
@add_start_docstrings(
|
| 806 |
+
"The EuroBert Model with a sequence classification head on top that performs pooling.",
|
| 807 |
+
EUROBERT_START_DOCSTRING,
|
| 808 |
+
)
|
| 809 |
+
class EuroBertForSequenceClassification(EuroBertPreTrainedModel):
|
| 810 |
+
def __init__(self, config: EuroBertConfig):
|
| 811 |
+
super().__init__(config)
|
| 812 |
+
self.num_labels = config.num_labels
|
| 813 |
+
self.clf_pooling = config.clf_pooling
|
| 814 |
+
|
| 815 |
+
self.model = EuroBertModel(config)
|
| 816 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
| 817 |
+
self.activation = nn.GELU()
|
| 818 |
+
self.classifier = nn.Linear(config.hidden_size, self.num_labels)
|
| 819 |
+
self.post_init()
|
| 820 |
+
|
| 821 |
+
@add_start_docstrings_to_model_forward(EUROBERT_INPUTS_DOCSTRING)
|
| 822 |
+
@add_code_sample_docstrings(
|
| 823 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 824 |
+
output_type=BaseModelOutput,
|
| 825 |
+
config_class=_CONFIG_FOR_DOC,
|
| 826 |
+
)
|
| 827 |
+
def forward(
|
| 828 |
+
self,
|
| 829 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 830 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 831 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 832 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 833 |
+
labels: Optional[torch.LongTensor] = None,
|
| 834 |
+
output_attentions: Optional[bool] = None,
|
| 835 |
+
output_hidden_states: Optional[bool] = None,
|
| 836 |
+
return_dict: Optional[bool] = None,
|
| 837 |
+
) -> Union[Tuple[torch.Tensor], SequenceClassifierOutput]:
|
| 838 |
+
r"""
|
| 839 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 840 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 841 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 842 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 843 |
+
"""
|
| 844 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 845 |
+
|
| 846 |
+
encoder_output = self.model(
|
| 847 |
+
input_ids,
|
| 848 |
+
attention_mask=attention_mask,
|
| 849 |
+
position_ids=position_ids,
|
| 850 |
+
inputs_embeds=inputs_embeds,
|
| 851 |
+
output_attentions=output_attentions,
|
| 852 |
+
output_hidden_states=output_hidden_states,
|
| 853 |
+
return_dict=return_dict,
|
| 854 |
+
)
|
| 855 |
+
last_hidden_state = encoder_output[0]
|
| 856 |
+
|
| 857 |
+
if self.clf_pooling in ["bos", "mean"]:
|
| 858 |
+
if self.clf_pooling == "bos":
|
| 859 |
+
pooled_output = last_hidden_state[:, 0]
|
| 860 |
+
|
| 861 |
+
elif self.clf_pooling == "mean":
|
| 862 |
+
if attention_mask is None:
|
| 863 |
+
pooled_output = last_hidden_state.mean(dim=1)
|
| 864 |
+
else:
|
| 865 |
+
pooled_output = (last_hidden_state * attention_mask.unsqueeze(-1)).sum(dim=1)
|
| 866 |
+
pooled_output /= attention_mask.sum(dim=1, keepdim=True)
|
| 867 |
+
|
| 868 |
+
pooled_output = self.dense(pooled_output)
|
| 869 |
+
pooled_output = self.activation(pooled_output)
|
| 870 |
+
logits = self.classifier(pooled_output)
|
| 871 |
+
|
| 872 |
+
elif self.clf_pooling == "late":
|
| 873 |
+
x = self.dense(last_hidden_state)
|
| 874 |
+
x = self.activation(x)
|
| 875 |
+
logits = self.classifier(x)
|
| 876 |
+
if attention_mask is None:
|
| 877 |
+
logits = logits.mean(dim=1)
|
| 878 |
+
else:
|
| 879 |
+
logits = (logits * attention_mask.unsqueeze(-1)).sum(dim=1)
|
| 880 |
+
logits /= attention_mask.sum(dim=1, keepdim=True)
|
| 881 |
+
|
| 882 |
+
loss = None
|
| 883 |
+
if labels is not None:
|
| 884 |
+
labels = labels.to(logits.device)
|
| 885 |
+
if self.config.problem_type is None:
|
| 886 |
+
if self.num_labels == 1:
|
| 887 |
+
self.config.problem_type = "regression"
|
| 888 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 889 |
+
self.config.problem_type = "single_label_classification"
|
| 890 |
+
else:
|
| 891 |
+
self.config.problem_type = "multi_label_classification"
|
| 892 |
+
|
| 893 |
+
if self.config.problem_type == "regression":
|
| 894 |
+
loss_fct = MSELoss()
|
| 895 |
+
if self.num_labels == 1:
|
| 896 |
+
loss = loss_fct(logits.squeeze(), labels.squeeze())
|
| 897 |
+
else:
|
| 898 |
+
loss = loss_fct(logits, labels)
|
| 899 |
+
elif self.config.problem_type == "single_label_classification":
|
| 900 |
+
loss_fct = CrossEntropyLoss()
|
| 901 |
+
loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
|
| 902 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 903 |
+
loss_fct = BCEWithLogitsLoss()
|
| 904 |
+
loss = loss_fct(logits, labels)
|
| 905 |
+
|
| 906 |
+
if not return_dict:
|
| 907 |
+
output = (logits,) + encoder_output[1:]
|
| 908 |
+
return ((loss,) + output) if loss is not None else output
|
| 909 |
+
|
| 910 |
+
return SequenceClassifierOutput(
|
| 911 |
+
loss=loss,
|
| 912 |
+
logits=logits,
|
| 913 |
+
hidden_states=encoder_output.hidden_states,
|
| 914 |
+
attentions=encoder_output.attentions,
|
| 915 |
+
)
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
@add_start_docstrings(
|
| 919 |
+
"""
|
| 920 |
+
The EuroBert Model with a token classification head on top (a linear layer on top of the hidden-states
|
| 921 |
+
output) e.g. for Named-Entity-Recognition (NER) tasks."
|
| 922 |
+
""",
|
| 923 |
+
EUROBERT_START_DOCSTRING,
|
| 924 |
+
)
|
| 925 |
+
class EuroBertForTokenClassification(EuroBertPreTrainedModel):
|
| 926 |
+
def __init__(self, config: EuroBertConfig):
|
| 927 |
+
super().__init__(config)
|
| 928 |
+
self.num_labels = config.num_labels
|
| 929 |
+
self.model = EuroBertModel(config)
|
| 930 |
+
|
| 931 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
| 932 |
+
self.post_init()
|
| 933 |
+
|
| 934 |
+
def get_input_embeddings(self):
|
| 935 |
+
return self.model.embed_tokens
|
| 936 |
+
|
| 937 |
+
def set_input_embeddings(self, value):
|
| 938 |
+
self.model.embed_tokens = value
|
| 939 |
+
|
| 940 |
+
@add_start_docstrings_to_model_forward(EUROBERT_INPUTS_DOCSTRING)
|
| 941 |
+
def forward(
|
| 942 |
+
self,
|
| 943 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 944 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 945 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 946 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 947 |
+
labels: Optional[torch.LongTensor] = None,
|
| 948 |
+
use_cache: Optional[bool] = None,
|
| 949 |
+
output_attentions: Optional[bool] = None,
|
| 950 |
+
output_hidden_states: Optional[bool] = None,
|
| 951 |
+
return_dict: Optional[bool] = None,
|
| 952 |
+
) -> Union[Tuple, TokenClassifierOutput]:
|
| 953 |
+
r"""
|
| 954 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 955 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 956 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 957 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 958 |
+
"""
|
| 959 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 960 |
+
|
| 961 |
+
outputs = self.model(
|
| 962 |
+
input_ids,
|
| 963 |
+
attention_mask=attention_mask,
|
| 964 |
+
position_ids=position_ids,
|
| 965 |
+
inputs_embeds=inputs_embeds,
|
| 966 |
+
use_cache=use_cache,
|
| 967 |
+
output_attentions=output_attentions,
|
| 968 |
+
output_hidden_states=output_hidden_states,
|
| 969 |
+
return_dict=return_dict,
|
| 970 |
+
)
|
| 971 |
+
sequence_output = outputs[0]
|
| 972 |
+
logits = self.classifier(sequence_output)
|
| 973 |
+
|
| 974 |
+
loss = None
|
| 975 |
+
if labels is not None:
|
| 976 |
+
loss_fct = CrossEntropyLoss()
|
| 977 |
+
loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
|
| 978 |
+
|
| 979 |
+
if not return_dict:
|
| 980 |
+
output = (logits,) + outputs[2:]
|
| 981 |
+
return ((loss,) + output) if loss is not None else output
|
| 982 |
+
|
| 983 |
+
return TokenClassifierOutput(
|
| 984 |
+
loss=loss,
|
| 985 |
+
logits=logits,
|
| 986 |
+
hidden_states=outputs.hidden_states,
|
| 987 |
+
attentions=outputs.attentions,
|
| 988 |
+
)
|
| 989 |
+
|
| 990 |
+
|
| 991 |
+
@add_start_docstrings(
|
| 992 |
+
"""
|
| 993 |
+
The EuroBert Model with a span classification head on top for extractive question-answering tasks
|
| 994 |
+
like SQuAD (a linear layers on top of the hidden-states output to compute span start logits
|
| 995 |
+
and span end logits).
|
| 996 |
+
""",
|
| 997 |
+
EUROBERT_START_DOCSTRING,
|
| 998 |
+
)
|
| 999 |
+
class EuroBertForQuestionAnswering(EuroBertPreTrainedModel):
|
| 1000 |
+
def __init__(self, config: EuroBertConfig):
|
| 1001 |
+
super().__init__(config)
|
| 1002 |
+
self.num_labels = config.num_labels
|
| 1003 |
+
self.model = EuroBertModel(config)
|
| 1004 |
+
|
| 1005 |
+
self.qa_outputs = nn.Linear(config.hidden_size, config.num_labels)
|
| 1006 |
+
self.post_init()
|
| 1007 |
+
|
| 1008 |
+
def get_input_embeddings(self):
|
| 1009 |
+
return self.model.embed_tokens
|
| 1010 |
+
|
| 1011 |
+
def set_input_embeddings(self, value):
|
| 1012 |
+
self.model.embed_tokens = value
|
| 1013 |
+
|
| 1014 |
+
@add_start_docstrings_to_model_forward(EUROBERT_INPUTS_DOCSTRING)
|
| 1015 |
+
def forward(
|
| 1016 |
+
self,
|
| 1017 |
+
input_ids: Optional[torch.Tensor] = None,
|
| 1018 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1019 |
+
position_ids: Optional[torch.Tensor] = None,
|
| 1020 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1021 |
+
use_cache: Optional[bool] = None,
|
| 1022 |
+
start_positions: Optional[torch.Tensor] = None,
|
| 1023 |
+
end_positions: Optional[torch.Tensor] = None,
|
| 1024 |
+
output_attentions: Optional[bool] = None,
|
| 1025 |
+
output_hidden_states: Optional[bool] = None,
|
| 1026 |
+
return_dict: Optional[bool] = None,
|
| 1027 |
+
) -> Union[Tuple[torch.Tensor], QuestionAnsweringModelOutput]:
|
| 1028 |
+
r"""
|
| 1029 |
+
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1030 |
+
Labels for position (index) of the start of the labelled span for computing the token classification loss.
|
| 1031 |
+
Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
|
| 1032 |
+
are not taken into account for computing the loss.
|
| 1033 |
+
end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1034 |
+
Labels for position (index) of the end of the labelled span for computing the token classification loss.
|
| 1035 |
+
Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
|
| 1036 |
+
are not taken into account for computing the loss.
|
| 1037 |
+
"""
|
| 1038 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1039 |
+
|
| 1040 |
+
outputs = self.model(
|
| 1041 |
+
input_ids,
|
| 1042 |
+
attention_mask=attention_mask,
|
| 1043 |
+
position_ids=position_ids,
|
| 1044 |
+
inputs_embeds=inputs_embeds,
|
| 1045 |
+
use_cache=use_cache,
|
| 1046 |
+
output_attentions=output_attentions,
|
| 1047 |
+
output_hidden_states=output_hidden_states,
|
| 1048 |
+
return_dict=return_dict,
|
| 1049 |
+
)
|
| 1050 |
+
sequence_output = outputs[0]
|
| 1051 |
+
|
| 1052 |
+
logits = self.qa_outputs(sequence_output)
|
| 1053 |
+
start_logits, end_logits = logits.split(1, dim=-1)
|
| 1054 |
+
start_logits = start_logits.squeeze(-1).contiguous()
|
| 1055 |
+
end_logits = end_logits.squeeze(-1).contiguous()
|
| 1056 |
+
|
| 1057 |
+
total_loss = None
|
| 1058 |
+
if start_positions is not None and end_positions is not None:
|
| 1059 |
+
# If we are on multi-GPU, split add a dimension
|
| 1060 |
+
if len(start_positions.size()) > 1:
|
| 1061 |
+
start_positions = start_positions.squeeze(-1)
|
| 1062 |
+
if len(end_positions.size()) > 1:
|
| 1063 |
+
end_positions = end_positions.squeeze(-1)
|
| 1064 |
+
# sometimes the start/end positions are outside our model inputs, we ignore these terms
|
| 1065 |
+
ignored_index = start_logits.size(1)
|
| 1066 |
+
start_positions = start_positions.clamp(0, ignored_index)
|
| 1067 |
+
end_positions = end_positions.clamp(0, ignored_index)
|
| 1068 |
+
|
| 1069 |
+
loss_fct = CrossEntropyLoss(ignore_index=ignored_index)
|
| 1070 |
+
start_loss = loss_fct(start_logits, start_positions)
|
| 1071 |
+
end_loss = loss_fct(end_logits, end_positions)
|
| 1072 |
+
total_loss = (start_loss + end_loss) / 2
|
| 1073 |
+
|
| 1074 |
+
if not return_dict:
|
| 1075 |
+
output = (start_logits, end_logits) + outputs[2:]
|
| 1076 |
+
return ((total_loss,) + output) if total_loss is not None else output
|
| 1077 |
+
|
| 1078 |
+
return QuestionAnsweringModelOutput(
|
| 1079 |
+
loss=total_loss,
|
| 1080 |
+
start_logits=start_logits,
|
| 1081 |
+
end_logits=end_logits,
|
| 1082 |
+
hidden_states=outputs.hidden_states,
|
| 1083 |
+
attentions=outputs.attentions,
|
| 1084 |
+
)
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
__all__ = [
|
| 1088 |
+
"EuroBertPreTrainedModel",
|
| 1089 |
+
"EuroBertModel",
|
| 1090 |
+
"EuroBertForMaskedLM",
|
| 1091 |
+
"EuroBertForSequenceClassification",
|
| 1092 |
+
"EuroBertForTokenClassification",
|
| 1093 |
+
"EuroBertForQuestionAnswering",
|
| 1094 |
+
]
|
modules.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{
|
| 15 |
+
"idx": 2,
|
| 16 |
+
"name": "2",
|
| 17 |
+
"path": "2_Normalize",
|
| 18 |
+
"type": "sentence_transformers.models.Normalize"
|
| 19 |
+
}
|
| 20 |
+
]
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_seq_length": 512,
|
| 3 |
+
"do_lower_case": false
|
| 4 |
+
}
|