update
This commit is contained in:
56
scripts/debug_detailcase.py
Normal file
56
scripts/debug_detailcase.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
from schemas.dataset import QueryData
|
||||
from schemas.stream import StreamDataModel
|
||||
from utils.evaluator_plus import evaluate_editops
|
||||
|
||||
|
||||
def main(detailcase_file: str):
|
||||
with open(detailcase_file) as f:
|
||||
d = json.load(f)[0]
|
||||
preds = d["preds"]
|
||||
preds = list(map(lambda x: StreamDataModel(**x), preds))
|
||||
preds = list(filter(lambda x: x.final_result, preds))
|
||||
label = d["label"]
|
||||
label = QueryData(**label)
|
||||
print(evaluate_editops(label, preds))
|
||||
|
||||
|
||||
def evaluate_from_record(detailcase_file: str, record_path: str):
|
||||
with open(detailcase_file) as f:
|
||||
d = json.load(f)[0]
|
||||
label = d["label"]
|
||||
label = QueryData(**label)
|
||||
with open(record_path) as f:
|
||||
record = json.load(f)
|
||||
tokens_pred = record["tokens_pred"]
|
||||
tokens_label = record["tokens_label"]
|
||||
recognition_results = record["recognition_results"]
|
||||
recognition_results = list(
|
||||
map(lambda x: StreamDataModel(**x), recognition_results)
|
||||
)
|
||||
a, b = [], []
|
||||
for i, rr in enumerate(recognition_results):
|
||||
if rr.final_result:
|
||||
a.append(tokens_pred[i])
|
||||
b.append(rr)
|
||||
tokens_pred = a
|
||||
recognition_results = b
|
||||
|
||||
print(
|
||||
evaluate_editops(
|
||||
label,
|
||||
recognition_results,
|
||||
tokens_pred,
|
||||
tokens_label,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("请指定 detailcase 文件路径")
|
||||
sys.exit(1)
|
||||
main(sys.argv[1])
|
||||
# evaluate_from_record(sys.argv[1], sys.argv[2])
|
||||
Reference in New Issue
Block a user