@@ -38,29 +38,30 @@ def compute_S_m(rewrite,quote):
38
38
try :
39
39
quote_index = rewrite .find (quote )
40
40
if quote_index != - 1 and quote_index != 0 :
41
- ppl = compute_ppl (rewrite [:quote_index + len (quote )],rewrite [quote_index + len (quote ):])
41
+ ppl = compute_ppl (rewrite [:quote_index + len (quote )],rewrite [quote_index + len (quote ):])
42
42
else :
43
- print ('Error : [Q] in the beginning or end of the query ' )
43
+ print ('指标位置在最开头或结尾 ' )
44
44
return 'nan'
45
- if ppl >= 50 :
46
- ppl = 50
47
- S_m = (1 - ppl / 50 )
45
+
46
+ S_m = safe_exp (0.053 * (ppl - 35.243 ))
47
+ print (ppl )
48
+ print ('语义匹配度S_m' , S_m )
48
49
return S_m
49
50
except Exception as e :
50
- print ('Error : Compute S_m :' , str (e ))
51
+ print ('计算语义匹配度出现问题 :' , str (e ))
51
52
ppl = 'nan'
52
53
return 'nan'
53
54
54
55
## Semantic Fluency(Compute the ppl of entire sentence)
55
56
def compute_S_f (rewrite ,quote ):
56
57
try :
57
58
ppl = compute_ppl ('' ,rewrite )
58
- if ppl >= 50 :
59
- ppl = 50
60
- S_f = ( 1 - ppl / 50 )
59
+ S_f = safe_exp ( 0.5 * ( ppl - 16.47 ))
60
+
61
+ print ( '语义流畅度S_f' , S_f )
61
62
return S_f
62
63
except Exception as e :
63
- print ('Error : Compute S_f ' , str (e ))
64
+ print ('计算语义流畅度出现问题: ' , str (e ))
64
65
ppl = 'nan'
65
66
return 'nan'
66
67
@@ -77,17 +78,22 @@ def compute_PPL_q(quote):
77
78
def compute_S_n (quote ):
78
79
try :
79
80
PPL_q = compute_PPL_q (quote )
80
- quote = quote .replace ('"' ,'' )
81
+ try :
82
+ quote = quote .replace ('"' ,'' )
83
+ except :
84
+ pass
85
+
81
86
if quote in Search_dict :
82
87
SearchFreq = Search_dict [quote ]
83
88
novelty = (PPL_q * 5 ) / math .log10 (SearchFreq )
84
- if novelty >= 20 :
85
- novelty = 20
86
- S_n = novelty / 20
89
+
90
+ exp_n = safe_exp ( - 0.253 * ( novelty - 10.67 ))
91
+ S_n = ( 1 / ( 1 + exp_n ))
87
92
print ('ppl' ,PPL_q ,'SearchFreq' ,SearchFreq )
93
+ print ('新颖度S_n' , S_n )
88
94
return S_n
89
95
except :
90
- print ('Error : Compute S_n ' )
96
+ print ('计算S_n出现问题 ' )
91
97
return 'nan'
92
98
93
99
0 commit comments