返回顶部
s

simple-csc简易CSC

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
101
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

simple-csc

简单中文拼写纠正

一种无需训练的中文拼写纠正方法,利用大型语言模型作为纯语言模型,结合束搜索和失真建模。

前置条件

本技能是simple-csc仓库的使用指南。在使用本文描述的任何命令或API之前,请先克隆该仓库并在其根目录下操作:

bash
git clone https://github.com/Jacob-Zhou/simple-csc.git
cd simple-csc

以下所有路径引用(例如configs/、scripts/、data/、eval/、datasets/)均相对于该仓库根目录。该仓库包含实际代码、配置文件、数据字典和脚本——本技能提供如何使用它们的知识。

快速参考

环境设置

bash

标准设置(创建虚拟环境,安装依赖)


bash scripts/set_environment.sh

针对Qwen3模型

bash scripts/setenvironmentqwen3.sh

推荐:安装flash-attn以获得更好的性能和更低的显存占用

pip install flash-attn --no-build-isolation

Qwen2/Qwen2.5警告:如果没有flash-attn,请设置torch_dtype=torch.bfloat16以避免意外行为。

Python API

python
import torch
from lmcsc import LMCorrector

corrector = LMCorrector(
model=Qwen/Qwen2.5-7B,
prompted_model=Qwen/Qwen2.5-7B, # 使用相同模型以节省显存
configpath=configs/c2ecconfig.yaml, # 或使用configs/default_config.yaml仅进行替换
torch_dtype=torch.bfloat16, # 针对没有flash-attn的Qwen2/2.5推荐使用
)

单句

outputs = corrector(完善农产品上行发展机智。)

=> [(完善农产品上行发展机制。,)]

批量处理

outputs = corrector([句子一, 句子二])

带上下文(相同长度的列表)

outputs = corrector([未挨前兆], contexts=[患者提问:])

流式处理(仅支持batch_size=1)

for output in corrector(完善农产品上行发展机智。, stream=True): print(output[0][0], end=\r, flush=True)

配置选择

配置使用场景
configs/defaultconfig.yaml仅替换的中文拼写纠正(v1.0.0风格)
configs/c2ecconfig.yaml
支持插入/删除的完整C2EC(v2.0.0) | | configs/democonfig.yaml | 与c2ecconfig相同,供演示应用使用 |

主要区别:c2ecconfig.yaml包含ROR(重排序)、MIS(缺失字符)、RED(冗余字符)失真类型以及lengthimmutable_chars数据文件。

推荐模型

  • - v2.0.0(C2EC):Qwen/Qwen2.5-7B或Qwen/Qwen2.5-14B——最佳性能/速度平衡
  • v1.0.0(CSC):baichuan-inc/Baichuan2-13B-Base——最佳性能
  • 始终优先选择Base模型而非Instruct/Chat变体

RESTful API服务器

bash
python api_server.py \
--model Qwen/Qwen2.5-7B \
--prompted_model Qwen/Qwen2.5-7B \
--configpath configs/c2ecconfig.yaml \
--host 127.0.0.1 --port 8000 --workers 1 --bf16

端点:

  • - GET /health — 健康检查
  • POST /correction — {input: ..., stream: false, contexts: null}

bash

非流式


curl -X POST http://127.0.0.1:8000/correction \
-H Content-Type: application/json \
-d {input: 完善农产品上行发展机智。}

带上下文

curl -X POST http://127.0.0.1:8000/correction \ -H Content-Type: application/json \ -d {input: 未挨前兆, contexts: 患者提问:}

有关详细的API参数、配置选项、评估流程和数据集格式,请参见references/details.md

关键架构概念

该方法的工作原理是:

  1. 1. 将大型语言模型用作纯语言模型(从左到右生成)
  2. 在每一步,根据每个候选词元与观察到的(可能错误的)字符的相似度计算其失真概率
  3. 通过束搜索将语言模型概率与失真概率相结合
  4. 失真类型编码了观察字符与候选字符之间的关系(相同、同音、形近等)

prompted_model参数增加了第二个概率来源:一个基于提示的大型语言模型,在给定完整输入句子作为上下文的情况下对候选词元进行评分,从而提高纠正质量。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 simple-csc-1776122382 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 simple-csc-1776122382 技能

通过命令行安装

skillhub install simple-csc-1776122382

下载

⬇ 下载 simple-csc v1.0.1(免费)

文件大小: 7.61 KB | 发布时间: 2026-4-14 13:11

v1.0.1 最新 2026-4-14 13:11
Version 1.0.1 of simple-csc

- Added explicit compatibility and prerequisite instructions, including GPU, Python version, and VRAM requirements.
- Clarified that this skill is a usage guide and that the simple-csc repository must be cloned locally before use.
- Noted that all file paths are relative to the repository root, improving user guidance.
- No changes to features, APIs, or behavior were made; this is a documentation update for improved clarity and onboarding.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部