Add model2vec embeddings & scripts
Browse files- CELLAR_EN_16_05_2024.parquet +2 -2
- index_eurovoc.ipynb +597 -0
CELLAR_EN_16_05_2024.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:981f623ccde80e3504864b77ce5b8d881a857b279d98e7f9a87d93632f96bda6
|
3 |
+
size 5241312391
|
index_eurovoc.ipynb
ADDED
@@ -0,0 +1,597 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"data": {
|
10 |
+
"application/vnd.jupyter.widget-view+json": {
|
11 |
+
"model_id": "65f8e86024294a6794a4bb3550623b8a",
|
12 |
+
"version_major": 2,
|
13 |
+
"version_minor": 0
|
14 |
+
},
|
15 |
+
"text/plain": [
|
16 |
+
"Downloading readme: 0%| | 0.00/537 [00:00<?, ?B/s]"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
"metadata": {},
|
20 |
+
"output_type": "display_data"
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"data": {
|
24 |
+
"application/vnd.jupyter.widget-view+json": {
|
25 |
+
"model_id": "0ee2de5bf53248d8a4079029a9504bdb",
|
26 |
+
"version_major": 2,
|
27 |
+
"version_minor": 0
|
28 |
+
},
|
29 |
+
"text/plain": [
|
30 |
+
"Downloading data: 0%| | 0.00/4.79G [00:00<?, ?B/s]"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
"metadata": {},
|
34 |
+
"output_type": "display_data"
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"data": {
|
38 |
+
"application/vnd.jupyter.widget-view+json": {
|
39 |
+
"model_id": "74c255d685774394927b0aa2baddff72",
|
40 |
+
"version_major": 2,
|
41 |
+
"version_minor": 0
|
42 |
+
},
|
43 |
+
"text/plain": [
|
44 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
45 |
+
]
|
46 |
+
},
|
47 |
+
"metadata": {},
|
48 |
+
"output_type": "display_data"
|
49 |
+
}
|
50 |
+
],
|
51 |
+
"source": [
|
52 |
+
"from datasets import load_dataset\n",
|
53 |
+
"\n",
|
54 |
+
"ds = load_dataset(\"do-me/Eurovoc_en\")\n",
|
55 |
+
"df = ds[\"train\"].to_pandas()\n",
|
56 |
+
"df"
|
57 |
+
]
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"cell_type": "code",
|
61 |
+
"execution_count": 4,
|
62 |
+
"metadata": {},
|
63 |
+
"outputs": [
|
64 |
+
{
|
65 |
+
"data": {
|
66 |
+
"text/html": [
|
67 |
+
"<div>\n",
|
68 |
+
"<style scoped>\n",
|
69 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
70 |
+
" vertical-align: middle;\n",
|
71 |
+
" }\n",
|
72 |
+
"\n",
|
73 |
+
" .dataframe tbody tr th {\n",
|
74 |
+
" vertical-align: top;\n",
|
75 |
+
" }\n",
|
76 |
+
"\n",
|
77 |
+
" .dataframe thead th {\n",
|
78 |
+
" text-align: right;\n",
|
79 |
+
" }\n",
|
80 |
+
"</style>\n",
|
81 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
82 |
+
" <thead>\n",
|
83 |
+
" <tr style=\"text-align: right;\">\n",
|
84 |
+
" <th></th>\n",
|
85 |
+
" <th>title</th>\n",
|
86 |
+
" <th>date</th>\n",
|
87 |
+
" <th>eurovoc_concepts</th>\n",
|
88 |
+
" <th>url</th>\n",
|
89 |
+
" <th>lang</th>\n",
|
90 |
+
" <th>formats</th>\n",
|
91 |
+
" <th>text</th>\n",
|
92 |
+
" <th>__index_level_0__</th>\n",
|
93 |
+
" </tr>\n",
|
94 |
+
" </thead>\n",
|
95 |
+
" <tbody>\n",
|
96 |
+
" <tr>\n",
|
97 |
+
" <th>0</th>\n",
|
98 |
+
" <td>96/493/EC: Council Decision of 29 March 1996 c...</td>\n",
|
99 |
+
" <td>1996-03-29</td>\n",
|
100 |
+
" <td>[UNO, forest conservation, international agree...</td>\n",
|
101 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
102 |
+
" <td>eng</td>\n",
|
103 |
+
" <td>[fmx4, html, pdfa1b, print, xhtml]</td>\n",
|
104 |
+
" <td>L_1996208EN. 01000101. xml 17. 8. 1996 EN O...</td>\n",
|
105 |
+
" <td>29</td>\n",
|
106 |
+
" </tr>\n",
|
107 |
+
" <tr>\n",
|
108 |
+
" <th>1</th>\n",
|
109 |
+
" <td>Proposal for a COUNCIL AND COMMISSION DECISION...</td>\n",
|
110 |
+
" <td>1996-03-29</td>\n",
|
111 |
+
" <td>[Ukraine, accession to the European Union, coo...</td>\n",
|
112 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
113 |
+
" <td>eng</td>\n",
|
114 |
+
" <td>[pdf]</td>\n",
|
115 |
+
" <td>COMMISSION OI l l ll I UKOIM AN COMMUNIMI S Br...</td>\n",
|
116 |
+
" <td>48</td>\n",
|
117 |
+
" </tr>\n",
|
118 |
+
" <tr>\n",
|
119 |
+
" <th>2</th>\n",
|
120 |
+
" <td>Proposal for a COUNCIL AND COMMISSION DECISION...</td>\n",
|
121 |
+
" <td>1996-03-29</td>\n",
|
122 |
+
" <td>[EU relations, Moldova, accession to the Europ...</td>\n",
|
123 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
124 |
+
" <td>eng</td>\n",
|
125 |
+
" <td>[pdf]</td>\n",
|
126 |
+
" <td>, * ir ; COMMISSION OF THE EUROPEAN COMMUNITIE...</td>\n",
|
127 |
+
" <td>54</td>\n",
|
128 |
+
" </tr>\n",
|
129 |
+
" <tr>\n",
|
130 |
+
" <th>3</th>\n",
|
131 |
+
" <td>Amended proposal for a COUNCIL REGULATION (EC)...</td>\n",
|
132 |
+
" <td>1996-03-28</td>\n",
|
133 |
+
" <td>[Antarctic Ocean, authorised catch, conservati...</td>\n",
|
134 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
135 |
+
" <td>eng</td>\n",
|
136 |
+
" <td>[html, pdf, pdfa1b, print]</td>\n",
|
137 |
+
" <td>COMMISSION OF THE bUROPEAN COMMUNITIES Brussel...</td>\n",
|
138 |
+
" <td>73</td>\n",
|
139 |
+
" </tr>\n",
|
140 |
+
" <tr>\n",
|
141 |
+
" <th>4</th>\n",
|
142 |
+
" <td>Proposal for a COUNCIL DIRECTIVE amending Dire...</td>\n",
|
143 |
+
" <td>1996-03-27</td>\n",
|
144 |
+
" <td>[case law (EU), gender equality, job access, p...</td>\n",
|
145 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
146 |
+
" <td>eng</td>\n",
|
147 |
+
" <td>[html, pdf, pdfa1b, print]</td>\n",
|
148 |
+
" <td>COMMISSION OF THE EUROPEAN COMMUNITIES Brussel...</td>\n",
|
149 |
+
" <td>108</td>\n",
|
150 |
+
" </tr>\n",
|
151 |
+
" <tr>\n",
|
152 |
+
" <th>...</th>\n",
|
153 |
+
" <td>...</td>\n",
|
154 |
+
" <td>...</td>\n",
|
155 |
+
" <td>...</td>\n",
|
156 |
+
" <td>...</td>\n",
|
157 |
+
" <td>...</td>\n",
|
158 |
+
" <td>...</td>\n",
|
159 |
+
" <td>...</td>\n",
|
160 |
+
" <td>...</td>\n",
|
161 |
+
" </tr>\n",
|
162 |
+
" <tr>\n",
|
163 |
+
" <th>352006</th>\n",
|
164 |
+
" <td>Non-opposition to a notified concentration (Ca...</td>\n",
|
165 |
+
" <td>2023-12-04</td>\n",
|
166 |
+
" <td>[India, economic concentration, electric vehic...</td>\n",
|
167 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
168 |
+
" <td>eng</td>\n",
|
169 |
+
" <td>[fmx4, pdfa2a, xhtml]</td>\n",
|
170 |
+
" <td>C_202301503EN. 000101. fmx. xml Official Journ...</td>\n",
|
171 |
+
" <td>21936</td>\n",
|
172 |
+
" </tr>\n",
|
173 |
+
" <tr>\n",
|
174 |
+
" <th>352007</th>\n",
|
175 |
+
" <td>REPORT - on the proposal for a regulation of t...</td>\n",
|
176 |
+
" <td>2023-12-04</td>\n",
|
177 |
+
" <td>[EU statistics, European Statistical System, d...</td>\n",
|
178 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
179 |
+
" <td>eng</td>\n",
|
180 |
+
" <td>[URI]</td>\n",
|
181 |
+
" <td>None</td>\n",
|
182 |
+
" <td>21940</td>\n",
|
183 |
+
" </tr>\n",
|
184 |
+
" <tr>\n",
|
185 |
+
" <th>352008</th>\n",
|
186 |
+
" <td>Steps in the asylum procedure.</td>\n",
|
187 |
+
" <td>2023-12-02</td>\n",
|
188 |
+
" <td>[asylum seeker, external border of the EU, imm...</td>\n",
|
189 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
190 |
+
" <td>eng</td>\n",
|
191 |
+
" <td>[pdf, pdfx4, print]</td>\n",
|
192 |
+
" <td>Steps in the asylum procedure Arrival 1 Applyi...</td>\n",
|
193 |
+
" <td>21945</td>\n",
|
194 |
+
" </tr>\n",
|
195 |
+
" <tr>\n",
|
196 |
+
" <th>352009</th>\n",
|
197 |
+
" <td>Do you need support? :</td>\n",
|
198 |
+
" <td>2023-12-02</td>\n",
|
199 |
+
" <td>[aid to refugees, asylum seeker, external bord...</td>\n",
|
200 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
201 |
+
" <td>eng</td>\n",
|
202 |
+
" <td>[pdf]</td>\n",
|
203 |
+
" <td>Do you need support? lleuaa EUROPEAN UNION AGE...</td>\n",
|
204 |
+
" <td>21946</td>\n",
|
205 |
+
" </tr>\n",
|
206 |
+
" <tr>\n",
|
207 |
+
" <th>352010</th>\n",
|
208 |
+
" <td>Do you fear for your safety in your country? :...</td>\n",
|
209 |
+
" <td>2023-12-02</td>\n",
|
210 |
+
" <td>[aid to refugees, asylum seeker, external bord...</td>\n",
|
211 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
212 |
+
" <td>eng</td>\n",
|
213 |
+
" <td>[pdf, pdfx4, print]</td>\n",
|
214 |
+
" <td>Do you fear for your safety in your country? T...</td>\n",
|
215 |
+
" <td>21947</td>\n",
|
216 |
+
" </tr>\n",
|
217 |
+
" </tbody>\n",
|
218 |
+
"</table>\n",
|
219 |
+
"<p>352011 rows × 8 columns</p>\n",
|
220 |
+
"</div>"
|
221 |
+
],
|
222 |
+
"text/plain": [
|
223 |
+
" title date \\\n",
|
224 |
+
"0 96/493/EC: Council Decision of 29 March 1996 c... 1996-03-29 \n",
|
225 |
+
"1 Proposal for a COUNCIL AND COMMISSION DECISION... 1996-03-29 \n",
|
226 |
+
"2 Proposal for a COUNCIL AND COMMISSION DECISION... 1996-03-29 \n",
|
227 |
+
"3 Amended proposal for a COUNCIL REGULATION (EC)... 1996-03-28 \n",
|
228 |
+
"4 Proposal for a COUNCIL DIRECTIVE amending Dire... 1996-03-27 \n",
|
229 |
+
"... ... ... \n",
|
230 |
+
"352006 Non-opposition to a notified concentration (Ca... 2023-12-04 \n",
|
231 |
+
"352007 REPORT - on the proposal for a regulation of t... 2023-12-04 \n",
|
232 |
+
"352008 Steps in the asylum procedure. 2023-12-02 \n",
|
233 |
+
"352009 Do you need support? : 2023-12-02 \n",
|
234 |
+
"352010 Do you fear for your safety in your country? :... 2023-12-02 \n",
|
235 |
+
"\n",
|
236 |
+
" eurovoc_concepts \\\n",
|
237 |
+
"0 [UNO, forest conservation, international agree... \n",
|
238 |
+
"1 [Ukraine, accession to the European Union, coo... \n",
|
239 |
+
"2 [EU relations, Moldova, accession to the Europ... \n",
|
240 |
+
"3 [Antarctic Ocean, authorised catch, conservati... \n",
|
241 |
+
"4 [case law (EU), gender equality, job access, p... \n",
|
242 |
+
"... ... \n",
|
243 |
+
"352006 [India, economic concentration, electric vehic... \n",
|
244 |
+
"352007 [EU statistics, European Statistical System, d... \n",
|
245 |
+
"352008 [asylum seeker, external border of the EU, imm... \n",
|
246 |
+
"352009 [aid to refugees, asylum seeker, external bord... \n",
|
247 |
+
"352010 [aid to refugees, asylum seeker, external bord... \n",
|
248 |
+
"\n",
|
249 |
+
" url lang \\\n",
|
250 |
+
"0 http://publications.europa.eu/resource/cellar/... eng \n",
|
251 |
+
"1 http://publications.europa.eu/resource/cellar/... eng \n",
|
252 |
+
"2 http://publications.europa.eu/resource/cellar/... eng \n",
|
253 |
+
"3 http://publications.europa.eu/resource/cellar/... eng \n",
|
254 |
+
"4 http://publications.europa.eu/resource/cellar/... eng \n",
|
255 |
+
"... ... ... \n",
|
256 |
+
"352006 http://publications.europa.eu/resource/cellar/... eng \n",
|
257 |
+
"352007 http://publications.europa.eu/resource/cellar/... eng \n",
|
258 |
+
"352008 http://publications.europa.eu/resource/cellar/... eng \n",
|
259 |
+
"352009 http://publications.europa.eu/resource/cellar/... eng \n",
|
260 |
+
"352010 http://publications.europa.eu/resource/cellar/... eng \n",
|
261 |
+
"\n",
|
262 |
+
" formats \\\n",
|
263 |
+
"0 [fmx4, html, pdfa1b, print, xhtml] \n",
|
264 |
+
"1 [pdf] \n",
|
265 |
+
"2 [pdf] \n",
|
266 |
+
"3 [html, pdf, pdfa1b, print] \n",
|
267 |
+
"4 [html, pdf, pdfa1b, print] \n",
|
268 |
+
"... ... \n",
|
269 |
+
"352006 [fmx4, pdfa2a, xhtml] \n",
|
270 |
+
"352007 [URI] \n",
|
271 |
+
"352008 [pdf, pdfx4, print] \n",
|
272 |
+
"352009 [pdf] \n",
|
273 |
+
"352010 [pdf, pdfx4, print] \n",
|
274 |
+
"\n",
|
275 |
+
" text __index_level_0__ \n",
|
276 |
+
"0 L_1996208EN. 01000101. xml 17. 8. 1996 EN O... 29 \n",
|
277 |
+
"1 COMMISSION OI l l ll I UKOIM AN COMMUNIMI S Br... 48 \n",
|
278 |
+
"2 , * ir ; COMMISSION OF THE EUROPEAN COMMUNITIE... 54 \n",
|
279 |
+
"3 COMMISSION OF THE bUROPEAN COMMUNITIES Brussel... 73 \n",
|
280 |
+
"4 COMMISSION OF THE EUROPEAN COMMUNITIES Brussel... 108 \n",
|
281 |
+
"... ... ... \n",
|
282 |
+
"352006 C_202301503EN. 000101. fmx. xml Official Journ... 21936 \n",
|
283 |
+
"352007 None 21940 \n",
|
284 |
+
"352008 Steps in the asylum procedure Arrival 1 Applyi... 21945 \n",
|
285 |
+
"352009 Do you need support? lleuaa EUROPEAN UNION AGE... 21946 \n",
|
286 |
+
"352010 Do you fear for your safety in your country? T... 21947 \n",
|
287 |
+
"\n",
|
288 |
+
"[352011 rows x 8 columns]"
|
289 |
+
]
|
290 |
+
},
|
291 |
+
"execution_count": 4,
|
292 |
+
"metadata": {},
|
293 |
+
"output_type": "execute_result"
|
294 |
+
}
|
295 |
+
],
|
296 |
+
"source": [
|
297 |
+
"df = ds[\"train\"].to_pandas()\n",
|
298 |
+
"df"
|
299 |
+
]
|
300 |
+
},
|
301 |
+
{
|
302 |
+
"cell_type": "code",
|
303 |
+
"execution_count": 6,
|
304 |
+
"metadata": {},
|
305 |
+
"outputs": [],
|
306 |
+
"source": [
|
307 |
+
"from datasets import load_dataset\n",
|
308 |
+
"from model2vec import StaticModel\n",
|
309 |
+
"\n",
|
310 |
+
"model = StaticModel.from_pretrained(\"minishlab/M2V_base_output\")"
|
311 |
+
]
|
312 |
+
},
|
313 |
+
{
|
314 |
+
"cell_type": "code",
|
315 |
+
"execution_count": 8,
|
316 |
+
"metadata": {},
|
317 |
+
"outputs": [],
|
318 |
+
"source": [
|
319 |
+
"df[\"text\"] = df[\"text\"].fillna(\"\")"
|
320 |
+
]
|
321 |
+
},
|
322 |
+
{
|
323 |
+
"cell_type": "code",
|
324 |
+
"execution_count": 9,
|
325 |
+
"metadata": {},
|
326 |
+
"outputs": [
|
327 |
+
{
|
328 |
+
"name": "stdout",
|
329 |
+
"output_type": "stream",
|
330 |
+
"text": [
|
331 |
+
"CPU times: user 17min 49s, sys: 16.3 s, total: 18min 6s\n",
|
332 |
+
"Wall time: 1min 36s\n"
|
333 |
+
]
|
334 |
+
}
|
335 |
+
],
|
336 |
+
"source": [
|
337 |
+
"%%time \n",
|
338 |
+
"embeddings = model.encode(df.text)\n",
|
339 |
+
"df[\"embeddings\"] = embeddings.tolist()"
|
340 |
+
]
|
341 |
+
},
|
342 |
+
{
|
343 |
+
"cell_type": "code",
|
344 |
+
"execution_count": 19,
|
345 |
+
"metadata": {},
|
346 |
+
"outputs": [],
|
347 |
+
"source": [
|
348 |
+
"del df[\"__index_level_0__\"]"
|
349 |
+
]
|
350 |
+
},
|
351 |
+
{
|
352 |
+
"cell_type": "code",
|
353 |
+
"execution_count": 28,
|
354 |
+
"metadata": {},
|
355 |
+
"outputs": [],
|
356 |
+
"source": [
|
357 |
+
"del df[\"cos_sim\"]"
|
358 |
+
]
|
359 |
+
},
|
360 |
+
{
|
361 |
+
"cell_type": "code",
|
362 |
+
"execution_count": 30,
|
363 |
+
"metadata": {},
|
364 |
+
"outputs": [],
|
365 |
+
"source": [
|
366 |
+
"df = df.sort_index()"
|
367 |
+
]
|
368 |
+
},
|
369 |
+
{
|
370 |
+
"cell_type": "code",
|
371 |
+
"execution_count": 31,
|
372 |
+
"metadata": {},
|
373 |
+
"outputs": [],
|
374 |
+
"source": [
|
375 |
+
"df.to_parquet(\"CELLAR_EN_16_05_2024.parquet\")"
|
376 |
+
]
|
377 |
+
},
|
378 |
+
{
|
379 |
+
"cell_type": "markdown",
|
380 |
+
"metadata": {},
|
381 |
+
"source": [
|
382 |
+
"## Test query"
|
383 |
+
]
|
384 |
+
},
|
385 |
+
{
|
386 |
+
"cell_type": "code",
|
387 |
+
"execution_count": null,
|
388 |
+
"metadata": {},
|
389 |
+
"outputs": [],
|
390 |
+
"source": [
|
391 |
+
"from model2vec import StaticModel\n",
|
392 |
+
"\n",
|
393 |
+
"model = StaticModel.from_pretrained(\"minishlab/M2V_base_output\")"
|
394 |
+
]
|
395 |
+
},
|
396 |
+
{
|
397 |
+
"cell_type": "code",
|
398 |
+
"execution_count": 24,
|
399 |
+
"metadata": {},
|
400 |
+
"outputs": [],
|
401 |
+
"source": [
|
402 |
+
"import numpy as np\n",
|
403 |
+
"from sklearn.metrics.pairwise import cosine_similarity \n",
|
404 |
+
"\n",
|
405 |
+
"query = \"social democracy\"\n",
|
406 |
+
"quer_emb = model.encode(query)\n",
|
407 |
+
"\n",
|
408 |
+
"embeddings_matrix = np.stack(df['embeddings'].to_numpy())\n",
|
409 |
+
"df[\"cos_sim\"] = cosine_similarity(embeddings_matrix, quer_emb.reshape(1, -1))[:, 0]\n",
|
410 |
+
"df = df.sort_values(\"cos_sim\", ascending=False)"
|
411 |
+
]
|
412 |
+
},
|
413 |
+
{
|
414 |
+
"cell_type": "code",
|
415 |
+
"execution_count": 26,
|
416 |
+
"metadata": {},
|
417 |
+
"outputs": [
|
418 |
+
{
|
419 |
+
"data": {
|
420 |
+
"text/html": [
|
421 |
+
"<div>\n",
|
422 |
+
"<style scoped>\n",
|
423 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
424 |
+
" vertical-align: middle;\n",
|
425 |
+
" }\n",
|
426 |
+
"\n",
|
427 |
+
" .dataframe tbody tr th {\n",
|
428 |
+
" vertical-align: top;\n",
|
429 |
+
" }\n",
|
430 |
+
"\n",
|
431 |
+
" .dataframe thead th {\n",
|
432 |
+
" text-align: right;\n",
|
433 |
+
" }\n",
|
434 |
+
"</style>\n",
|
435 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
436 |
+
" <thead>\n",
|
437 |
+
" <tr style=\"text-align: right;\">\n",
|
438 |
+
" <th></th>\n",
|
439 |
+
" <th>title</th>\n",
|
440 |
+
" <th>date</th>\n",
|
441 |
+
" <th>eurovoc_concepts</th>\n",
|
442 |
+
" <th>url</th>\n",
|
443 |
+
" <th>lang</th>\n",
|
444 |
+
" <th>formats</th>\n",
|
445 |
+
" <th>text</th>\n",
|
446 |
+
" <th>embeddings</th>\n",
|
447 |
+
" <th>cos_sim</th>\n",
|
448 |
+
" </tr>\n",
|
449 |
+
" </thead>\n",
|
450 |
+
" <tbody>\n",
|
451 |
+
" <tr>\n",
|
452 |
+
" <th>295413</th>\n",
|
453 |
+
" <td>10 trends shaping democracy in a volatile world.</td>\n",
|
454 |
+
" <td>2019-11-21</td>\n",
|
455 |
+
" <td>[democracy, digital technology, election, popu...</td>\n",
|
456 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
457 |
+
" <td>eng</td>\n",
|
458 |
+
" <td>[pdf]</td>\n",
|
459 |
+
" <td>31 October 2019 10 TRENDS SHAPING DEMOCRACY IN...</td>\n",
|
460 |
+
" <td>[-0.7749167680740356, 5.183741569519043, -4.15...</td>\n",
|
461 |
+
" <td>0.497865</td>\n",
|
462 |
+
" </tr>\n",
|
463 |
+
" <tr>\n",
|
464 |
+
" <th>351006</th>\n",
|
465 |
+
" <td>Defence of democracy.</td>\n",
|
466 |
+
" <td>2023-12-20</td>\n",
|
467 |
+
" <td>[action programme, civic engagement, democracy...</td>\n",
|
468 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
469 |
+
" <td>eng</td>\n",
|
470 |
+
" <td>[pdf]</td>\n",
|
471 |
+
" <td>Defence of Democracy #EUDemocracy 12 December ...</td>\n",
|
472 |
+
" <td>[-0.4795585572719574, 6.859988212585449, -5.87...</td>\n",
|
473 |
+
" <td>0.451415</td>\n",
|
474 |
+
" </tr>\n",
|
475 |
+
" <tr>\n",
|
476 |
+
" <th>314572</th>\n",
|
477 |
+
" <td>EU citizenship report 2020 : factsheet.</td>\n",
|
478 |
+
" <td>2021-04-20</td>\n",
|
479 |
+
" <td>[European citizenship, European election, acce...</td>\n",
|
480 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
481 |
+
" <td>eng</td>\n",
|
482 |
+
" <td>[pdf]</td>\n",
|
483 |
+
" <td>EU Citizenship Report 2020 F A C T S H E E T 1...</td>\n",
|
484 |
+
" <td>[-0.9046934247016907, 5.682852745056152, -4.97...</td>\n",
|
485 |
+
" <td>0.432170</td>\n",
|
486 |
+
" </tr>\n",
|
487 |
+
" <tr>\n",
|
488 |
+
" <th>286936</th>\n",
|
489 |
+
" <td>Opinion of the European Economic and Social Co...</td>\n",
|
490 |
+
" <td>2019-03-20</td>\n",
|
491 |
+
" <td>[Liberalism, civil society, democracy, extremi...</td>\n",
|
492 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
493 |
+
" <td>eng</td>\n",
|
494 |
+
" <td>[fmx4, pdfa2a, xhtml]</td>\n",
|
495 |
+
" <td>C_2019228EN. 01002401. xml 5. 7. 2019 EN Of...</td>\n",
|
496 |
+
" <td>[-0.5640900135040283, 3.6944658756256104, -4.5...</td>\n",
|
497 |
+
" <td>0.420833</td>\n",
|
498 |
+
" </tr>\n",
|
499 |
+
" <tr>\n",
|
500 |
+
" <th>330997</th>\n",
|
501 |
+
" <td>Making participatory and deliberative democrac...</td>\n",
|
502 |
+
" <td>2022-06-16</td>\n",
|
503 |
+
" <td>[EU research policy, green economy, innovation...</td>\n",
|
504 |
+
" <td>http://publications.europa.eu/resource/cellar/...</td>\n",
|
505 |
+
" <td>eng</td>\n",
|
506 |
+
" <td>[pdf]</td>\n",
|
507 |
+
" <td>#HorizonEU June 2022 MAKING PARTICIPATORY AND ...</td>\n",
|
508 |
+
" <td>[-0.27760544419288635, 5.397331237792969, -5.9...</td>\n",
|
509 |
+
" <td>0.419882</td>\n",
|
510 |
+
" </tr>\n",
|
511 |
+
" </tbody>\n",
|
512 |
+
"</table>\n",
|
513 |
+
"</div>"
|
514 |
+
],
|
515 |
+
"text/plain": [
|
516 |
+
" title date \\\n",
|
517 |
+
"295413 10 trends shaping democracy in a volatile world. 2019-11-21 \n",
|
518 |
+
"351006 Defence of democracy. 2023-12-20 \n",
|
519 |
+
"314572 EU citizenship report 2020 : factsheet. 2021-04-20 \n",
|
520 |
+
"286936 Opinion of the European Economic and Social Co... 2019-03-20 \n",
|
521 |
+
"330997 Making participatory and deliberative democrac... 2022-06-16 \n",
|
522 |
+
"\n",
|
523 |
+
" eurovoc_concepts \\\n",
|
524 |
+
"295413 [democracy, digital technology, election, popu... \n",
|
525 |
+
"351006 [action programme, civic engagement, democracy... \n",
|
526 |
+
"314572 [European citizenship, European election, acce... \n",
|
527 |
+
"286936 [Liberalism, civil society, democracy, extremi... \n",
|
528 |
+
"330997 [EU research policy, green economy, innovation... \n",
|
529 |
+
"\n",
|
530 |
+
" url lang \\\n",
|
531 |
+
"295413 http://publications.europa.eu/resource/cellar/... eng \n",
|
532 |
+
"351006 http://publications.europa.eu/resource/cellar/... eng \n",
|
533 |
+
"314572 http://publications.europa.eu/resource/cellar/... eng \n",
|
534 |
+
"286936 http://publications.europa.eu/resource/cellar/... eng \n",
|
535 |
+
"330997 http://publications.europa.eu/resource/cellar/... eng \n",
|
536 |
+
"\n",
|
537 |
+
" formats \\\n",
|
538 |
+
"295413 [pdf] \n",
|
539 |
+
"351006 [pdf] \n",
|
540 |
+
"314572 [pdf] \n",
|
541 |
+
"286936 [fmx4, pdfa2a, xhtml] \n",
|
542 |
+
"330997 [pdf] \n",
|
543 |
+
"\n",
|
544 |
+
" text \\\n",
|
545 |
+
"295413 31 October 2019 10 TRENDS SHAPING DEMOCRACY IN... \n",
|
546 |
+
"351006 Defence of Democracy #EUDemocracy 12 December ... \n",
|
547 |
+
"314572 EU Citizenship Report 2020 F A C T S H E E T 1... \n",
|
548 |
+
"286936 C_2019228EN. 01002401. xml 5. 7. 2019 EN Of... \n",
|
549 |
+
"330997 #HorizonEU June 2022 MAKING PARTICIPATORY AND ... \n",
|
550 |
+
"\n",
|
551 |
+
" embeddings cos_sim \n",
|
552 |
+
"295413 [-0.7749167680740356, 5.183741569519043, -4.15... 0.497865 \n",
|
553 |
+
"351006 [-0.4795585572719574, 6.859988212585449, -5.87... 0.451415 \n",
|
554 |
+
"314572 [-0.9046934247016907, 5.682852745056152, -4.97... 0.432170 \n",
|
555 |
+
"286936 [-0.5640900135040283, 3.6944658756256104, -4.5... 0.420833 \n",
|
556 |
+
"330997 [-0.27760544419288635, 5.397331237792969, -5.9... 0.419882 "
|
557 |
+
]
|
558 |
+
},
|
559 |
+
"execution_count": 26,
|
560 |
+
"metadata": {},
|
561 |
+
"output_type": "execute_result"
|
562 |
+
}
|
563 |
+
],
|
564 |
+
"source": [
|
565 |
+
"df.head(5)"
|
566 |
+
]
|
567 |
+
},
|
568 |
+
{
|
569 |
+
"cell_type": "code",
|
570 |
+
"execution_count": null,
|
571 |
+
"metadata": {},
|
572 |
+
"outputs": [],
|
573 |
+
"source": []
|
574 |
+
}
|
575 |
+
],
|
576 |
+
"metadata": {
|
577 |
+
"kernelspec": {
|
578 |
+
"display_name": "py3.11",
|
579 |
+
"language": "python",
|
580 |
+
"name": "python3"
|
581 |
+
},
|
582 |
+
"language_info": {
|
583 |
+
"codemirror_mode": {
|
584 |
+
"name": "ipython",
|
585 |
+
"version": 3
|
586 |
+
},
|
587 |
+
"file_extension": ".py",
|
588 |
+
"mimetype": "text/x-python",
|
589 |
+
"name": "python",
|
590 |
+
"nbconvert_exporter": "python",
|
591 |
+
"pygments_lexer": "ipython3",
|
592 |
+
"version": "3.11.9"
|
593 |
+
}
|
594 |
+
},
|
595 |
+
"nbformat": 4,
|
596 |
+
"nbformat_minor": 2
|
597 |
+
}
|