PsychiatryNLPKit.analysis.image_text_similarity
- PsychiatryNLPKit.analysis.image_text_similarity(image, text, vit_model, sections=None, manage_lifecycle=True)[source]
Compute cosine similarity between an image and selected text sections.
- Notes:
Theoretical basis - Lower multimodal embedding similarity scores predict higher disorganization (He et al., 2024).
- Args:
image: PIL image object, image path, or URL supported by the model. text: Dict mapping section names to text strings (from
TextData.data). vit_model:HFMultimodalEmbeddingModelinstance. Must be loaded unlessmanage_lifecycle is
True.sections: Sections to process.
Noneprocesses all sections in text. manage_lifecycle: IfTrue(default), load and unload the modelinternally. Set to
Falsewhen the caller manages the lifecycle.- Returns:
Dict mapping section names to a metric dict with key
"image_text_similarity"(SentenceTransformer cosine similarity).- Raises:
RuntimeError: If the model cannot encode image and text inputs.
- References:
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