Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

utils.py 876 B

You have to be logged in to leave a comment. Sign In
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
  1. import importlib
  2. import random
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from sklearn import decomposition as sk_dec
  6. from sklearn import preprocessing as sk_prep
  7. import torch
  8. def seed(value: int = 42):
  9. np.random.seed(value)
  10. torch.manual_seed(value)
  11. torch.cuda.manual_seed(value)
  12. random.seed(value)
  13. def plot_vectors(latent: torch.Tensor, labels: torch.Tensor):
  14. latent = sk_prep.normalize(X=latent, norm="l2")
  15. z2d = sk_dec.PCA(n_components=2).fit_transform(latent)
  16. fig, ax = plt.subplots(figsize=(10, 10))
  17. for y in labels.unique():
  18. ax.scatter(
  19. z2d[labels == y, 0], z2d[labels == y, 1],
  20. marker=".", label=y.item(),
  21. )
  22. fig.legend()
  23. return fig
  24. def load_cls_from_str(path):
  25. module, model = path.rsplit('.', maxsplit=1)
  26. return getattr(importlib.import_module(module), model)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...