一个用于使用spaCy从文本中计算各种特征的库
项目描述
TextDescriptives
TextDescriptives是一个Python库,用于使用spaCy v.3管道组件和扩展从文本中计算大量度量。
🔧 安装
pip安装textdescriptives
📰 新闻
- 现在我们有了由TextDescriptives驱动的web-app,您无需编写任何代码即可提取和下载指标!去看看这里
- 2.0版本推出,包括新的API、新的组件、更新的文档和教程!组件现在称为"
textdescriptives/{metric_name}
”。新增了coherence
组件,用于计算句子之间的语义连贯性。请参阅文档以获取教程和更多信息!
⚡ 快速开始
使用extract_metrics
快速提取您想要的指标。要查看可用方法,您只需运行
import textdescriptives as td
td.get_valid_metrics()
# {'quality', 'readability', 'all', 'descriptive_stats', 'dependency_distance', 'pos_proportions', 'information_theory', 'coherence'}
将spacy_model
参数设置为指定要使用的spaCy模型,否则,TextDescriptives将根据lang
自动下载一个合适的模型。如果设置了lang
,则不需要spacy_model
,反之亦然。
在metrics
参数中指定要提取的指标。None
提取所有指标。
import textdescriptives as td
text = "The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air. Much that once was is lost, for none now live who remember it."
# will automatically download the relevant model (´en_core_web_lg´) and extract all metrics
df = td.extract_metrics(text=text, lang="en", metrics=None)
# specify spaCy model and which metrics to extract
df = td.extract_metrics(text=text, spacy_model="en_core_web_lg", metrics=["readability", "coherence"])
与spaCy的用法
要与其他spaCy管道集成,导入库并使用标准spaCy语法将组件添加到您的管道中。可用的组件包括带有前缀textdescriptives/
的descriptive_stats、readability、dependency_distance、pos_proportions、coherence和quality。
如果您想添加所有组件,可以使用简写textdescriptives/all
。
import spacy
import textdescriptives as td
# load your favourite spacy model (remember to install it first using e.g. `python -m spacy download en_core_web_sm`)
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("textdescriptives/all")
doc = nlp("The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air. Much that once was is lost, for none now live who remember it.")
# access some of the values
doc._.readability
doc._.token_length
TextDescriptives包括从Doc
提取指标到Pandas DataFrame或字典的便利函数。
td.extract_dict(doc)
td.extract_df(doc)
文本 | 第一级连贯性 | 第二级连贯性 | pos_prop_DET | pos_prop_NOUN | pos_prop_AUX | pos_prop_VERB | pos_prop_PUNCT | pos_prop_PRON | pos_prop_ADP | pos_prop_ADV | pos_prop_SCONJ | flesch_reading_ease | flesch_kincaid_grade | smog | gunning_fog | automated_readability_index | coleman_liau_index | lix | rix | n_stop_words | alpha_ratio | mean_word_length | doc_length | proportion_ellipsis | proportion_bullet_points | duplicate_line_chr_fraction | duplicate_paragraph_chr_fraction | duplicate_5-gram_chr_fraction | duplicate_6-gram_chr_fraction | duplicate_7-gram_chr_fraction | duplicate_8-gram_chr_fraction | duplicate_9-gram_chr_fraction | duplicate_10-gram_chr_fraction | top_2-gram_chr_fraction | top_3-gram_chr_fraction | top_4-gram_chr_fraction | symbol_#_to_word_ratio | contains_lorem ipsum | passed_quality_check | dependency_distance_mean | dependency_distance_std | prop_adjacent_dependency_relation_mean | prop_adjacent_dependency_relation_std | token_length_mean | token_length_median | token_length_std | sentence_length_mean | sentence_length_median | sentence_length_std | syllables_per_token_mean | syllables_per_token_median | syllables_per_token_std | n_tokens | n_unique_tokens | proportion_unique_tokens | n_characters | n_sentences | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 世界已经改变(...) | 0.633002 | 0.573323 | 0.097561 | 0.121951 | 0.0731707 | 0.170732 | 0.146341 | 0.195122 | 0.0731707 | 0.0731707 | 0.0487805 | 107.879 | -0.0485714 | 5.68392 | 3.94286 | -2.45429 | -0.708571 | 12.7143 | 0.4 | 24 | 0.853659 | 2.95122 | 41 | 0 | 0 | 0 | 0 | 0.232258 | 0.232258 | 0 | 0 | 0 | 0 | 0.0580645 | 0.174194 | 0 | 0 | False | False | 1.77524 | 0.553188 | 0.457143 | 0.0722806 | 3.28571 | 3 | 1.54127 | 7 | 6 | 3.09839 | 1.08571 | 1 | 0.368117 | 35 | 23 | 0.657143 | 121 | 5 |
📖 文档
TextDescriptives拥有详细的文档以及一系列Jupyter笔记本教程。所有教程都位于docs/tutorials
文件夹中,也可以在文档网站上找到。
文档 | |
---|---|
📚 入门 | 有关如何使用TextDescriptives及其功能的指南和说明。 |
👩💻 演示 | TextDescriptives的实时演示。 |
😎 教程 | 如何充分利用TextDescriptives的详细教程。 |
📰 新闻和更新日志 | 新功能、更改和版本历史。 |
🎛 API参考 | TextDescriptive的API的详细参考。包括功能文档 |
📄 论文 | TextDescriptives论文的预印本。 |
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
textdescriptives-2.8.2.tar.gz (1.4 MB 查看哈希值)
构建分布
textdescriptives-2.8.2-py3-none-any.whl (254.3 kB 查看哈希值)
关闭
textdescriptives-2.8.2.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e6fccc8dc7a08eeb98171e11e3ce3ee015c75107ab4c887a58334fbc1b47fd59 |
|
MD5 | ff3a9999a7a3dbecf3ad00933a4eecdb |
|
BLAKE2b-256 | 549a874d218b703bc8c93b52ec81d82865cba607717d291fb4676cda3bd93a06 |
关闭
textdescriptives-2.8.2-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 262095cf1be93fce0626a8c09f6815ed6225b67196d2f6d1df576acb6b5828de |
|
MD5 | f147624b3422ab13f40d2f5862038af1 |
|
BLAKE2b-256 | b5ff943bfa1bee5e19b957adef2753a9985d791b50d2ef69cc93ce8a600c40f2 |