{"id":23692438,"url":"https://github.com/cementzhang/csanmt-translation","last_synced_at":"2026-02-16T11:08:05.469Z","repository":{"id":269502883,"uuid":"907262979","full_name":"CementZhang/CSANMT-Translation","owner":"CementZhang","description":"基于CSANMT模型的翻译服务,支持多语言互译;tensorflow,nvidia-gpu推理应用; 使用了python的fastapi框架. 小而美的翻译应用","archived":false,"fork":false,"pushed_at":"2024-12-24T03:43:26.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-02T20:46:28.259Z","etag":null,"topics":["csanmt","fastapi","model","python","tensorflow","translation","translation-model"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CementZhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-23T07:37:40.000Z","updated_at":"2025-03-19T02:55:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1dc93b3-ac28-4eec-9449-74f414b3bff5","html_url":"https://github.com/CementZhang/CSANMT-Translation","commit_stats":null,"previous_names":["cementzhang/csanmt-translation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CementZhang/CSANMT-Translation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CementZhang%2FCSANMT-Translation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CementZhang%2FCSANMT-Translation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CementZhang%2FCSANMT-Translation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CementZhang%2FCSANMT-Translation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CementZhang","download_url":"https://codeload.github.com/CementZhang/CSANMT-Translation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CementZhang%2FCSANMT-Translation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278366664,"owners_count":25975095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csanmt","fastapi","model","python","tensorflow","translation","translation-model"],"created_at":"2024-12-30T03:27:50.209Z","updated_at":"2025-10-04T20:07:29.867Z","avatar_url":"https://github.com/CementZhang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nCSANMT-Translation为翻译的模型服务; 项目基于**TensorFlow**框架**CSANMT**系列(Modelscope平台)的模型翻译项目; 目前支持中文到英文的翻译，英文到中文的翻译,其他模型可以到[Modelscope](https://modelscope.cn/models)下载即可. 也可以作为**FastApi**入门项目使用. 对性能有要求可以看章节性能部分参数;\n本项目基于pyhton的fastapi框架开发. 代码简洁,可以直接部署作为翻译的原子(微服务)服务使用投入到生成. 特色:\n- 模型预加载 - 减少首次推理时间\n- 超长文本推理 - 内置切分、断句逻辑\n- API封装 - 基于FastApi开箱即用,调用方式参考[API调用章节]( #API调用)\n\n\u003cdiv align=\"center\"\u003e  \n\u003ch4\u003e\n \u003ca href=\"#安装教程\"\u003e 安装教程 \u003c/a\u003e   \n｜\u003ca href=\"#训练\"\u003e 训练 \u003c/a\u003e\n｜\u003ca href=\"#性能\"\u003e 性能 \u003c/a\u003e\n｜\u003ca href=\"#配置及缓存\"\u003e 配置及缓存 \u003c/a\u003e\n\u003c/h4\u003e\n\u003c/div\u003e\n\n\u003ca name=\"安装教程\"\u003e\u003c/a\u003e\n## 安装教程\n- 部署最简单的方式是使用docker-compose部署, 支持了GPU, CPU\n- MPS, 其他Mac/Win平台开发调试,Clone本项目后直接requirments.txt安装依赖\n\n### Docker部署\n  - 1、在本地主机上安装最新版本的 Docker,自带了Compose版本。\n  - 2、如需在 Linux 上启用 GPU推理，请安装显卡[NVIDIA的驱动](https://github.com/NVIDIA/nvidia-docker/wiki/Frequently-Asked-Questions#how-do-i-install-the-nvidia-driver) 以及 [NVIDIA Docker](https://github.com/NVIDIA/nvidia-docker) 支持\n  以上都可以参考[TensorFlow](https://www.tensorflow.org/install/docker?hl=zh-cn)官网文档。\n  - 3、修改模型、日志挂载目录等配置,具体可以参考docker-compose.yml文件;\n  - 4、运行 docker-compose.yml\n      ```bash\n      docker compose up -d --build\n      ```\n    \n  - 5、镜像 \u0026\u0026 核心的组件\n    - 镜像:tensorflow/tensorflow:2.18.0-gpu,需要其他镜像可以到dockerhub上自行更新/更换;如果更新/更换镜像注意涉及相应pip依赖保持更新.以下为镜像里核心组件的版本号,你也可以自行到官方镜像具体查询.\n      - CUDA_VERSION=12.3.0\n      - PYTHON_VERSION=python3.11\n      - TENSORFLOW_PACKAGE=tensorflow==2.18.0\n  \n    - python包核心依赖:\n      - torch_tensorrt==2.2.0 (linux的GPU必须依赖; 这个在modelscope平台里没有具体说明的核心)\n      - modelscope==1.21.0\n      - datasets==2.18.0\n      - sacremoses==0.1.1\n      - subword_nmt==0.3.8\n        其他依赖在requirements.txt中\n### 本地开发部署\n- 要求**python\u003e3.10**; 直接pip install -r requirements.txt后启动即可\n    ```bash\n    pip install --default-timeout=600 -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt\n    ```\n### 更换模型\n- 目前预置为modelscope的两个模型.路径在tanslation.translation.ModelEnum.model_path; 自行更换即可\n\n    ```bash\n       class ModelEnum(Enum):\n           ZH2EN = ModelConfig(model_path=\"damo/nlp_csanmt_translation_zh2en\", preload_infer_text=\"你好\",\n                               split_pattern=r\"[。！？；]\")\n           EN2ZH = ModelConfig(model_path=\"damo/nlp_csanmt_translation_en2zh\", preload_infer_text=\"hello\",\n                               split_pattern=r\"[.!?;,]\")\n    ```\n\n### API调用\n- 启动后,默认端口为11000,可以通过修改docker-compose.yml中的ports参数来修改端口;\n \n例子:中文 =》英文\n```bash \ncurl --location '127.0.0.1:11000/translation' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"text\":\"沉睡数千年, 一醒惊天下. 你好欢迎来到三星堆博物馆.\",\n    \"source_lang\":\"zh\",\n    \"target_lang\":\"en\"\n}'\n```\n将的到如下结果:\n\n```json\n{\n    \"errorcode\": 0,\n    \"ret\": 0,\n    \"msg\": \"ok\",\n    \"traceid\": \"\",\n    \"data\": \"Sleeping for thousands of years, waking up to shock the world. Hello and welcome to Sanxingdui Museum.\"\n}\n```\n\n例子:英文=》中文\n\n```bash \ncurl --location '127.0.0.1:11000/translation' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"text\":\"Sleeping for thousands of years, waking up to shock the world. Hello and welcome to Sanxingdui Museum.\",\n    \"source_lang\":\"en\",\n    \"target_lang\":\"zh\"\n}'\n ```\n返回结果:\n```json\n{\n    \"errorcode\": 0,\n    \"ret\": 0,\n    \"msg\": \"ok\",\n    \"traceid\": \"\",\n    \"data\": \"睡了几千年，醒来震惊世界。大家好，欢迎来到三星堆博物馆。\"\n}\n```\n\n\n\n\u003ca name=\"训练\"\u003e\u003c/a\u003e\n## 训练\n- 模型微调/训练,请参考官方[Modelscope](https://www.modelscope.cn/models/iic/nlp_csanmt_translation_zh2en)文档\n\n\u003ca name=\"性能\"\u003e\u003c/a\u003e\n## 性能\n- 模型大小: large-7GB\n- 各平台推理性能测试:\n\n| 设备                        | 推理速度 (ms)-10个字(中文)/单词(英文) | 推理速度(ms)-20个字(中文)/单词(英文) |\n|-----------------------------|---------------------------|--------------------------|\n| **CPU (8C/16G)**            | 2000 ~ 3000 ms            | 3000 ~ 4000 ms           |\n| **RTX-4090 / Tesla-P40 / RTX-3060Ti** | 100 ~ 200 ms              | 200 ~ 400 ms             |\n| **MPS**                     | 100 ~ 200 ms              | 200 ~ 400 ms             |\n\n 通过多个GPU来测试, 对于**单次**推理速度基本都差不多. 如果有负载好的显卡对于承载会更高;\n\n\u003ca name=\"配置及缓存\"\u003e\u003c/a\u003e\n## 配置及缓存：\n- 模型缓存目录: ~/.cache/modelscope/hub/下; 通过挂载到主机,主机目录可以docker-compose.yml修改\n- 日志目录: /app/logs下;通过挂载到主机,主机目录可以docker-compose.yml修改\n\n## 许可协议\n项目遵循[The MIT License](https://opensource.org/licenses/MIT)开源协议，模型许可协议请参考（[模型协议](./MODEL_LICENSE)）\n\n## 引用\n\n``` bibtex\n@inproceedings{wei-etal-2022-learning,\n  title = {Learning to Generalize to More: Continuous Semantic Augmentation for Neural Machine Translation},\n  author = {Xiangpeng Wei and Heng Yu and Yue Hu and Rongxiang Weng and Weihua Luo and Rong Jin},\n  booktitle = {Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, ACL 2022},\n  year = {2022},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcementzhang%2Fcsanmt-translation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcementzhang%2Fcsanmt-translation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcementzhang%2Fcsanmt-translation/lists"}