English 简体中文 繁體中文 한국 사람 日本語 Deutsch русский بالعربية TÜRKÇE português คนไทย french
查看: 0|回复: 0

开源最强中文纠错大模型,超越华为17个点!

[复制链接]
查看: 0|回复: 0

开源最强中文纠错大模型,超越华为17个点!

[复制链接]
查看: 0|回复: 0

220

主题

0

回帖

670

积分

高级会员

积分
670
0sSe1Ah

220

主题

0

回帖

670

积分

高级会员

积分
670
3 天前 | 显示全部楼层 |阅读模式
​项目地址:GitHub - TW-NLP/ChineseErrorCorrector: 中文拼写错误和语法错误纠正
 

文本纠错任务在审查、写作任务中至关重要,以前的纠错大多采用小模型进行训练,例如BART、T5、BERT等,但是小模型的泛化性较差,需要在不同领域训练不同的小模型进行纠错,为此我们使用200万数据进行大模型的训练,经过验证我们在GitHub - masr2000/NaCGEC数据集上,F1值比华为高10个点,遥遥领先,下面从三个方面进行详细的技术说明:数据集(涵盖业界所有的开源数据)、评估结果、使用方法,欢迎star,后续会持续更新纠错模型。
 
1、数据集

数据集名称数据链接数据量和类别说明描述CSC(拼写纠错数据集)twnlp/csc_dataW271K:279,816 条,Medical:39,303 条,Lemon:22,259 条,ECSpell:6,688 条,CSCD:35,001 条中文拼写纠错的数据集CGC(语法纠错数据集)twnlp/cgc_dataCGED:20449 条,FCGEC:37354 条,MuCGEC:2467 条,NaSGEC:7568条中文语法纠错的数据集Lang8+HSK(百万语料-拼写和语法错误混合数据集)twnlp/lang8_hsk1568885条中文拼写和语法数据集项目包含三个部分的数据集,分别为CSC、CGC和Lang8+HSK,涵盖了所有开源高质量的拼写纠错和语法纠错的数据集,也是我们分阶段训练的数据。
2、评估结果

Model NameModel LinkPrecRecF0.5twnlp/ChineseErrorCorrector2-7Bhttps://huggingface.co/twnlp/ChineseErrorCorrector2-7B0.62330.62280.6232HW_TSC_nlpcc2023_cgec(华为)未开源0.50950.31290.4526鱼饼啾啾Plus未开源0.57080.12940.3394CUHK_SU未开源0.38820.15580.2990CGEC++未开源0.24140.07350.1657zhao_jia未开源0.17190.14780.1665我们在NaCGEC数据集上,比最高的华为要高17个点,实测效果也很不错,强力推荐!

3、使用方法


transformers

通过 transformers 库,您可以方便地加载和使用中文拼写纠错模型:
# 安装 transformers 库pip install transformers
 

以下是使用模型进行拼写纠错的代码示例:
# pip install transformersfrom transformers import AutoModelForCausalLM, AutoTokenizercheckpoint = "twnlp/ChineseErrorCorrector2-7B"device = "cuda" # for GPU usage or "cpu" for CPU usagetokenizer = AutoTokenizer.from_pretrained(checkpoint)model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)input_content = "你是一个文本纠错专家,纠正输入句子中的语法错误,并输出正确的句子,输入句子为:\n少先队员因该为老人让坐。"messages = [{"role": "user", "content": input_content}]input_text=tokenizer.apply_chat_template(messages, tokenize=False)print(input_text)inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)outputs = model.generate(inputs, max_new_tokens=1024, temperature=0, do_sample=False, repetition_penalty=1)print(tokenizer.decode(outputs[0]))
 

VLLM

使用 VLLM 进行推理,支持快速高效地生成文本:
# 安装 VLLMpip install vllm
 

以下是 VLLM 示例代码:
from transformers import AutoTokenizerfrom vllm import LLM, SamplingParams# Initialize the tokenizertokenizer = AutoTokenizer.from_pretrained("twnlp/ChineseErrorCorrector2-7B")# Pass the default decoding hyperparameters of twnlp/ChineseErrorCorrector-7B# max_tokens is for the maximum length for generation.sampling_params = SamplingParams(seed=42, max_tokens=512)# Input the model name or path. Can be GPTQ or AWQ models.llm = LLM(model="twnlp/ChineseErrorCorrector2-7B")# Prepare your promptsprompt = "少先队员因该为老人让坐。"messages = [    {"role": "user", "content": "你是一个文本纠错专家,纠正输入句子中的语法错误,并输出正确的句子,输入句子为:"+prompt}]text = tokenizer.apply_chat_template(    messages,    tokenize=False,    add_generation_prompt=True)# generate outputsoutputs = llm.generate([text], sampling_params)# Print the outputs.for output in outputs:    prompt = output.prompt    generated_text = output.outputs[0].text    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
 
 
总结

ChineseErrorCorrector 是一个强大的中文拼写和语法纠错工具,开箱即用,后面会不断的跟进前沿的纠错方法和数据,不断更新开源模型。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

220

主题

0

回帖

670

积分

高级会员

积分
670

QQ|智能设备 | 粤ICP备2024353841号-1

GMT+8, 2025-3-10 18:31 , Processed in 6.057337 second(s), 31 queries .

Powered by 智能设备

©2025

|网站地图