michael-0acf4 commited on
Commit
d263deb
·
1 Parent(s): a66dcf1

chore: readme

Browse files
Files changed (2) hide show
  1. README.md +31 -0
  2. pytorch/setup_params.json +12 -0
README.md CHANGED
@@ -1,3 +1,34 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ # AniTag2Vec
6
+
7
+ Training and inference examples are all available on [my github](https://github.com/michael-0acf4/anitag2vec).
8
+
9
+ Implementation is detailed in [this blog post](https://blog.afmichael.dev/posts/2026/set-embeddings-and-anitag2vec/).
10
+
11
+ ```python
12
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
+ cfg = SetupConfig.load_from_file("./pytorch/setup_params.json")
14
+ data, tagtok, anitag2vec = get_setup(
15
+ cfg,
16
+ device=device,
17
+ prefix_path= "."
18
+ )
19
+ # Load model
20
+ anitag2vec.load_state_dict(torch.load("./pytorch/anitag2vec_e15_s50000_p1871744.pth"))
21
+ anitag2vec.to(device)
22
+ anitag2vec.eval()
23
+ runner = AniTag2VecRunner(tagtok, anitag2vec)
24
+
25
+ # Inference
26
+ def compare(a: str, b: str):
27
+ ax = runner.run_inference_human([a])
28
+ bx = runner.run_inference_human([b])
29
+ howmuch = ((F.normalize(ax) @ F.normalize(bx).T).item())
30
+ print(f"{howmuch:.2f}: '{a}' vs '{b}'")
31
+
32
+ compare("#1girl #1boy", "#1boy #1girl")
33
+ # 1.00: '#1girl #1boy' vs '#1boy #1girl'
34
+ ```
pytorch/setup_params.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "TRAINING_TAKE_EXAMPLES": 50000,
3
+ "TRAINING_BATCH_SIZE": 256,
4
+ "HYPERP_TAGTOK_MAX_TOKEN_CLAMP": 128,
5
+ "HYPERP_TAGTOK_VOCAB_SIZE": 5000,
6
+ "HYPERP_TAGTOK_MIN_FREQ": 3,
7
+ "HYPERP_TRANSFORMER_D_MODEL": 128,
8
+ "HYPERP_TRANSFORMER_N_HEADS": 8,
9
+ "HYPERP_TRANSFORMER_N_LAYERS": 2,
10
+ "HYPERP_OUTPUT_EMB": 128,
11
+ "HYPERP_EPOCHS": 15
12
+ }