File size: 397 Bytes
2ce7015
c915c94
325e69e
 
 
 
 
2ce7015
c915c94
 
 
2ce7015
325e69e
b337b8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#import rapidfuzz

import pandas as pd
from sentence_transformers import SentenceTransformer
cmp_model = SentenceTransformer('uer/sbert-base-chinese-nli')

def compare(text0, text1):
    '''
    val = rapidfuzz.fuzz.ratio(text0, text1)
    if val >= 75:
        return val
    '''
    embeddings = cmp_model.encode([text0, text1])
    return int(pd.DataFrame(embeddings.T).corr().iloc[0, 1] * 100)