liveBook · Manning

Vocabulary

As explained in Starting Data Analytics with Generative AI and Python

A vocabulary is the fixed collection of tokens that a language model can represent.

A vocabulary is a collection of terms available for a task. In dictionary-based text mining, it can be a lexicon of words associated with sentiments, emotions, or a subject area. Such a lexicon gives an analysis a starting point beyond keywords chosen by hand. This is a task-specific word list, not an explanation of the fixed token vocabulary a language model can represent. section 5.6 section 5.6.1

Suppose you need to assess sentiment in Portuguese product reviews. A sentiment lexicon supplies terms and polarity information, but choosing one is not enough. Check whether its language and domain fit the reviews, whether it is current, and whose language it may miss. Compare candidates on sample reviews rather than trusting the first resource you find. section 5.6.2 section 5.6.4

Inspect the actual file before asking an AI assistant to write a loader. An initial Python suggestion assumed SentiLex was a CSV with word and polarity columns; the chosen file instead needed parsing as text. Check the resulting entries and scores. If matches remain sparse, check word forms too: a lexicon of lemmas may not match inflected words in reviews until preprocessing produces lemmas. section 5.6.4 section 5.6.5

def load_sentilex(filepath):
    sentilex_dict = {}
    with open(filepath, 'r', encoding='utf-8') as file:
        for line in file:
            parts = line.strip().split(';')
            word = parts[0].split('.')[0]  # Get the word before '.PoS='
            pol_entry = [part for part in parts if 
            part.startswith('POL:N0=')]
            if pol_entry:
                # Assuming there's exactly one 'POL:N0=' entry per line
                polarity = int(pol_entry[0].split('=')[1])
                sentilex_dict[word] = polarity
    return sentilex_dict

# Example usage
filepath = 'SentiLex-lem-PT02.txt'
sentilex_dict = load_sentilex(filepath)

# Now sentilex_dict is ready to be used as in the previous example.

A Python loader for the selected text file shows how entries and polarity values are extracted instead of assuming a CSV layout. section 5.6.4

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Works through lexicon selection, file loading, and matching; does not explain language-model token vocabularies.
Examples
Uses Portuguese product reviews and SentiLex files to expose a mistaken CSV assumption and a lemma-matching problem.
What it assumes
Assumes a review-analysis task and basic Python workflow while introducing criteria for choosing and interpreting a lexicon.
What you can do after
Apply it via a chosen lexicon and Python preprocessing, then inspect file formats and test matches against reviews.
How it connects
Connects dictionaries with sentiment analysis, polarity scores, preprocessing, and lemmatization.

Also explained in

Compare how 13 books explain vocabulary →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.