Add README
Browse files
README.md
CHANGED
@@ -1,26 +1,165 @@
|
|
1 |
---
|
2 |
dataset_info:
|
3 |
features:
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
splits:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
download_size: 2307703671
|
20 |
dataset_size: 2580729273
|
|
|
21 |
configs:
|
22 |
-
- config_name: default
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
dataset_info:
|
3 |
features:
|
4 |
+
- name: id
|
5 |
+
dtype: string
|
6 |
+
- name: url
|
7 |
+
dtype: string
|
8 |
+
- name: title
|
9 |
+
dtype: string
|
10 |
+
- name: chunks
|
11 |
+
sequence: string
|
12 |
+
- name: embeddings
|
13 |
+
sequence:
|
14 |
+
sequence: float32
|
15 |
splits:
|
16 |
+
- name: train
|
17 |
+
num_bytes: 2580729273
|
18 |
+
num_examples: 534044
|
19 |
download_size: 2307703671
|
20 |
dataset_size: 2580729273
|
21 |
+
|
22 |
configs:
|
23 |
+
- config_name: default
|
24 |
+
data_files:
|
25 |
+
- split: train
|
26 |
+
path: data/train-*
|
27 |
+
|
28 |
+
language:
|
29 |
+
- cs
|
30 |
+
|
31 |
+
size_categories:
|
32 |
+
- 100K<n<1M
|
33 |
+
|
34 |
+
task_categories:
|
35 |
+
- text-generation
|
36 |
+
- fill-mask
|
37 |
+
|
38 |
+
license:
|
39 |
+
- cc-by-sa-3.0
|
40 |
+
- gfdl
|
41 |
---
|
42 |
+
|
43 |
+
This dataset contains the Czech subset of the [`wikimedia/wikipedia`](https://huggingface.co/datasets/wikimedia/wikipedia) dataset. Each page is divided into paragraphs, stored as a list in the `chunks` column. For every paragraph, embeddings are created using the [`Seznam/simcse-dist-mpnet-paracrawl-cs-en`](https://huggingface.co/Seznam/simcse-dist-mpnet-paracrawl-cs-en) model.
|
44 |
+
|
45 |
+
## Usage
|
46 |
+
|
47 |
+
Load the dataset:
|
48 |
+
|
49 |
+
```python
|
50 |
+
from datasets import load_dataset
|
51 |
+
|
52 |
+
ds = load_dataset("karmiq/wikipedia-embeddings-cs-seznam-mpnet", split="train")
|
53 |
+
ds[1]
|
54 |
+
```
|
55 |
+
|
56 |
+
```
|
57 |
+
{
|
58 |
+
'id': '1',
|
59 |
+
'url': 'https://cs.wikipedia.org/wiki/Astronomie',
|
60 |
+
'title': 'Astronomie',
|
61 |
+
'chunks': [
|
62 |
+
'Astronomie, řecky αστρονομία z άστρον ( astron ) hvězda a νόμος ( nomos ) ...',
|
63 |
+
'Novověk Roku 1514 navrhl Mikuláš Koperník nový model, ve kterém bylo ...',
|
64 |
+
...,
|
65 |
+
],
|
66 |
+
'embeddings': [
|
67 |
+
[ 0.653917670249939, -0.879465639591217, 0.3993946313858032, ... ]
|
68 |
+
[ 0.0035442777443677187, -1.0201066732406616, -0.06573136150836945, ... ]
|
69 |
+
]
|
70 |
+
}
|
71 |
+
```
|
72 |
+
|
73 |
+
The structure makes it easy to use the dataset for implementing semantic search.
|
74 |
+
|
75 |
+
<details>
|
76 |
+
<summary>Load the data in Elasticsearch</summary>
|
77 |
+
|
78 |
+
```python
|
79 |
+
def doc_generator(data, batch_size=1000):
|
80 |
+
for batch in data.with_format("numpy").iter(batch_size):
|
81 |
+
for i, id in enumerate(batch["id"]):
|
82 |
+
output = {"id": id}
|
83 |
+
output["title"] = batch["title"][i]
|
84 |
+
output["url"] = batch["url"][i]
|
85 |
+
output["parts"] = [
|
86 |
+
{ "chunk": chunk, "embedding": embedding }
|
87 |
+
for chunk, embedding in zip(batch["chunks"][i], batch["embeddings"][i])
|
88 |
+
]
|
89 |
+
yield output
|
90 |
+
|
91 |
+
num_indexed, num_failed = 0, 0,
|
92 |
+
progress = tqdm(total=ds.num_rows, unit="doc", desc="Indexing")
|
93 |
+
|
94 |
+
for ok, info in parallel_bulk(
|
95 |
+
es,
|
96 |
+
index="wikipedia-search",
|
97 |
+
actions=doc_generator(ds),
|
98 |
+
raise_on_error=False,
|
99 |
+
):
|
100 |
+
if not ok:
|
101 |
+
print(f"ERROR {info['index']['status']}: {info['index']['error']}"
|
102 |
+
|
103 |
+
progress.update(1)
|
104 |
+
```
|
105 |
+
</details>
|
106 |
+
|
107 |
+
<details>
|
108 |
+
<summary>Use <code>sentence_transformers.util.semantic_search</code></summary>
|
109 |
+
|
110 |
+
```python
|
111 |
+
import os
|
112 |
+
import textwrap
|
113 |
+
|
114 |
+
import sentence_transformers
|
115 |
+
|
116 |
+
model = sentence_transformers.SentenceTransformer("Seznam/simcse-dist-mpnet-paracrawl-cs-en")
|
117 |
+
|
118 |
+
ds.set_format(type="torch", columns=["embeddings"], output_all_columns=True)
|
119 |
+
|
120 |
+
# Flatten the dataset
|
121 |
+
def explode_sequence(batch):
|
122 |
+
output = { "id": [], "url": [], "title": [], "chunk": [], "embedding": [] }
|
123 |
+
|
124 |
+
for id, url, title, chunks, embeddings in zip(
|
125 |
+
batch["id"], batch["url"], batch["title"], batch["chunks"], batch["embeddings"]
|
126 |
+
):
|
127 |
+
output["id"].extend([id for _ in range(len(chunks))])
|
128 |
+
output["url"].extend([url for _ in range(len(chunks))])
|
129 |
+
output["title"].extend([title for _ in range(len(chunks))])
|
130 |
+
output["chunk"].extend(chunks)
|
131 |
+
output["embedding"].extend(embeddings)
|
132 |
+
|
133 |
+
return output
|
134 |
+
|
135 |
+
ds_flat = ds.map(
|
136 |
+
explode_sequence,
|
137 |
+
batched=True,
|
138 |
+
remove_columns=ds.column_names,
|
139 |
+
num_proc=min(os.cpu_count(), 32),
|
140 |
+
desc="Flatten")
|
141 |
+
ds_flat
|
142 |
+
|
143 |
+
query = "Čím se zabývá fyzika?"
|
144 |
+
|
145 |
+
hits = sentence_transformers.util.semantic_search(
|
146 |
+
query_embeddings=model.encode(query),
|
147 |
+
corpus_embeddings=ds_flat["embedding"],
|
148 |
+
top_k=10)
|
149 |
+
|
150 |
+
for hit in hits[0]:
|
151 |
+
title = ds_flat[hit['corpus_id']]['title']
|
152 |
+
chunk = ds_flat[hit['corpus_id']]['chunk']
|
153 |
+
print(f"[{hit['score']:0.2f}] {textwrap.shorten(chunk, width=100, placeholder='…')} [{title}]")
|
154 |
+
|
155 |
+
# [0.58] Dynamika Fyzikální zákony [Newtonovy pohybové zákony]
|
156 |
+
# [0.53] Teorie množin [Ordinální číslo]
|
157 |
+
# ...
|
158 |
+
```
|
159 |
+
</details>
|
160 |
+
|
161 |
+
The embeddings generation took about 25 minutes on an NVIDIA RTX 4090 24GB.
|
162 |
+
|
163 |
+
## License
|
164 |
+
|
165 |
+
See license of the original dataset: <https://huggingface.co/datasets/wikimedia/wikipedia>.
|