{"id":13754380,"url":"https://github.com/425776024/nlpcda","last_synced_at":"2026-10-19T11:07:40.774Z","repository":{"id":37652410,"uuid":"230702807","full_name":"425776024/nlpcda","owner":"425776024","description":"一键中文数据增强包 ； NLP数据增强、bert数据增强、EDA：pip install nlpcda","archived":false,"fork":false,"pushed_at":"2025-03-18T08:26:13.000Z","size":1105,"stargazers_count":1875,"open_issues_count":23,"forks_count":170,"subscribers_count":7,"default_branch":"master","last_synced_at":"2026-10-18T00:34:51.705Z","etag":null,"topics":["chinese-data-augmentation","chinese-eda","data-augmentation","nlp","nlpcda"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/425776024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-12-29T04:33:10.000Z","updated_at":"2026-09-18T09:35:07.000Z","dependencies_parsed_at":"2022-07-14T09:22:33.405Z","dependency_job_id":"b257f1ac-74dc-4360-b981-3b7bda38360d","html_url":"https://github.com/425776024/nlpcda","commit_stats":{"total_commits":70,"total_committers":4,"mean_commits":17.5,"dds":"0.12857142857142856","last_synced_commit":"da96d1ef2d94e43dbc110a1eadb097f535312bb6"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/425776024/nlpcda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/425776024%2Fnlpcda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/425776024%2Fnlpcda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/425776024%2Fnlpcda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/425776024%2Fnlpcda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/425776024","download_url":"https://codeload.github.com/425776024/nlpcda/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/425776024%2Fnlpcda/sbom","scorecard":{"id":3913,"data":{"date":"2025-08-11","repo":{"name":"github.com/425776024/nlpcda","commit":"2a130d3ae9c1cc76cdc538c623f9f26932e26bf1"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.1,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 2/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2021-856 / GHSA-5545-2q6w-2gh6","Warn: Project is vulnerable to: GHSA-6p56-wp2h-9hxr","Warn: Project is vulnerable to: PYSEC-2021-857 / GHSA-f7c7-j99h-c22f","Warn: Project is vulnerable to: GHSA-fpfv-jqm9-f5jm","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-9wx4-h78v-vm56","Warn: Project is vulnerable to: PYSEC-2023-74 / GHSA-j8r2-6x86-q33q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-14T13:08:42.841Z","repository_id":37652410,"created_at":"2025-08-14T13:08:42.841Z","updated_at":"2025-08-14T13:08:42.841Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38336266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-18T02:00:06.448Z","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":["chinese-data-augmentation","chinese-eda","data-augmentation","nlp","nlpcda"],"created_at":"2024-08-03T09:01:57.698Z","updated_at":"2026-10-19T11:07:40.745Z","avatar_url":"https://github.com/425776024.png","language":"Python","funding_links":[],"categories":["深度学习大类","Python"],"sub_categories":["数据集"],"readme":"# NLP Chinese Data Augmentation 一键中文数据增强工具\n\n使用：`pip install nlpcda`\n\n开源不易，欢迎 star🌟\n\npypi:https://pypi.org/project/nlpcda/\n\n---\n\n## 介绍\n\n一键中文数据增强工具，支持：\n- [1.随机实体替换](#1随机等价实体替换)\n- [2.近义词](#2随机同义词替换)\n- [3.近义近音字替换](#3随机近义字替换)\n- [4.随机字删除（内部细节：数字时间日期片段，内容不会删）](#4随机字删除)\n- [5.NER类 `BIO` 数据增强](#5ner命名实体-数据增强)\n- [6.随机置换邻近的字：**研表究明，汉字序顺并不定一影响文字的阅读理解**\u003c\u003c是乱序的](#6随机置换邻近的字)\n- [7.中文等价字替换（1\t一\t壹\t①，2\t二\t贰\t②）](#7等价字替换)\n- [8.翻译互转实现的增强](#8翻译互转实现的增强)\n- [9.使用`simbert`做生成式相似句生成](#9simbert)\n\n`经过细节特殊处理，比如不改变年月日数字，尽量保证不改变原文语义。即使改变也能被猜出来、能被猜出来、能被踩出来、能被菜粗来、被菜粗、能菜粗来`\n\n## WIP\n- 基于语音的洗文本过程（类似翻译）。`文本`转`语音`\u003e`语音`识别回`文本`：基于fastspeech2对文本生成语音，基于wav2vec2语音识别文本\n\u003e 例子：\n\u003e \n\u003e input: 新华社北京消息 \u003e `fastspeech2` \u003e x.wav\n\u003e \n\u003e x.wav \u003e `wav2vec2` \u003e output: 新华设北京消息\n\u003e \n\n- 数字转换工具（用于文本转换、中文语音合成需要纯中文）\n\u003e 今天是8月29日消息 \u003e 今天是八月二十九日消息\n\u003e \n\u003e 我有1234个苹果 \u003e 我有一千二百三十四个苹果\n\n## 意义\n- 在不改变原文语义的情况下，生成指定数量的训练语料文本\n- 对NLP模型的泛化性能、对抗攻击、干扰波动，有很好的提升作用\n- 参考比赛(本人用此策略+base bert拿到：50+-/1000)：https://www.biendata.net/competition/2019diac/\n- 基于nlpcda，本人[CCKS 2020：基于标题的大规模商品实体检索](https://www.biendata.net/competition/ccks_2020_6/final-leaderboard/)获得第9名，名字叫`nlpcda`\n\n\u003e ⚠️ 单纯刷准确率分数的比赛，用此包一般不会有分数提升\n\n\n\n---\n## API\n\n### 1.随机(等价)实体替换\n\n参数：\n- base_file ：缺省时使用内置（公司）实体。对公司实体进行替换\n    \u003e 是文本文件路径，内容形如：\\\n    \u003e 实体1\\\n    \u003e 实体2\\\n    \u003e ...\\\n    \u003e 实体n\n- create_num=3 ：返回最多3个增强文本\n- change_rate=0.3 ： 文本改变率\n- seed ： 随机种子\n\n```python\nfrom nlpcda import Randomword\n\ntest_str = '''这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击'''\n\nsmw = Randomword(create_num=3, change_rate=0.3)\nrs1 = smw.replace(test_str)\n\nprint('随机实体替换\u003e\u003e\u003e\u003e\u003e\u003e')\nfor s in rs1:\n    print(s)\n'''\n随机实体替换\u003e\u003e\u003e\u003e\u003e\u003e\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：长兴国际；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：浙江世宝；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n'''\n\n```\n\n### 2.随机同义词替换\n参数：\n- base_file ：缺省时使用内置同义词表，你可以设定/自己指定更加丰富的同义词表：\n    \u003e 是文本文件路径，内容形如（空格隔开）：\\\n    \u003e Aa01A0 人类 生人 全人类\\\n    \u003e id2 同义词b1 同义词b2 ... 同义词bk\\\n    \u003e ...\\\n    \u003e idn 同义词n1 同义词n2\\\n- create_num=3 ：返回最多3个增强文本\n- change_rate=0.3 ： 文本改变率\n- seed ： 随机种子\n\n```python\nfrom nlpcda import Similarword\n\ntest_str = '''这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击'''\n\nsmw = Similarword(create_num=3, change_rate=0.3)\nrs1 = smw.replace(test_str)\n\nprint('随机同义词替换\u003e\u003e\u003e\u003e\u003e\u003e')\nfor s in rs1:\n    print(s)\n\n'''\n随机同义词替换\u003e\u003e\u003e\u003e\u003e\u003e\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数量增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；斯nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n'''\n\n\n```\n\n### 3.随机近义字替换\n参数：\n- base_file ：缺省时使用内置【同义同音字表】，你可以设定/自己指定更加丰富的同义同音字表：\n    \u003e 是文本文件路径，内容形如（\\t隔开）：\\\n    \u003e de\t的\t地\t得\t德\t嘚\t徳\t锝\t脦\t悳\t淂\t鍀\t惪\t恴\t棏\\\n    \u003e 拼音2 字b1 字b2 ... 字bk\\\n    \u003e ...\\\n    \u003e 拼音n 字n1 字n2\\\n- create_num=3 ：返回最多3个增强文本\n- change_rate=0.3 ： 文本改变率\n- seed ： 随机种子\n```python\nfrom nlpcda import Homophone\n\ntest_str = '''这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击'''\n\nsmw = Homophone(create_num=3, change_rate=0.3)\nrs1 = smw.replace(test_str)\n\nprint('随机近义字替换\u003e\u003e\u003e\u003e\u003e\u003e')\nfor s in rs1:\n    print(s)\n\n'''\n随机近义字替换\u003e\u003e\u003e\u003e\u003e\u003e\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：58同城；今填是2020年3月8日11:40，天气晴朗，天气很不错，空气痕好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n鷓是个实体：58同乘；今天是2020年3月8日11:40，天迄晴朗，天气很不错，空气很儫，不差；这个nlpcad包，用于方便一键数据增强，犐有效增牆NLP模型的橎化性能、减少波动、抵抗对抗攻击\n'''\n\n```\n\n### 4.随机字删除\n参数：\n- create_num=3 ：返回最多3个增强文本\n- change_rate=0.3 ： 文本改变率\n- seed ： 随机种子\n```python\nfrom nlpcda import RandomDeleteChar\n\ntest_str = '''这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击'''\n\nsmw = RandomDeleteChar(create_num=3, change_rate=0.3)\nrs1 = smw.replace(test_str)\n\nprint('随机字删除\u003e\u003e\u003e\u003e\u003e\u003e')\nfor s in rs1:\n    print(s)\n\n'''\n随机字删除\u003e\u003e\u003e\u003e\u003e\u003e\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气，不差；这个nlpcad包用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗\n个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型泛化性能、减少波动、抵抗对抗\n'''\n\n```\n\n### 5.NER命名实体 数据增强\n输入标注好的NER数据目录，和需要增强的标注文件路径，和增强的数量，即可一键增强\n\nNer类参数：\n- ner_dir_name='ner_data' : 在ner数据放在ner_data目录下（里面很多.txt）\n- ner_dir_name提供的目录下是各种标注数据文件，文件内容以标准的NER 的BIO格式分开：\n\u003e 字1 \\t TAG\n\u003e\n\u003e 北 \\t B-LOC\n\u003e\n\u003e 京 \\t I-LOC\n\u003e\n\u003e 今 \\t O\n\u003e\n\u003e 天 \\t O\n\u003e\n\u003e 很 \\t O\n\u003e\n\u003e 热 \\t O\n\u003e\n\u003e 。 \\t O\n- ignore_tag_list=['O'] : 数据里面O标签的不需要管\n- data_augument_tag_list=['P', 'LOC'] : 只对P、LOC标签的实体做增强\n- augument_size=3 : 每条标注数据，最多新增强数量\n- seed=0 : 随机种子/ 可缺省\n\n调用函数augment()参数\n- file_name: 1条标注训练文件的路径，如0.txt\n- ner.augment(file_name='0.txt')\n\n例子：\n```python\nfrom nlpcda import Ner\n\nner = Ner(ner_dir_name='ner_data',\n        ignore_tag_list=['O'],\n        data_augument_tag_list=['P', 'LOC','ORG'],\n        augument_size=3, seed=0)\ndata_sentence_arrs, data_label_arrs = ner.augment(file_name='0.txt')\n# 3条增强后的句子、标签 数据，len(data_sentence_arrs)==3\n# 你可以写文件输出函数，用于写出，作为后续训练等\nprint(data_sentence_arrs, data_label_arrs)\n```\n\n### 6.随机置换邻近的字\n- char_gram=3：某个字只和邻近的3个字交换\n- 内部细节：遇到数字，符号等非中文，不会交换\n```python\nfrom nlpcda import CharPositionExchange\n\nts = '''这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击'''\nsmw = CharPositionExchange(create_num=3, change_rate=0.3,char_gram=3,seed=1)\nrs=smw.replace(ts)\nfor s in rs:\n    print(s)\n\n'''\n这是个实体：58同城；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，不差；这个nlpcad包，用于方便一键数据增强，可有效增强NLP模型的泛化性能、减少波动、抵抗对抗攻击\n这实个是体：58城同；今天是2020年3月8日11:40，天气晴朗，天气很不错，空气很好，差不；这个nlpcad包，便用一数方增键强据于，增有效可强NLP模型性泛化的能、动少减波、抵对攻抗抗击\n这是个体实：58城同；今是天2020年3月8日11:40，朗气晴天，天气很错不，空好很气，不差；个这nlpcad包，方便键一据增用数于强，可有效强增NLP模型的性化泛能、动减波少、抗抗击抵对攻\n'''\n\n```\n\n### 7.等价字替换\n参数：\n- base_file ：缺省时使用内置【等价数字字表】，你可以设定/自己指定更加丰富的等价字表(或者使用函数：add_equivalent_list)：\n    \u003e 是文本文件路径，内容形如（(\\t)隔开）：\\\n    \u003e 0\t零\t〇\\\n    \u003e 1\t一\t壹\t①\\\n    \u003e ...\\\n    \u003e 9\t九\t玖\t⑨\n- create_num=3 ：返回最多3个增强文本\n- change_rate=0.3 ： 文本改变率\n- seed ： 随机种子\n```python\nfrom nlpcda import EquivalentChar\n\ntest_str = '''今天是2020年3月8日11:40，天气晴朗，天气很不错。'''\n\ns = EquivalentChar(create_num=3, change_rate=0.3)\n# 添加等价字\ns.add_equivalent_list(['看', '瞅'])\nres=s.replace(test_str)\nprint('等价字替换\u003e\u003e\u003e\u003e\u003e\u003e')\nfor s in res:\n    print(s)\n\n'''\n等价字替换\u003e\u003e\u003e\u003e\u003e\u003e\n今天是2020年3月8日11:40，天气晴朗，天气很不错。\n今天是二〇2〇年3月八日1①:4〇，天气晴朗，天气很不错。\n今天是二0贰零年3月捌日11:40，天气晴朗，天气很不错\n'''\n\n```\n\n### 添加自定义词典\n用于使用之前，增加分词效果\n```python\nfrom nlpcda import Randomword\nfrom nlpcda import Similarword\nfrom nlpcda import Homophone\nfrom nlpcda import RandomDeleteChar\nfrom nlpcda import Ner\nfrom nlpcda import CharPositionExchange\n\nRandomword.add_word('小明')\nRandomword.add_words(['小明','小白','天地良心'])\n# Similarword，Homophone，RandomDeleteChar 同上\n\n```\n\n\n### 8.翻译互转实现的增强\n1.百度中英翻译互转实现的增强\nnote:\n\n\u003e 申请你的 appid、secretKey: http://api.fanyi.baidu.com/api/trans\n\u003e\n```python\nfrom nlpcda import baidu_translate\n\nzh = '天气晴朗，天气很不错，空气很好'\n# 申请你的 appid、secretKey\n# 两遍洗数据法（回来的中文一般和原来不一样，要是一样，就不要了，靠运气？）\nen_s = baidu_translate(content=zh, appid='xxx', secretKey='xxx',t_from='zh', t_to='en')\nzh_s = baidu_translate(content=en_s, appid='xxx', secretKey='xxx',t_from='en', t_to='zh')\nprint(zh_s)\n\n```\n\n2.谷歌翻译互转实现的增强\n\npip 包：[py-googletrans](https://py-googletrans.readthedocs.io/en/latest/)\n\n免费的谷歌翻译API，需要翻墙且不稳定\n\n[https://py-googletrans.readthedocs.io/en/latest](https://py-googletrans.readthedocs.io/en/latest)\n\npip install googletrans\n```python\nfrom googletrans import Translator\ndef googletrans(content='一个免费的谷歌翻译API', t_from='zh-cn', t_to='en'):\n    translator = Translator()\n    s = translator.translate(text=content, dest=t_to,src=t_from)\n    return s.text\n\n```\n\n\n\n### 9.simbert\n[来源：https://github.com/ZhuiyiTechnology/pretrained-models](https://github.com/ZhuiyiTechnology/pretrained-models)\n\n[参考：https://github.com/ZhuiyiTechnology/simbert](https://github.com/ZhuiyiTechnology/simbert)\n\n下载其中任意模型，解压到任意位置赋值给`model_path`变量：\n\n| 名称           | 训练数据大小 | 词表大小 | 模型大小 | 下载地址 |\n| :----------:  |:---------:| :------: | :------: | :------: |\n| SimBERT Tiny  | 2200万相似句组  | 13685   | 26MB   | [百度网盘](https://pan.baidu.com/s/1z_agqTuBTuyHANwrS-gPcg)(1tp7) |\n| SimBERT Small |  2200万相似句组 | 13685  | 49MB  | [百度网盘](https://pan.baidu.com/s/1kq_EQDI0gpiZBLFd_AxwrA)(nu67) |\n| SimBERT Base  |  2200万相似句组 | 13685  | 344MB | [百度网盘](https://pan.baidu.com/s/1uGfQmX1Kxcv_cXTVsvxTsQ)(6xhq) |\n\n参数：\n- config：model_path（上述下载的模型位置），设备（cpu/cuda...）、最大长度、随机种子\n- sent：需要增强的句子\n- create_num：构造的句子数量\n\n环境参考（手动安装）：\n```\n\nkeras==2.3.1\nbert4keras==0.7.7\n# tensorflow==1.13.1\ntensorflow-gpu==1.13.1\n\n```\n```python\nfrom nlpcda import Simbert\nconfig = {\n        'model_path': '/xxxx/chinese_simbert_L-12_H-768_A-12',\n        'CUDA_VISIBLE_DEVICES': '0,1',\n        'max_len': 32,\n        'seed': 1\n}\nsimbert = Simbert(config=config)\nsent = '把我的一个亿存银行安全吗'\nsynonyms = simbert.replace(sent=sent, create_num=5)\nprint(synonyms)\n'''\n[('我的一个亿，存银行，安全吗', 0.9871675372123718), \n('把一个亿存到银行里安全吗', 0.9352194666862488), \n('一个亿存银行安全吗', 0.9330801367759705), \n('一个亿的存款存银行安全吗', 0.92387855052948),\n ('我的一千万存到银行安不安全', 0.9014463424682617)]\n'''\n\n\n```\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=425776024/nlpcda\u0026type=Date)](https://www.star-history.com/#425776024/nlpcda\u0026Date)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F425776024%2Fnlpcda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F425776024%2Fnlpcda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F425776024%2Fnlpcda/lists"}