# TextBlob

**TextBlob** 是一个开源 Python 库，用于常见的自然语言处理任务，包括词性标注、名词短语提取、[情感分析](https://www.edgepedia.org/zh/sentiment-analysis)、分类、分词和拼写纠正，其接口设计得像 Python 字符串，并附带了文本处理能力。它由史蒂文·洛里亚编写和维护，采用 MIT 许可证，在 PyPI 上分发，文档托管在 textblob.readthedocs.io。<sup>[1](https://pypi.org/project/textblob/)</sup> 它的许多英语语言功能建立在自然语言工具包（NLTK）之上，后者的语料库必须单独下载，而其默认的情感和解析实现源自 pattern 库。<sup>[2](https://textblob.readthedocs.io/en/stable/api_reference.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 作者与许可证 | 史蒂文·洛里亚；MIT 许可证；PyPI 包 `textblob`，文档位于 textblob.readthedocs.io<sup>[1](https://pypi.org/project/textblob/)</sup> |
| 核心接口 | `TextBlob` 对象暴露 `tags`（词性）、`noun_phrases`、`words`、`sentences` 以及 `sentiment` 属性<sup>[3](https://textblob.readthedocs.io/en/dev/quickstart.html?highlight=sentiment+score)</sup> |
| 情感输出 | `sentiment` 属性返回一个形式为 `Sentiment(polarity, subjectivity)` 的命名元组<sup>[3](https://textblob.readthedocs.io/en/dev/quickstart.html?highlight=sentiment+score)</sup> |
| 情感分析器 | 默认 `PatternAnalyzer`（pattern 库实现）；替代方案 `NaiveBayesAnalyzer` 在电影评论语料库上训练<sup>[2](https://textblob.readthedocs.io/en/stable/api_reference.html)</sup> |
| 最新版本 | 0.20.1（2026 年 7 月 18 日）、0.20.0（2026 年 4 月 1 日）、0.19.0（2025 年 1 月 13 日）<sup>[1](https://pypi.org/project/textblob/)</sup> |
| 训练数据 | 默认的基于词典的分析器不需要标注训练数据；朴素贝叶斯分析器和分类器使用 NLTK 语料库<sup>[4](https://www.iieta.org/download/file/fid/168756)</sup><sup> • </sup><sup>[2](https://textblob.readthedocs.io/en/stable/api_reference.html)</sup> |
| 实测准确率 | 在 7,997 条推文的比较中为 73%，而 VADER 为 79%<sup>[5](https://jacta.utem.edu.my/jacta/article/view/5207)</sup> |

## 该库提供的功能

TextBlob 将文本处理操作封装在一个小型对象接口之后。一个 `TextBlob` 对象通过 `tags` 属性暴露词性标注，通过 `noun_phrases` 暴露名词短语，通过 `words` 和 `sentences` 暴露词级和句级分词。词级对象支持 WordNet 集成，具有 `synsets` 和 `definitions` 属性，并通过 `Word.lemma` 进行词形还原。<sup>[3](https://textblob.readthedocs.io/en/dev/quickstart.html?highlight=sentiment+score)</sup><sup> • </sup><sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup>

分词器建立在 [NLTK](https://www.edgepedia.org/zh/nltk) 之上：句子分词器是 NLTK 的 `PunktSentenceTokenizer`，它使用无监督算法对缩写、搭配和句首词进行建模，以找到句子边界。<sup>[2](https://textblob.readthedocs.io/en/stable/api_reference.html)</sup> 使用这些功能需要下载 NLTK 语料库，该库为此提供了一个辅助脚本。<sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup>

`textblob.classifiers` 模块添加了朴素贝叶斯、决策树和最大熵分类器，可以在 CSV、JSON 或 TSV 数据上训练和测试；`Blobber` 类创建共享已配置分词器、标注器和名词短语提取器的 TextBlob 对象。<sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup>

## 情感分析

情感分析是 TextBlob 最常用的功能。`sentiment` 属性返回 `Sentiment(polarity, subjectivity)`，其中极性衡量正面与负面倾向，主观性衡量文本的主观程度。<sup>[3](https://textblob.readthedocs.io/en/dev/quickstart.html?highlight=sentiment+score)</sup> 该库自带两种分析器实现。默认的 `PatternAnalyzer` 使用与 pattern 库相同的实现，返回极性和主观性，以及被评估词元及其各自分数的列表。替代方案 `NaiveBayesAnalyzer` 是在电影评论语料库上训练的分类器，返回带有正面和负面类别概率的分类结果。<sup>[2](https://textblob.readthedocs.io/en/stable/api_reference.html)</sup>

默认方法是基于词典的：它根据带有词性信息的预定义词典对单词进行评分，而不是从标注示例中学习。这意味着 TextBlob 不需要标注训练数据，这与机器学习情感技术不同。<sup>[4](https://www.iieta.org/download/file/fid/168756)</sup>

## 实测性能

比较研究一致认为，在非正式文本上，TextBlob 略逊于其最接近的竞争对手 VADER（Valence Aware Dictionary and sEntiment Reasoner）。在一项将两种词典应用于 7,997 条推文的研究中，两者都达到了可接受的准确率，VADER 为 79%，TextBlob 为 73%。<sup>[5](https://jacta.utem.edu.my/jacta/article/view/5207)</sup> 一项针对 3,309 篇自传体记忆书面叙述的研究，将两种工具与自我报告的效价进行比较，发现两种工具——尤其是 TextBlob——都表现出将记忆评为中性的偏差，并且 VADER 在两个数据集上产生的分类更加一致。当分类仅限于三种效价类型（负面、中性或正面）而非五种时，准确率提高到中等一致性（rMCC = .32），与其他工作中报告的人类编码者相当。<sup>[7](https://pubmed.ncbi.nlm.nih.gov/42241054/)</sup>

领域和语域很重要。TextBlob 在正式语言用法上效果更好，而其领域特定词汇覆盖有限，可能会给某些词赋予错误的分数，导致情感分数出现较大偏差。<sup>[8](https://pmc.ncbi.nlm.nih.gov/articles/PMC9910766/)</sup> 在一项针对两个科学资助机构同行评审报告的研究中，作者得出结论，TextBlob 和 VADER 不适合准确估计特定评审的绝对情感，但在比较评审组之间的相对情感时可能有帮助。<sup>[9](https://direct.mit.edu/qss/article/2/4/1271/107503/Analyzing-sentiments-in-peer-review-reports)</sup> 一项针对 COVID-19 推特数据的比较评估将 TextBlob 描述为利用基于词典的方法并结合词性标注，提供了简单性但领域特异性有限，并指出它在极性评分方面表现出优势，但存在过度泛化的问题。<sup>[10](https://doi.org/10.1007/s10791-026-09967-1)</sup>

## 局限性

由于 TextBlob 依赖预定义词典和基于规则的技术，它可能会遗漏上下文提供的含义。其情感分析有时会检查单个单词或短语而不考虑上下文，这可能会改变情感；文中列举的可能导致错误解释的例子包括习语、文化典故和讽刺。它也不包含使用上下文嵌入的高级深度学习模型，这与基于 Transformer 的方法（如 BERT）不同，后者会考虑单词周围的短语。<sup>[4](https://www.iieta.org/download/file/fid/168756)</sup>

《数字人文季刊》中的一项批判性代码研究分析认为，TextBlob 以及一般的情感分析将情感建模为程序化地潜伏在语言的最小粒子中，并且该库为服务于计算处理，抹去了其程序化和文本依赖网络的形式特异性。<sup>[11](https://www.researchgate.net/publication/402960727_Counting_Feeling_Affect_Theory_and_Sentiment_Analysis_in_TextBlob)</sup>

## 版本历史

TextBlob 在 2013 年迅速达到了现代形态：版本 0.5.0（2013 年 8 月）添加了带有 `PatternAnalyzer` 和 `NaiveBayesAnalyzer` 的 `text.sentiments` 模块、语言翻译和检测 API，以及 `polarity` 和 `subjectivity` 辅助属性；0.6.0（2013 年 8 月）添加了朴素贝叶斯分类、解析和拼写纠正；0.7.0（2013 年 9 月）添加了 WordNet 集成，并将英语特定代码移入 `text.en` 模块。<sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup>

后续版本紧随 Python 生态系统的发展。版本 0.16.0（2020 年 4 月）弃用了 `TextBlob.translate()` 和 `TextBlob.detect_language`，转而使用官方 Google Translate API，并在 Python 2 上将 NLTK 固定在 3.5 以下，因为 NLTK 3.5 放弃了对 Python 2 的支持，破坏了 TextBlob 在那里的语料库下载器。<sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup><sup> • </sup><sup>[12](https://github.com/sloria/TextBlob/issues/315)</sup> 版本 0.18.0（2024 年 2 月）完全移除了翻译和语言检测方法，放弃了对 3.8 之前 Python 版本的支持，并添加了对 nltk 3.8 及更高版本的支持；0.19.0（2025 年 1 月）支持 Python 3.9 到 3.13 以及 nltk 3.9 及更高版本；0.20.0（2026 年 4 月）支持 Python 3.10 到 3.14，并允许为 `.words` 自定义分词器。<sup>[6](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)</sup> 当前版本是 0.20.1，于 2026 年 7 月 18 日在 PyPI 上发布。<sup>[1](https://pypi.org/project/textblob/)</sup>

## References

1. [textblob · PyPI](https://pypi.org/project/textblob/)
2. [API Reference — TextBlob 0.19.0 documentation](https://textblob.readthedocs.io/en/stable/api_reference.html)
3. [Tutorial: Quickstart — TextBlob documentation](https://textblob.readthedocs.io/en/dev/quickstart.html?highlight=sentiment+score)
4. [IIETA file download (TextBlob limitations discussion)](https://www.iieta.org/download/file/fid/168756)
5. [Comparative Evaluation of Lexicons in Performing Sentiment Analysis, JACTA](https://jacta.utem.edu.my/jacta/article/view/5207)
6. [TextBlob/CHANGELOG.rst, GitHub](https://github.com/sloria/TextBlob/blob/dev/CHANGELOG.rst)
7. [Can computational sentiment analysis classify autobiographical memories? Comparing VADER and TextBlob, PubMed](https://pubmed.ncbi.nlm.nih.gov/42241054/)
8. [Sentiment analysis using Twitter data: a comparative application of lexicon- and machine-learning-based approach, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC9910766/)
9. [Analyzing sentiments in peer review reports: Evidence from two science funding agencies, Quantitative Science Studies](https://direct.mit.edu/qss/article/2/4/1271/107503/Analyzing-sentiments-in-peer-review-reports)
10. [Comparative evaluation of lexicon-based and transformer-based sentiment analysis tools, Discover Computing](https://doi.org/10.1007/s10791-026-09967-1)
11. [Jeffrey Moro, Counting Feeling: Affect Theory and Sentiment Analysis in TextBlob, Digital Humanities Quarterly 20(1), 2026](https://www.researchgate.net/publication/402960727_Counting_Feeling_Affect_Theory_and_Sentiment_Analysis_in_TextBlob)
12. [Issue #315: python -m textblob.download_corpora error on Python 2, GitHub](https://github.com/sloria/TextBlob/issues/315)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Natural language processing › NLP software, people, and community › NLP toolkits and libraries

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/textblob

English original: https://www.edgepedia.org/textblob
