Una biblioteca de Python para calcular una gran variedad de métricas de textos que utilizan componentes y extensiones de tubería Spacy V.3.
pip install textdescriptives
textdescriptives/{metric_name} . Nuevo componente coherence para calcular la coherencia semántica entre oraciones. ¡Vea la documentación para tutoriales y más información! Use extract_metrics para extraer rápidamente las métricas deseadas. Para ver los métodos disponibles, simplemente puede ejecutar:
import textdescriptives as td
td . get_valid_metrics ()
# {'quality', 'readability', 'all', 'descriptive_stats', 'dependency_distance', 'pos_proportions', 'information_theory', 'coherence'} Establezca el parámetro spacy_model para especificar qué modelo de Spacy usar, de lo contrario, TextDescriptives descargará automáticamente uno apropiado basado en lang . Si lang está configurado, spacy_model no es necesario y viceversa.
Especifique qué métricas extraer en el argumento metrics . None extrae todas las métricas.
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" ]) Para integrarse con otras tuberías de Spacy, importe la biblioteca y agregue los componentes a su tubería utilizando la sintaxis de Spacy estándar. Los componentes disponibles son descriptivos_stats , legibilidad , dependencia_distance , pos_proportions , coherencia y calidad con prefijo textdescriptives/ .
Si desea agregar todos los componentes, puede usar los 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 incluye funciones de conveniencia para extraer métricas de un Doc a un marco de datos PANDAS o un diccionario.
td . extract_dict ( doc )
td . extract_df ( doc )| texto | 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 | niebla tóxica | gunning_fog | automated_readability_index | coleman_liau_index | LIX | rix | n_stop_words | alpha_ratio | Mean_word_length | doc_length | proporción_ellipsis | proporción_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 | símbolo _#_ to_word_ratio | contiene_LOREM ipsum | pase_quality_check | dependencia_distance_mean | dependencia_distance_std | prop_adjacent_dependency_relation_mean | prop_adjacent_dependency_relation_std | token_length_mean | token_length_median | token_length_std | oración_length_mean | oración_length_median | oración_length_std | Syllables_per_token_mean | Syllables_per_token_median | Syllables_per_token_std | n_tokens | n_unique_tokens | proporción_unique_tokens | N_CARACTERS | n_sentencias | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | El mundo ha cambiado (...) | 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 | FALSO | FALSO | 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 tiene una documentación detallada, así como una serie de tutoriales del cuaderno Jupyter. Todos los tutoriales se encuentran en la carpeta docs/tutorials y también se pueden encontrar en el sitio web de documentación.
| Documentación | |
|---|---|
| Empezando | Guías e instrucciones sobre cómo usar TextDescriptives y sus características. |
| ? demostración | Una demostración en vivo de TextDescriptives. |
| ? Tutoriales | Tutoriales detallados sobre cómo aprovechar al máximo los descriptivos de text |
| ? Noticias y Changelog | Nuevas adiciones, cambios e historial de versiones. |
| ? Referencias de API | La referencia detallada para la API de TextDescriptive. Incluyendo documentación de la función |
| ? Papel | La preimpresión del documento TextDescriptives. |