Datasets:

Languages:
English
Tags:
Not-For-All-Audiences
License:
Gaeros commited on
Commit
2b1e5cf
1 Parent(s): 1ba045b

update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -5
README.md CHANGED
@@ -1,11 +1,86 @@
1
  ---
2
  license: cc-by-sa-4.0
3
  task_categories:
4
- - token-classification
5
  language:
6
- - en
7
  size_categories:
8
- - 10K<n<100K
9
  tags:
10
- - not-for-all-audiences
11
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-4.0
3
  task_categories:
4
+ - token-classification
5
  language:
6
+ - en
7
  size_categories:
8
+ - 10K<n<100K
9
  tags:
10
+ - not-for-all-audiences
11
+ ---
12
+
13
+ # E6DB
14
+
15
+ This a dataset is compiled from the e621 database. It currently provides indexes
16
+ for normalizing tags and embeddings for finding similar tags.
17
+
18
+ ## Utilities
19
+
20
+ ### `query_tags.py`
21
+
22
+ A small command-line utility that finds related tags and generates 2D plots illustrating tag relationships through local PCA projection. It utilizes collaborative filtering embeddings, [computed with alternating least squares](./notebooks/AltLstSq.ipynb).
23
+
24
+ When only tags are provided as arguments, it displays the top-k most similar tags (where k is set with `-k`). By using `-o plot.png` or `-o -`, it saves or displays a 2D plot showing the local projection of the query and related tags.
25
+
26
+ Tag categories are represented with the e621 color scheme. Results can be filtered based on one or more categories using the `-c` flag once or multiple times. The `-f` flag sets a post count threshold.
27
+
28
+ Filtering occurs in the following sequence:
29
+
30
+ - Tags used fewer than twice are excluded from the dataset; tags with a post count lower than the `-f` threshold are also discarded.
31
+ - If a category filter is specified, only matching tags are retained.
32
+ - For each query tag, the most `-k` similar neighboring tags are selected.
33
+ - The per-query neighbors are printed, and if no plot is being generated, filtering halts at this point.
34
+ - Similarity scores are aggregated across queries, and the `-n` tags closest to all queries are chosen for the PCA.
35
+ - Only the highest `-N` scoring tags are displayed in the plot.
36
+
37
+ ### `e6db.utils`
38
+
39
+ This [module](./e6db/utils/__init__.py) contains utilities for loading the provided data and use it to normalize tag sets.
40
+
41
+ - `load_tags` and `load_implications` loads the tags indexes and implications,
42
+ - `TagNormalizer` allows to adapt the spellings of tag and alias for working with various datasets. It can normalize spellings by converting tag strings to numerical ids and back,
43
+ - `TagSetNormalizer` uses the above class along tag implications to normalize tag sets and strip implied tags.
44
+
45
+ See [this example notebook](./notebooks/Normalize%20tags%20T2I%20dataset.ipynb) that cleans T2I datasets in the sd-script format.
46
+
47
+ Additionally, the `e6db.utils.numpy` and `e6db.utils.torch` modules provides
48
+ functions to construct post-tag interaction matrices in sparse matrix format. For this
49
+ you'll need to generate the `posts.parquet` file from CSVs.
50
+
51
+ ### `importdb`
52
+
53
+ Reads the CSVs from [e621 db export](https://e621.net/db_export/)
54
+
55
+ `python -m e6db.importdb ./data` reads tags, aliases, implications and posts CSV
56
+ files. The following operations are performed:
57
+
58
+ - Tags used at least twice are assigned numerical ids based on their rank.
59
+ - Computes the transitive closure of implications,
60
+ - For each post, split the tags into direct and implied tag.
61
+ - Write parquets files for tags and posts (~500MB) and convert tags indexes using simple formats described in the next section.
62
+
63
+ The CSV files must be decompressed beforehand.
64
+
65
+ ## Dataset content
66
+
67
+ This dataset currently focus on tags alone using simple file formats that are
68
+ easily parsed without additional dependencies.
69
+
70
+ - `tag2idx.json.gz`: a dictionary mapping tag strings and aliases to numerical id (tag rank),
71
+ - `tags.txt.gz`: list of tags sorted by rank, can be indexed by the ids given by `tag2idx.json.gz`,
72
+ - `tags_categories.bin.gz`: a raw array of bytes representing tag categories in the same order than `tags.txt.gz`,
73
+ - `implications.json.gz`: maps tags id to implied tag ids (including transitive implications),
74
+ - `implications_rej.json.gz`: maps tag strings to a list of implied numerical
75
+ ids. Keys in implications_rej are tags that have a very little usage (less
76
+ than 2 posts) and don't have numerical ids associated with them.
77
+ - `implicit_tag_factors.safetensors`: Tag embedding computed by [alternating least squares](./notebooks/AltLstSq.ipynb).
78
+
79
+ No post data is currently included, since this wouldn't add any useful
80
+ information compared to what's inside the CSVs. If you want the post parquet
81
+ files with normalized tags, you can download the CSVs and run the
82
+ [`e6db.importdb`](#importdb) script yourself.
83
+
84
+ I plan to compile more post data in the future, such as aesthetic predictions,
85
+ adjusted favcounts, etc. Utilities will then be added to assists with the
86
+ selection of a subset of posts for specific ML tasks.