PsychiatryNLPKit.analysis.paragraph_level_perplexity
- PsychiatryNLPKit.analysis.paragraph_level_perplexity(paragraph_generative_tokens, generative_model, sections=None, manage_lifecycle=True)[source]
Generative perplexity for full paragraphs.
- Notes:
Theoretical basis - Perplexity can be computed both at the sentence and paragraph levels (Alqahtani et al., 2022). High perplexity predicts delusion and unusual thought content, as reflected by the total PANSS scores (He et al., 2024).
- Args:
- paragraph_generative_tokens: Dict from
TextData.paragraph_generative_tokens. Maps section names to token dicts withinput_idsandattention_mask.- generative_model:
HFGenerativeLLMinstance. Must be loaded unless manage_lifecycle is
True.
sections: Sections to process.
Noneprocesses all sections in the dict. manage_lifecycle: IfTrue(default), load and unload the modelinternally. Set to
Falsewhen the caller manages the lifecycle.- Returns:
Dict mapping section names to a dict with key
"paragraph_level_perplexity".- References:
Alqahtani, A., Kayi, E. S., Hamidian, S., Compton, M., & Diab, M. (2022, December). A quantitative and qualitative analysis of schizophrenia language. In A. Lavelli, E. Holderness, A. Jimeno Yepes, A. Minard, J. Pustejovsky, & F. Rinaldi (Eds.), Proceedings of the 13th International Workshop on Health Text Mining and Information Analysis (LOUHI) (pp. 173-183). Association for Computational Linguistics. https://doi.org/10.18653/v1/2022.louhi-1.20 He, R., Palominos, C., Zhang, H., Alonso-Sánchez, M. F., Palaniyappan, L., & Hinzen, W. (2024). Navigating the semantic space: Unraveling the structure of meaning in psychosis using different computational language models. Psychiatry Research, 333, 115752. https://doi.org/10.1016/j.psychres.2024.115752