Datasets:

Modalities:
Text
Formats:
parquet
ArXiv:
Libraries:
Datasets
pandas
License:
File size: 1,957 Bytes
da1a91a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from bs4 import BeautifulSoup
from datasets import load_dataset

def get_titles(file_path):
    # get the titles from html file (html file is downloaded from https://de.wikipedia.org/wiki/Wikipedia:Exzellente_Artikel)
    with open(file_path, 'r') as f:
        html_content = f.read()
    soup = BeautifulSoup(html_content, 'html.parser')
    # Find the <tbody> element (you can modify this based on your HTML structure)
    tbody = soup.find('tbody')
    # Extract all <tr> elements within the <tbody> element
    trs = tbody.find_all('tr')
    # Remove the first two <tr> elements
    trs = trs[2:]
    # Extract title attributes from the remaining <tr> elements
    titles = []
    for tr in trs:
        if tr is None or tr.find('a') is None:
            continue
        a_tags = tr.find_all('a')
        for a_tag in a_tags:
            if a_tag and 'title' in a_tag.attrs:
                titles.append(a_tag['title'])
    return titles

if __name__ == '__main__':
    titles_exzellent = get_titles('exzellent.txt')
    #titles_lesenswert = get_titles('lesenswert.txt')
    titles = titles_exzellent #+ titles_lesenswert
    titles = list(set(titles))
    with open('titles.txt', 'w') as f:
        for title in titles:
            f.write(title + '\n')
    
    # Get wikipedia dataset
    dataset = load_dataset("graelo/wikipedia", "20230901.de", split="train")
    # Filter dataset
    dataset = dataset.filter(lambda example: example['title'] in titles, num_proc=64)
    dataset.map(lambda x: {'text': f"# {x['title']}\n\n{x['text']}"}, remove_columns=['title'], num_proc=64)
    # Save dataset
    used_title = [example['title'] for example in dataset]
    non_used_title = [title for title in titles if title not in used_title]
    print(f'Number of used titles: {len(used_title)}')
    print(f'Number of non used titles: {len(non_used_title)}')
    print(non_used_title[:20])

    dataset.push_to_hub("LeoLM/wiki_de_exzellent", private=True)