Datasets:

Languages:
English
Tags:
Not-For-All-Audiences
License:
Gaeros commited on
Commit
26807ba
1 Parent(s): e2c0539

e6localmap: new version using ALS factors

Browse files
.gitattributes CHANGED
@@ -1,3 +1,4 @@
1
  *.txt filter=lfs diff=lfs merge=lfs -text
2
  *.json filter=lfs diff=lfs merge=lfs -text
3
  *.safetensors filter=lfs diff=lfs merge=lfs -text
 
 
1
  *.txt filter=lfs diff=lfs merge=lfs -text
2
  *.json filter=lfs diff=lfs merge=lfs -text
3
  *.safetensors filter=lfs diff=lfs merge=lfs -text
4
+ *.gz filter=lfs diff=lfs merge=lfs -text
data/{model-verybighalfbrain2e60.safetensors → implicit_tag_factors.safetensors} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:37fc80f31f158d5de026446b277b6da112677b72196994740b6d26d43e7c88f5
3
- size 70397688
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfea51d9db1bd413aedb1781cc4b936c41c117a78221bc18dfbc6dface513ef7
3
+ size 33554520
data/{tags.txt → tag2idx.json.gz} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:10cca1eba52aa3b36145f6c913911067221c660b51000e51dbaf598edb77b289
3
- size 424308
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4c98ec5f2b8488abd68ef617425c4d1fc1afd5962898d1dd78963444075485a
3
+ size 4253419
data/tags.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1d0910d099345c89fedb6eb8acdac1312d18758e8c3678910602f7a42435803
3
+ size 2875605
e6db/utils.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import gzip
3
+ import json
4
+
5
+ # FIXME: split this module by dependencies
6
+ import numpy as np
7
+ import scipy.sparse
8
+ import torch
9
+ import polars as pl
10
+ from polars import col
11
+
12
+ id2tagcat = {
13
+ 0: "general",
14
+ 1: "artist",
15
+ 3: "copyright",
16
+ 4: "character",
17
+ 5: "species",
18
+ 6: "invalid",
19
+ 7: "meta",
20
+ 8: "lore",
21
+ }
22
+ tagcat2id = {v: k for k, v in id2tagcat.items()}
23
+
24
+
25
+ def load_tags(data_dir):
26
+ data_dir = Path(data_dir)
27
+ with gzip.open(data_dir / "tags.txt.gz", 'rt') as fd:
28
+ idx2tag = fd.read().split("\n")
29
+ if not idx2tag[-1]:
30
+ idx2tag = idx2tag[:-1]
31
+ with gzip.open(data_dir / "tag2idx.json.gz", "rb") as fp:
32
+ tag2idx = json.load(fp)
33
+ return tag2idx, idx2tag
34
+
35
+
36
+ def filter_tag_list(column, vocab_size):
37
+
38
+ return col(column).list.eval(pl.element().filter(pl.element() < vocab_size))
39
+
40
+
41
+ def tags_to_csr(df_posts, column="stripped_tags"):
42
+ from polars import col
43
+
44
+ indices = df_posts[column].explode().drop_nulls().to_numpy()
45
+ indptr = df_posts.select(
46
+ offset=col(column).list.len().cum_sum().shift(1, fill_value=0)
47
+ )["offset"].to_numpy()
48
+ return indices, indptr
49
+
50
+
51
+ def tags_to_scipy_csr(df_posts, column="stripped_tags", vocab_size=None):
52
+ indices, indptr = tags_to_csr(df_posts, column=column)
53
+ indptr = np.r_[indptr, len(indices)]
54
+ R = scipy.sparse.csr_array(
55
+ (np.ones(indices.shape[0], dtype=np.uint8), indices, indptr),
56
+ shape=(len(df_posts), vocab_size or indices.max() + 1),
57
+ )
58
+ return R
59
+
60
+
61
+ def tags_to_tensors(df_posts, column="stripped_tags", device=None, dtype=torch.int32):
62
+ indices, indptr = tags_to_csr(df_posts, column=column)
63
+ tags = torch.tensor(indices, dtype=dtype, device=device)
64
+ offsets = torch.tensor(indptr, dtype=dtype, device=device)
65
+ return tags, offsets
notebooks/E6LocalMap.ipynb CHANGED
The diff for this file is too large to render. See raw diff