Skip to content

Commit

Permalink
update demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
shibing624 committed Dec 28, 2023
1 parent 99569ee commit c2135c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions examples/macbert/model_correction_pipeline_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@
'因为爸爸在看录音机,所以我没得看',
'不过在许多传统国家,女人向未得到平等',
'我想喝小明同学。', # 漏召回
'直接采用君主常用名,如赵昺。', # 人名误杀
]

model1 = MacBertCorrector()
# add confusion corrector for post process
confusion_dict = {"喝小明同学": "喝小茗同学", "老人让坐": "老人让座", "平净": "平静", "分知": "分支",
"赵昺": "赵昺"}
confusion_dict = {"喝小明同学": "喝小茗同学", "老人让坐": "老人让座", "平净": "平静", "分知": "分支"}
model2 = ConfusionCorrector(custom_confusion_path_or_dict=confusion_dict)
for line in error_sentences:
r1 = model1.correct(line)
correct_sent = r1['target']
print("query:{} => {} err:{}".format(line, correct_sent, r1['errors']))
r2 = model2.correct(line)
r2 = model2.correct(correct_sent)
corrected_sent2 = r2['target']
if corrected_sent2 != correct_sent:
print("update, query:{} => {} err:{}".format(line, corrected_sent2, r2['errors']))
print("update, query:{} => {} err:{}".format(correct_sent, corrected_sent2, r2['errors']))
2 changes: 1 addition & 1 deletion pycorrector/macbert/macbert_corrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, model_name_or_path="shibing624/macbert4csc-base-chinese"):
logger.debug("Use device: {}".format(device))
logger.debug('Loaded macbert4csc model: %s, spend: %.3f s.' % (model_name_or_path, time.time() - t1))

def _predict(self, sentences, threshold=0.75, batch_size=32, silent=True):
def _predict(self, sentences, threshold=0.7, batch_size=32, silent=True):
"""Predict sentences with macbert4csc model"""
corrected_sents = []
for batch in tqdm(
Expand Down

0 comments on commit c2135c4

Please sign in to comment.