osiria commited on
Commit
5a35bf2
·
1 Parent(s): fbef3bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -53,12 +53,12 @@ def classify(text, classes, prompt = "L'argomento di cui parliamo è quindi: "):
53
 
54
  classes = {el.split(":")[0].strip(): el.split(":")[1].strip() for el in classes.split("\n")}
55
 
56
- t_vec = model_cl(tokenizer_cl.encode(text, return_tensors = "pt")).last_hidden_state[0,0,:].cpu().detach().numpy()
57
  t_vec = t_vec/np.linalg.norm(t_vec)
58
  t_vec = t_vec.reshape(-1, 1)
59
 
60
  classes_mod = [prompt + re.sub("\s+", " ", classes[cl].lower().replace(",", " ")).strip() for cl in classes]
61
- cl_vecs = np.array([model_cl(tokenizer_cl.encode(cl, return_tensors = "pt")).last_hidden_state[0,0,:].cpu().detach().numpy() for cl in classes_mod])
62
  cl_vecs = cl_vecs/np.sqrt(np.sum(cl_vecs**2, axis = 1).reshape(-1,1))
63
 
64
  scores = np.dot(cl_vecs, t_vec).reshape(1,-1)[0]
 
53
 
54
  classes = {el.split(":")[0].strip(): el.split(":")[1].strip() for el in classes.split("\n")}
55
 
56
+ t_vec = model_cl(tokenizer_cl.encode(text, return_tensors = "pt", truncation = True, max_length = 512)).last_hidden_state[0,0,:].cpu().detach().numpy()
57
  t_vec = t_vec/np.linalg.norm(t_vec)
58
  t_vec = t_vec.reshape(-1, 1)
59
 
60
  classes_mod = [prompt + re.sub("\s+", " ", classes[cl].lower().replace(",", " ")).strip() for cl in classes]
61
+ cl_vecs = np.array([model_cl(tokenizer_cl.encode(cl, return_tensors = "pt", truncation = True, max_length = 512)).last_hidden_state[0,0,:].cpu().detach().numpy() for cl in classes_mod])
62
  cl_vecs = cl_vecs/np.sqrt(np.sum(cl_vecs**2, axis = 1).reshape(-1,1))
63
 
64
  scores = np.dot(cl_vecs, t_vec).reshape(1,-1)[0]