Update README.md
Browse files
README.md
CHANGED
@@ -37,7 +37,7 @@ optimizer = AdamW(model.parameters(), lr=5e-5)
|
|
37 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
38 |
model.to(device)
|
39 |
|
40 |
-
for epoch in range(3):
|
41 |
model.train()
|
42 |
total_loss = 0
|
43 |
count = 0
|
@@ -53,11 +53,11 @@ for epoch in range(3): # 에포크 반복
|
|
53 |
positive_encodings = batch_to_device(positive_encodings, device)
|
54 |
negative_encodings = batch_to_device(negative_encodings, device)
|
55 |
|
56 |
-
|
57 |
-
anchor_output = model(**anchor_encodings)[0][:, 0, :]
|
58 |
positive_output = model(**positive_encodings)[0][:, 0, :]
|
59 |
negative_output = model(**negative_encodings)[0][:, 0, :]
|
60 |
-
|
61 |
if loss==None:
|
62 |
loss = triplet_loss(anchor_output, positive_output, negative_output)
|
63 |
else:
|
@@ -91,7 +91,6 @@ def evaluate(validation_dataset):
|
|
91 |
negative_embedding = get_embedding(item["Fake Title"], model, tokenizer)
|
92 |
|
93 |
|
94 |
-
# 쿼리와 모든 문서 간의 유사도 계산 (코사인 거리 사용)
|
95 |
positive_distances = pairwise_distances(query_embedding.detach().cpu().float().numpy(), document_embedding.detach().cpu().float().numpy(), metric="cosine")
|
96 |
negative_distances = pairwise_distances(query_embedding.detach().cpu().float().numpy(), negative_embedding.detach().cpu().float().numpy(), metric="cosine")
|
97 |
|
|
|
37 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
38 |
model.to(device)
|
39 |
|
40 |
+
for epoch in range(3):
|
41 |
model.train()
|
42 |
total_loss = 0
|
43 |
count = 0
|
|
|
53 |
positive_encodings = batch_to_device(positive_encodings, device)
|
54 |
negative_encodings = batch_to_device(negative_encodings, device)
|
55 |
|
56 |
+
|
57 |
+
anchor_output = model(**anchor_encodings)[0][:, 0, :]
|
58 |
positive_output = model(**positive_encodings)[0][:, 0, :]
|
59 |
negative_output = model(**negative_encodings)[0][:, 0, :]
|
60 |
+
|
61 |
if loss==None:
|
62 |
loss = triplet_loss(anchor_output, positive_output, negative_output)
|
63 |
else:
|
|
|
91 |
negative_embedding = get_embedding(item["Fake Title"], model, tokenizer)
|
92 |
|
93 |
|
|
|
94 |
positive_distances = pairwise_distances(query_embedding.detach().cpu().float().numpy(), document_embedding.detach().cpu().float().numpy(), metric="cosine")
|
95 |
negative_distances = pairwise_distances(query_embedding.detach().cpu().float().numpy(), negative_embedding.detach().cpu().float().numpy(), metric="cosine")
|
96 |
|