Datasets:
Update README.md
Browse files
README.md
CHANGED
|
@@ -7,8 +7,12 @@ language:
|
|
| 7 |
---
|
| 8 |
|
| 9 |
```
|
|
|
|
|
|
|
|
|
|
| 10 |
import pandas as pd
|
| 11 |
from datasets import load_dataset
|
|
|
|
| 12 |
|
| 13 |
dataset_name_list = [
|
| 14 |
"mteb/sts12-sts",
|
|
@@ -35,6 +39,29 @@ for dataset_name, datasetDict in dataset_dict.items():
|
|
| 35 |
df_list.append(df)
|
| 36 |
df = pd.concat(df_list, axis=0)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
df['text_sim'] = df.apply(lambda row :int(text_sim(row['sentence1'].lower(), row['sentence2'].lower()) * 100 + 0.5) / 100, axis=1)
|
| 40 |
df['fuzz_sim'] = df.apply(lambda row :fuzz.ratio(row['sentence1'].lower(), row['sentence2'].lower()) / 100, axis=1)
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
```
|
| 10 |
+
! pip install python-Levenshtein
|
| 11 |
+
! pip install fuzzywuzzy
|
| 12 |
+
|
| 13 |
import pandas as pd
|
| 14 |
from datasets import load_dataset
|
| 15 |
+
from fuzzywuzzy import fuzz
|
| 16 |
|
| 17 |
dataset_name_list = [
|
| 18 |
"mteb/sts12-sts",
|
|
|
|
| 39 |
df_list.append(df)
|
| 40 |
df = pd.concat(df_list, axis=0)
|
| 41 |
|
| 42 |
+
def text_sim(sent0, sent1):
|
| 43 |
+
is_str = False
|
| 44 |
+
if isinstance(sent0, str):
|
| 45 |
+
sent0 = [sent0]
|
| 46 |
+
sent1 = [sent1]
|
| 47 |
+
is_str = True
|
| 48 |
+
scores = []
|
| 49 |
+
for s1, s2 in zip(sent0, sent1):
|
| 50 |
+
set1 = set(s1.split(' '))
|
| 51 |
+
# print(set1)
|
| 52 |
+
set2 = set(s2.split(' '))
|
| 53 |
+
# print(set2)
|
| 54 |
+
# 计算交集和并集
|
| 55 |
+
intersection = set1.intersection(set2)
|
| 56 |
+
union = set1.union(set2)
|
| 57 |
+
|
| 58 |
+
# 计算雅可比相似度
|
| 59 |
+
similarity = len(intersection) / len(union)
|
| 60 |
+
|
| 61 |
+
scores.append(similarity )
|
| 62 |
+
return scores[0] if is_str else scores
|
| 63 |
+
|
| 64 |
+
print(text_sim('hello', 'hello world'))
|
| 65 |
|
| 66 |
df['text_sim'] = df.apply(lambda row :int(text_sim(row['sentence1'].lower(), row['sentence2'].lower()) * 100 + 0.5) / 100, axis=1)
|
| 67 |
df['fuzz_sim'] = df.apply(lambda row :fuzz.ratio(row['sentence1'].lower(), row['sentence2'].lower()) / 100, axis=1)
|