davidmezzetti commited on
Commit
607707e
·
1 Parent(s): 001d6d4

Add dataset

Browse files
Files changed (3) hide show
  1. README.md +12 -0
  2. labels.csv +0 -0
  3. labels.py +46 -0
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ ---
5
+
6
+ # Dataset card for Wikipedia Domain Labels
7
+
8
+ This dataset is a list of domain labels for the [txtai-wikipedia-slim](https://huggingface.co/NeuML/txtai-wikipedia-slim) embeddings database, which is the Top 100K most viewed Wikipedia articles.
9
+
10
+ ## Training code
11
+
12
+ [The training code used to build this model is here](https://huggingface.co/datasets/NeuML/wikipedia-domain-labels/blob/main/labels.py).
labels.csv ADDED
The diff for this file is too large to render. See raw diff
 
labels.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+
3
+ from tqdm.auto import tqdm
4
+ from txtai import Embeddings
5
+ from txtai.pipeline import Labels
6
+
7
+ LABELS = [
8
+ "aerospace", "agronomy", "artistic", "astronomy", "atmospheric_science", "automotive", "beauty",
9
+ "biology", "celebrity", "chemistry", "civil_engineering", "communication_engineering",
10
+ "computer_science_and_technology", "design", "drama_and_film", "economics",
11
+ "electronic_science", "entertainment", "environmental_science", "fashion", "finance",
12
+ "food", "gamble", "game", "geography", "health", "history", "hobby", "hydraulic_engineering",
13
+ "instrument_science", "journalism_and_media_communication", "landscape_architecture", "law",
14
+ "library", "literature", "materials_science", "mathematics", "mechanical_engineering",
15
+ "medical", "mining_engineering", "movie", "music_and_dance", "news", "nuclear_science",
16
+ "ocean_science", "optical_engineering", "painting", "pet",
17
+ "petroleum_and_natural_gas_engineering", "philosophy", "photo", "physics", "politics",
18
+ "psychology", "public_administration", "relationship", "religion", "sociology", "sports",
19
+ "statistics", "systems_science", "textile_science", "topicality", "transportation_engineering",
20
+ "travel", "urban_planning", "vulgar_language",
21
+ ]
22
+
23
+
24
+ def stream():
25
+ for row in tqdm(rows):
26
+ yield row["text"]
27
+
28
+
29
+ labels = Labels("MoritzLaurer/deberta-v3-large-zeroshot-v2.0-c")
30
+
31
+ embeddings = Embeddings()
32
+ embeddings.load(provider="huggingface-hub", container="neuml/txtai-wikipedia-slim")
33
+
34
+ rows = embeddings.search("SELECT id, text FROM txtai", 100_000)
35
+
36
+ print("NUMBER OF LABELS:", len(LABELS))
37
+
38
+ with open("labels.csv", "w", encoding="utf-8", newline="") as f:
39
+ writer = csv.writer(f)
40
+
41
+ # Write header
42
+ writer.writerow(["id", "label"])
43
+
44
+ # Write each row one by one
45
+ for x, label in enumerate(labels(stream(), LABELS, flatten=True, batch_size=32)):
46
+ writer.writerow([rows[x]["id"], label[0]])