imbed.components.vectorization#
Vectorization functions for converting text to embeddings
Functions
|
Generate basic constant vector for each segment |
|
Extracts a set of lightweight, linguistically significant features from a text segment. |
|
Calculate simple (pseudo-)semantic features of the text. |
- imbed.components.vectorization.constant_vectorizer(segments, *, sleep_s=0)[source]#
Generate basic constant vector for each segment
- imbed.components.vectorization.simple_text_embedder(texts, stopwords=None)[source]#
Extracts a set of lightweight, linguistically significant features from a text segment.
The function computes several features based on the input text including:
Total number of words.
Mean and median word lengths.
Number and ratio of stopwords.
Number of punctuation characters.
Total number of characters.
Number of sentences and average words per sentence.
Lexical diversity (ratio of unique words to total words).
Number of numeric tokens.
Number of capitalized words.
- Parameters:
- Returns:
- A list of numerical features representing the text, in the following order:
[num_words, mean_word_length, median_word_length, num_stopwords, stopword_ratio, num_punctuation, num_characters, num_sentences, avg_words_per_sentence, lexical_diversity, num_numeric_tokens, num_capitalized_words]
- Return type:
Example
>>> sample_text = "Hello, world! This is an example text, with 123 numbers and various punctuation marks." >>> sample_stopwords = {'this', 'is', 'an', 'with', 'and'} >>> simple_text_embedder(sample_text, sample_stopwords) [14, 5.21..., 6, 5, 0.35..., 4, 86, 2, 7.0, 1.0, 1, 2]