File size: 702 Bytes
eb90fa0
 
 
 
ace78e8
eb90fa0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b86962d
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from sentence_transformers import SentenceTransformer


encoder = SentenceTransformer("../model/")

tags = []
f = open('tags.txt', 'r')
for line in f.readlines():
    tags.append(line.strip())
f.close()

tags_embed = encoder.encode(tags)
tags_dis = [np.sqrt(np.dot(_, _.T)) for _ in tags_embed]

print(tags_embed.shape, tags_dis.shape)

with open('./tags_embed.npy', 'wb') as f:
    np.save(f, tags_embed)

with open('./tags_dis.npy', 'wb') as f:
    np.save(f, tags_dis)

# f = open('gpttag.txt', 'r')
# data = eval(f.readline())
# f.close()
#
# out = ""
# f = open('tags.txt', 'w')
# for tmp in data:
#     if tmp[1] > 2:
#         out += tmp[0] + '\n'
#
# f.write(out)
# f.close()