Update main.py
Browse files
main.py
CHANGED
|
@@ -6,13 +6,12 @@ import torch
|
|
| 6 |
|
| 7 |
torch.cuda.is_available()
|
| 8 |
|
| 9 |
-
# 1. Türkçe destekli güçlü bir Sentence Transformer modeli yüklüyoruz
|
| 10 |
# (Bu model cümleleri anlamsal vektörlere dönüştürür)
|
| 11 |
model_name = "paraphrase-multilingual-mpnet-base-v2"
|
| 12 |
print("Model yükleniyor...")
|
| 13 |
model = SentenceTransformer(model_name)
|
| 14 |
|
| 15 |
-
|
| 16 |
data = [
|
| 17 |
{"sentence1": "Sabahları erkenden kalkıp yürüyüş yapmayı çok severdi.", "sentence2": "Gözleri ekrana kilitlenmişti, karakterlerle birlikte replikleri mırıldanıyordu.", "humanScore": 12.51},
|
| 18 |
{"sentence1": "Hava bugün çok yağmurlu.", "sentence2": "Bugün dışarıda şiddetli yağış var.", "humanScore": 86.74},
|
|
@@ -68,12 +67,12 @@ data = [
|
|
| 68 |
|
| 69 |
df = pd.DataFrame(data)
|
| 70 |
|
| 71 |
-
#
|
| 72 |
print("Vektörler hesaplanıyor...")
|
| 73 |
embeddings1 = model.encode(df['sentence1'].tolist(), convert_to_tensor=True)
|
| 74 |
embeddings2 = model.encode(df['sentence2'].tolist(), convert_to_tensor=True)
|
| 75 |
|
| 76 |
-
#
|
| 77 |
cos_scores = []
|
| 78 |
cos_scores_norm = []
|
| 79 |
for i in range(len(df)):
|
|
@@ -91,7 +90,7 @@ for i in range(len(df)):
|
|
| 91 |
cos_scores.append(score_100)
|
| 92 |
cos_scores_norm.append(score_0_1)
|
| 93 |
|
| 94 |
-
#
|
| 95 |
df['CosScore'] = cos_scores
|
| 96 |
df['CosScoreNorm'] = cos_scores_norm
|
| 97 |
|
|
@@ -99,7 +98,7 @@ df['CosScoreNorm'] = cos_scores_norm
|
|
| 99 |
output_columns = ['sentence1', 'sentence2', 'humanScore', 'CosScore', 'CosScoreNorm']
|
| 100 |
df = df[output_columns]
|
| 101 |
|
| 102 |
-
csv_filename = "
|
| 103 |
df.to_csv(csv_filename, index=False, encoding='utf-8-sig')
|
| 104 |
|
| 105 |
print(f"İşlem tamamlandı! Veri seti '{csv_filename}' dosyasına kaydedildi.")
|
|
|
|
| 6 |
|
| 7 |
torch.cuda.is_available()
|
| 8 |
|
|
|
|
| 9 |
# (Bu model cümleleri anlamsal vektörlere dönüştürür)
|
| 10 |
model_name = "paraphrase-multilingual-mpnet-base-v2"
|
| 11 |
print("Model yükleniyor...")
|
| 12 |
model = SentenceTransformer(model_name)
|
| 13 |
|
| 14 |
+
|
| 15 |
data = [
|
| 16 |
{"sentence1": "Sabahları erkenden kalkıp yürüyüş yapmayı çok severdi.", "sentence2": "Gözleri ekrana kilitlenmişti, karakterlerle birlikte replikleri mırıldanıyordu.", "humanScore": 12.51},
|
| 17 |
{"sentence1": "Hava bugün çok yağmurlu.", "sentence2": "Bugün dışarıda şiddetli yağış var.", "humanScore": 86.74},
|
|
|
|
| 67 |
|
| 68 |
df = pd.DataFrame(data)
|
| 69 |
|
| 70 |
+
# Cümlelerin vektörlerini (Embedding) çıkarma
|
| 71 |
print("Vektörler hesaplanıyor...")
|
| 72 |
embeddings1 = model.encode(df['sentence1'].tolist(), convert_to_tensor=True)
|
| 73 |
embeddings2 = model.encode(df['sentence2'].tolist(), convert_to_tensor=True)
|
| 74 |
|
| 75 |
+
# Kosinüs Benzerliği Hesaplama (0-100 ve 0-1 Normalizasyonu)
|
| 76 |
cos_scores = []
|
| 77 |
cos_scores_norm = []
|
| 78 |
for i in range(len(df)):
|
|
|
|
| 90 |
cos_scores.append(score_100)
|
| 91 |
cos_scores_norm.append(score_0_1)
|
| 92 |
|
| 93 |
+
# Sonuçları dataframe'e ekleme
|
| 94 |
df['CosScore'] = cos_scores
|
| 95 |
df['CosScoreNorm'] = cos_scores_norm
|
| 96 |
|
|
|
|
| 98 |
output_columns = ['sentence1', 'sentence2', 'humanScore', 'CosScore', 'CosScoreNorm']
|
| 99 |
df = df[output_columns]
|
| 100 |
|
| 101 |
+
csv_filename = "STS.csv"
|
| 102 |
df.to_csv(csv_filename, index=False, encoding='utf-8-sig')
|
| 103 |
|
| 104 |
print(f"İşlem tamamlandı! Veri seti '{csv_filename}' dosyasına kaydedildi.")
|