diff --git a/models/match/dssm/run.sh b/models/match/dssm/run.sh index aab3b0f3b2b8f7b07fa36546d0fdc5d22ec72103..33c8979d4b8e90c0128602d9ad022877fd67e8ce 100644 --- a/models/match/dssm/run.sh +++ b/models/match/dssm/run.sh @@ -13,11 +13,7 @@ # limitations under the License. #!/bin/bash echo "................run................." -python -m paddlerec.run -m ./config.yaml &> result1.txt -grep -i "query_doc_sim" ./result1.txt >./result2.txt -sed '$d' result2.txt >result.txt -rm -f result1.txt -rm -f result2.txt +python -m paddlerec.run -m ./config.yaml &> result.txt python transform.py sort -t $'\t' -k1,1 -k 2nr,2 pair.txt >result.txt rm -f pair.txt diff --git a/models/match/dssm/transform.py b/models/match/dssm/transform.py index 42e35d9552e04f75d06f141c3456b844bac764f9..0c69673e46e7232f816ca4ed7e3db28c032b6a4e 100644 --- a/models/match/dssm/transform.py +++ b/models/match/dssm/transform.py @@ -16,6 +16,20 @@ import random import numpy as np import sklearn.metrics +filename = './result.txt' +f = open(filename, "r") +lines = f.readlines() +f.close() +result = [] +for line in lines: + if "query_doc_sim" in str(line): + result.append(line) +result = result[:-1] +f = open(filename, "w") +for i in range(len(result)): + f.write(str(result[i])) +f.close() + label = [] filename = './data/label.txt' f = open(filename, "r") diff --git a/models/match/match-pyramid/eval.py b/models/match/match-pyramid/eval.py index c3eccdb681faa1f5bb893007fd597cbf6de836ce..72922e5a62b481793a51564927dd2183c03ecd98 100644 --- a/models/match/match-pyramid/eval.py +++ b/models/match/match-pyramid/eval.py @@ -32,6 +32,20 @@ def eval_MAP(pred, gt): return map_value / r +filename = './result.txt' +f = open(filename, "r") +lines = f.readlines() +f.close() +result = [] +for line in lines: + if "prediction" in str(line): + result.append(line) +result = result[:-1] +f = open(filename, "w") +for i in range(len(result)): + f.write(str(result[i])) +f.close() + filename = './data/relation.test.fold1.txt' gt = [] qid = [] @@ -56,7 +70,7 @@ for line in open(filename): pred.append(float(line)) result_dict = {} -for i in range(len(qid)): +for i in range(len(pred)): if qid[i] not in result_dict: result_dict[qid[i]] = [] result_dict[qid[i]].append([gt[i], pred[i]]) diff --git a/models/match/match-pyramid/run.sh b/models/match/match-pyramid/run.sh index ad9f5216065570f623d5eaa751dfc29562062741..d0778308cf7141e2fa73121335ef631ce3837dce 100644 --- a/models/match/match-pyramid/run.sh +++ b/models/match/match-pyramid/run.sh @@ -1,8 +1,4 @@ #!/bin/bash echo "................run................." -python -m paddlerec.run -m ./config.yaml &>result1.txt -grep -i "prediction" ./result1.txt >./result2.txt -sed '$d' result2.txt >result.txt -rm -f result2.txt -rm -f result1.txt +python -m paddlerec.run -m ./config.yaml &>result.txt python eval.py diff --git a/models/match/multiview-simnet/run.sh b/models/match/multiview-simnet/run.sh index 4efbe6b9a989e7a560b6a70d2a32b0beb69ed8d2..e3a70a71f7938c6db705aebe9c332132b71a9351 100644 --- a/models/match/multiview-simnet/run.sh +++ b/models/match/multiview-simnet/run.sh @@ -14,12 +14,8 @@ #!/bin/bash echo "................run................." -python -m paddlerec.run -m ./config.yaml &>result1.txt -grep -i "query_pt_sim" ./result1.txt >./result2.txt -sed '$d' result2.txt >result.txt -rm -f result1.txt -rm -f result2.txt +python -m paddlerec.run -m ./config.yaml &>result.txt python transform.py -sort -t $'\t' -k1,1 -k 2nr,2 pair.txt >result.txt +sort -t $'\t' -k1,1 -k 2nr,2 pair.txt &>result.txt rm -f pair.txt python ../../../tools/cal_pos_neg.py result.txt diff --git a/models/match/multiview-simnet/transform.py b/models/match/multiview-simnet/transform.py index 7246b2d0ccc4e3e2b78a04ba6fb48a7d3ae6bdcb..89710f0fffa4c50aef90989d7ee0aba4d7d22f13 100644 --- a/models/match/multiview-simnet/transform.py +++ b/models/match/multiview-simnet/transform.py @@ -15,6 +15,20 @@ import random import numpy as np +filename = './result.txt' +f = open(filename, "r") +lines = f.readlines() +f.close() +result = [] +for line in lines: + if "query_pt_sim" in str(line): + result.append(line) +result = result[:-1] +f = open(filename, "w") +for i in range(len(result)): + f.write(str(result[i])) +f.close() + label = [] filename = './data/label.txt' f = open(filename, "r") @@ -31,7 +45,7 @@ filename = './result.txt' sim = [] for line in open(filename): line = line.strip().split(",") - print(line) + #print(line) line[3] = line[3].split(":") line = line[3][1].strip(" ") line = line.strip("[") @@ -50,6 +64,6 @@ f.close() filename = 'pair.txt' f = open(filename, "w") for i in range(len(sim)): - print(i) + #print(i) f.write(str(query[i]) + "\t" + str(sim[i]) + "\t" + str(label[i]) + "\n") f.close()