Spaces:
Running
Running
zhangxiyi.amos
commited on
Commit
·
94a6df5
1
Parent(s):
5f7d877
fix: 使用cpu获取codet5p嵌入表示
Browse files
app.py
CHANGED
@@ -39,7 +39,8 @@ def generate(query1, query2, source_code):
|
|
39 |
# 特殊处理 Salesforce/codet5p-110m-embedding 模型
|
40 |
inputs = tokenizer([query1, query2, source_code], padding=True, truncation=True, return_tensors="pt")
|
41 |
with torch.no_grad():
|
42 |
-
|
|
|
43 |
|
44 |
score1 = cos_sim(embeddings[0], embeddings[2])
|
45 |
score2 = cos_sim(embeddings[1], embeddings[2])
|
|
|
39 |
# 特殊处理 Salesforce/codet5p-110m-embedding 模型
|
40 |
inputs = tokenizer([query1, query2, source_code], padding=True, truncation=True, return_tensors="pt")
|
41 |
with torch.no_grad():
|
42 |
+
outputs = model6(**inputs)
|
43 |
+
embeddings = outputs.last_hidden_state[:, 0, :].cpu().numpy() # 使用 [CLS] token 的嵌入
|
44 |
|
45 |
score1 = cos_sim(embeddings[0], embeddings[2])
|
46 |
score2 = cos_sim(embeddings[1], embeddings[2])
|