返回资源列表

Datawhale(datawhalechina) · erenup(多多笔记) · 张帆 · 张贤 · 李泺秋 · 蔡杰 · hlzhang · 台运鹏 · 张红旭

基于transformers的自然语言处理(NLP)入门

跟着中文图文教程理解 Transformer/BERT/GPT 原理,并用 PyTorch 与 Hugging Face Transformers 动手完成常见 NLP 任务的实现与训练。

打开官方课程
难度
入门
形式
实践教程
语言
zh
规模
21 个课节
内容费用
免费
动手
需要动手环境

使用限制

阅读教程只需浏览器;跑通代码需自备 Python/PyTorch 环境,并可能用到 GPU。

学习材料
可访问 GitHub 或 GitHub Pages 在线阅读教程
练习与作业
如需实际训练模型,训练任务可能依赖 GPU;网页未说明具体要求
  1. 选择学习环境

    按你的电脑系统准备;提示词在你自己的电脑上使用。

    本机动手

    这是 Datawhale 的中文 NLP/Transformer 入门开源教程,包含原理图解与多个动手实践篇章,建议按篇章 1→4 顺序学习。

    需要一台可运行 Python 的电脑(本地或在线环境),能安装 requirements.txt 中的依赖;如需 GPU 训练,网页未说明具体要求。

  2. 准备工具和账号

    标“选用”的可以跳过。

    运行费用:实践可能产生费用,教程含配套代码与运行环境配置说明,动手跑通可能需要本地环境或 GPU,具体成本原站未说明。

  3. 让 AI Agent 一次搭好课程

    复制开课提示词发给你常用的 AI Agent。它会下载允许保存的官方材料、建立课节目录并自检;需要账号、权限或费用时会先问你。

    开课提示词 · 只需用一次此提示词尚未实测验证
    请帮我把「基于transformers的自然语言处理(NLP)入门」的学习环境一次准备好,让我之后只需要按顺序学习和做练习。
    开始前先问我:课程放在哪个目录(等我给出完整路径),确认我的操作系统和已有工具。确认前不要创建文件或安装软件。
    
    课程入口:https://github.com/datawhalechina/learn-nlp-with-transformers
    我的系统:Windows。如果实际不符,先调整方案。
    本次路线:Windows:本机动手。只准备这条路线需要的工具;只读路线不安装运行环境、不配置模型密钥。
    练习:读完每个篇章后做对应“篇章小测”,并在篇章 4 中实际运行文本分类、序列标注、问答、翻译、摘要等任务脚本,把结果与教程示例对照。
    课节(官方顺序):
    1. 1.0-本地阅读和代码运行环境配置:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A01-%E5%89%8D%E8%A8%80/1.0-%E6%9C%AC%E5%9C%B0%E9%98%85%E8%AF%BB%E5%92%8C%E4%BB%A3%E7%A0%81%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE.md
    2. 1.1-Transformers在NLP中的兴起:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A01-%E5%89%8D%E8%A8%80/1.1-Transformers%E5%9C%A8NLP%E4%B8%AD%E7%9A%84%E5%85%B4%E8%B5%B7.md
    3. 2.1-图解attention:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.1-%E5%9B%BE%E8%A7%A3attention.md
    4. 2.2-图解transformer:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.2-%E5%9B%BE%E8%A7%A3transformer.md
    5. 2.2.1-Pytorch编写Transformer:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.2.1-Pytorch%E7%BC%96%E5%86%99Transformer.md
    6. 2.2.2-Pytorch编写Transformer-选读:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.2.1-Pytorch%E7%BC%96%E5%86%99Transformer-%E9%80%89%E8%AF%BB.md
    7. 2.3-图解BERT:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.3-%E5%9B%BE%E8%A7%A3BERT.md
    8. 2.4-图解GPT:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.4-%E5%9B%BE%E8%A7%A3GPT.md
    9. 2.5-篇章小测:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A02-Transformer%E7%9B%B8%E5%85%B3%E5%8E%9F%E7%90%86/2.5-%E7%AF%87%E7%AB%A0%E5%B0%8F%E6%B5%8B.md
    10. 3.1-如何实现一个BERT:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A03-%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AATransformer%E6%A8%A1%E5%9E%8B%EF%BC%9ABERT/3.1-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AABERT.md
    11. 3.2-如何应用一个BERT:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A03-%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AATransformer%E6%A8%A1%E5%9E%8B%EF%BC%9ABERT/3.2-%E5%A6%82%E4%BD%95%E5%BA%94%E7%94%A8%E4%B8%80%E4%B8%AABERT.md
    12. 3.3-篇章小测:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A03-%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AATransformer%E6%A8%A1%E5%9E%8B%EF%BC%9ABERT/3.3-%E7%AF%87%E7%AB%A0%E5%B0%8F%E6%B5%8B.md
    13. 4.0-前言:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.0-%E5%89%8D%E8%A8%80.md
    14. 4.1-文本分类:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.1-%E6%96%87%E6%9C%AC%E5%88%86%E7%B1%BB.md
    15. 4.2-序列标注:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.2-%E5%BA%8F%E5%88%97%E6%A0%87%E6%B3%A8.md
    16. 4.3-问答任务-抽取式问答:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.3-%E9%97%AE%E7%AD%94%E4%BB%BB%E5%8A%A1-%E6%8A%BD%E5%8F%96%E5%BC%8F%E9%97%AE%E7%AD%94.md
    17. 4.4-问答任务-多选问答:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.4-%E9%97%AE%E7%AD%94%E4%BB%BB%E5%8A%A1-%E5%A4%9A%E9%80%89%E9%97%AE%E7%AD%94.md
    18. 4.5-生成任务-语言模型:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.5-%E7%94%9F%E6%88%90%E4%BB%BB%E5%8A%A1-%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B.md
    19. 4.6-生成任务-机器翻译:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.6-%E7%94%9F%E6%88%90%E4%BB%BB%E5%8A%A1-%E6%9C%BA%E5%99%A8%E7%BF%BB%E8%AF%91.md
    20. 4.7-生成任务-摘要生成:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.7-%E7%94%9F%E6%88%90%E4%BB%BB%E5%8A%A1-%E6%91%98%E8%A6%81%E7%94%9F%E6%88%90.md
    21. 4.8-篇章小测:https://github.com/datawhalechina/learn-nlp-with-transformers/blob/main/docs/%E7%AF%87%E7%AB%A04-%E4%BD%BF%E7%94%A8Transformers%E8%A7%A3%E5%86%B3NLP%E4%BB%BB%E5%8A%A1/4.8-%E7%AF%87%E7%AB%A0%E5%B0%8F%E6%B5%8B.md
    
    1. 环境
    - Python 3
    - PyTorch
    - Hugging Face transformers(依赖见 requirements.txt)
    - 可选的 GPU 训练环境
    - 安装前先列出要装的软件和命令,等我同意;已装好的直接复用。
    2. 材料
    - 官方课程页面:只记录链接 https://github.com/datawhalechina/learn-nlp-with-transformers
    3. 目录(最外层放在我确认的位置)
    learn-nlp-with-transformers/
    ├── README.md        # 课程入口、课节清单、每次怎么开始
    ├── progress.md      # 每课:读讲义 / 做练习 / 记笔记
    ├── questions.md     # 待解决的问题
    ├── check-env.ps1     # 环境自检,按 README 操作
    ├── data/            # 练习用到的样例数据
    └── lessons/         # 每课一个文件夹:notes.md + exercises/
        ├── 01-01-1-0/
        ├── 02-02-1-1-transformers-nlp/
        ├── 03-03-2-1-attention/
        ├── 04-04-2-2-transformer/
        ├── 05-05-2-2-1-pytorch-transformer/
        ├── 06-06-2-2-2-pytorch-transformer/
        ├── 07-07-2-3-bert/
        ├── 08-08-2-4-gpt/
        ├── 09-09-2-5/
        ├── 10-10-3-1-bert/
        ├── 11-11-3-2-bert/
        ├── 12-12-3-3/
        ├── 13-13-4-0/
        ├── 14-14-4-1/
        ├── 15-15-4-2/
        ├── 16-16-4-3/
        ├── 17-17-4-4/
        ├── 18-18-4-5/
        ├── 19-19-4-6/
        ├── 20-20-4-7/
        └── 21-21-4-8/
    - 每课文件夹里建 notes.md(顶部写本课官方链接)和 exercises/;课节文件夹名称与上面一致。
    - 已有课程目录先检查并复用;不覆盖笔记、作业或 progress.md,不重置已有进度。尚未发布的课节保留入口并注明未发布,不能代写讲义或虚构练习。
    4. 自检
    - 创建 check-env.ps1,逐项检查并记录“通过/未通过”:
    - 在课程根目录运行;每项检查独立执行,进入子目录不能影响下一项。将下面检查转换为 PowerShell 命令,不使用 Bash 语法。
      - python -c "import torch, transformers; print(torch.__version__, transformers.__version__)"  → 正常输出版本号,无 ImportError
      - 打开 https://datawhalechina.github.io/learn-nlp-with-transformers 确认能访问教程正文  → 页面显示篇章 1–4 的教程目录与内容
    - 标注为人工检查、浏览器操作或 notebook 单元的项目,按相应方式操作,不直接粘贴进 shell;脚本只包含当前系统可执行的命令。
    - 仅在当前路线需要、对应材料已获准保存、工具已安装时运行该项;需要登录、付费或尚未开放的材料记为“需要我操作/未验证”,不能伪报通过。不执行会调用付费 API、提交作业或修改云服务的检查。
    - 运行一次,把结果给我看;未通过的项目说明原因和修复办法。
    5. 学习计划
    - README.md:课程入口、课节清单(带链接)、每次学习怎么开始(使用“每课提示词”)。
    - progress.md:每课三项勾选——读讲义、做练习、记笔记。
    6. 最后分三部分汇报:已完成、需要我自己操作的、尚未验证的。
    
    边界:
    - 需要管理员权限、会产生费用或需要填写密钥的操作,先告诉我原因,等我同意。密钥由我在本机配置,不发到聊天,不写进笔记或版本库;原项目需要 .env 时确认已被 Git 忽略。
    - 不替我写练习或作业答案,也不替我提交。我卡住时只给提示;我明确要求时才给解答。
    - 只下载许可允许个人保存的材料;其余只放链接。不把未运行的命令说成成功。
    如果你不能直接操作我的文件系统,请在确认目录后给出适用于我的系统、可直接执行的命令和需要保存的文件内容。
    搭好后的课程目录
    learn-nlp-with-transformers/
    ├── README.md        # 课程入口、课节清单、每次怎么开始
    ├── progress.md      # 每课:读讲义 / 做练习 / 记笔记
    ├── questions.md     # 待解决的问题
    ├── check-env.ps1     # 环境自检,按 README 操作
    ├── data/            # 练习用到的样例数据
    └── lessons/         # 每课一个文件夹:notes.md + exercises/
        ├── 01-01-1-0/
        ├── 02-02-1-1-transformers-nlp/
        ├── 03-03-2-1-attention/
        ├── 04-04-2-2-transformer/
        ├── 05-05-2-2-1-pytorch-transformer/
        ├── 06-06-2-2-2-pytorch-transformer/
        ├── 07-07-2-3-bert/
        ├── 08-08-2-4-gpt/
        ├── 09-09-2-5/
        ├── 10-10-3-1-bert/
        ├── 11-11-3-2-bert/
        ├── 12-12-3-3/
        ├── 13-13-4-0/
        ├── 14-14-4-1/
        ├── 15-15-4-2/
        ├── 16-16-4-3/
        ├── 17-17-4-4/
        ├── 18-18-4-5/
        ├── 19-19-4-6/
        ├── 20-20-4-7/
        └── 21-21-4-8/
准备好了,开始学习

来源与使用须知

收录时间
本站首次收录 2026-10-17
指南参考

版权与转载

  • 课程材料未标明许可:仅供个人学习,转载、修改或商用前请先联系原作者。
  • 本站只提供原始链接和学习指南,不转载、不镜像课程材料;引用时请注明原作者与出处。