PsychiatryNLPKit.data.TextData
- class PsychiatryNLPKit.data.TextData(sections, lang='en', embedding_model=None, generative_model=None)[source]
Main text data container with lazy-computed linguistic properties.
- Args:
sections: List of Section objects. lang: Language code (“en” or “fr”). Determines tokenizer and stopwords. embedding_model: Optional embedding model for vector computations. generative_model: Optional generative model for perplexity computations.
Properties compute on first access and cache results. The
_computedset tracks which properties have been materialized.Methods
__init__(sections[, lang, embedding_model, ...])Attributes
Attention scores per section, shape (n_tokens, n_tokens).
Word2Vec embeddings for content words per section, shape (n_words, dim).
Content words (nouns, verbs, adjectives, adverbs) per section.
Raw section text keyed by section name.
Tokenized paragraphs for generative perplexity.
list of sentences, each a list of (word, lemma, tag) tuples.
Sentence-level embeddings per section, shape (n_sentences, dim).
Tokenized sentences for generative perplexity.
Sentences per section (list of strings).
Benepar constituency trees per section (one per sentence).
Token-level embeddings per section, shape (n_tokens, dim).
- property pos_tags: dict[str, list[list[tuple[str, str, str]]]]
list of sentences, each a list of (word, lemma, tag) tuples.
- Type:
POS tags per section
- property syntax_trees: dict[str, list[Any]]
Benepar constituency trees per section (one per sentence).
- property token_embedding_vectors: dict[str, Tensor]
Token-level embeddings per section, shape (n_tokens, dim).
Computed via the embedding model’s last_hidden_state with attention-mask aware mean pooling. Requires
output_attentions=Trueon the model.
- property attention_scores: dict[str, Tensor]
Attention scores per section, shape (n_tokens, n_tokens).
Aggregated over layers and heads. Computed alongside token embeddings.
- property sentence_embedding_vectors: dict[str, Tensor]
Sentence-level embeddings per section, shape (n_sentences, dim).
- property content_words: dict[str, list[str]]
Content words (nouns, verbs, adjectives, adverbs) per section.
- property content_word_embedding_vectors: dict[str, Tensor]
Word2Vec embeddings for content words per section, shape (n_words, dim).