Spacy V.3パイプラインコンポーネントと拡張機能を使用して、テキストから多種多様なメトリックを計算するためのPythonライブラリ。
pip install textdescriptives
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モデルを指定します。そうしないと、TextDescripivesは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構文を使用してコンポーネントをパイプラインに追加します。利用可能なコンポーネントは、 Decriptive_stats 、読みやすさ、依存関係、 POS_PROPORTIONS 、コヒーレンス、およびtextdescriptives/を付けた品質です。
すべてのコンポーネントを追加する場合は、速記の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 TextDescripiveには、 DocからPandasデータフレームまたは辞書にメトリックを抽出するための利便性関数が含まれています。
td . extract_dict ( doc )
td . extract_df ( doc )| 文章 | first_order_coherence | second_order_coherence | 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 | スモッグ | gunning_fog | Automated_readability_index | Coleman_liau_index | lix | リックス | n_stop_words | alpha_ratio | mean_word_length | doc_length | Propution_ellipsis | Propuent_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 | シンボル_#_ 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 | cente_length_mean | cente_length_median | cente_length_std | syllables_per_token_mean | syllables_per_token_median | syllables_per_token_std | n_tokens | n_unique_tokens | PRORSENT_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 | 間違い | 間違い | 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 |
TextDescripivesには、詳細なドキュメントと一連のJupyterノートブックのチュートリアルがあります。すべてのチュートリアルは、 docs/tutorialsフォルダーにあり、ドキュメントWebサイトにもあります。
| ドキュメント | |
|---|---|
| はじめる | TextDescriptivesとその機能の使用方法に関するガイドと指示。 |
| ? デモ | TextDescripiveのライブデモ。 |
| ?チュートリアル | テキスト設計を最大限に活用する方法に関する詳細なチュートリアル |
| ?ニュースとチェンジログ | 新しい追加、変更、バージョン履歴。 |
| ? API参照 | TextDescriptiveのAPIの詳細なリファレンス。関数ドキュメントを含む |
| ?紙 | TextDescripive Paperのプレプリント。 |