Language Models in Python: Bag-of-Words, TF-IDF and Embeddings
Turn text into numbers with Python. Build bag-of-words and TF-IDF models by hand and with scikit-learn, classify text with Naive Bayes, and measure meaning with word vectors and embeddings you compute yourself.
- Intermediate level
- 5 modules
- 15 lessons
- 53 tasks and questions
Syllabus
01Preparing TextBefore any model can count words, text has to be split into clean, consistent tokens. Write a tokenizer with regular expressions and filter out stop words.2 lessons
02Bag-of-WordsRepresent documents by their word counts: build the model by hand, scale it up with scikit-learn's CountVectorizer, train a Naive Bayes classifier, and see what word order costs you.5 lessons
03TF-IDFWeight words by how characteristic they are of a document: compute term frequency and inverse document frequency by hand, match scikit-learn's formula, and pull out each document's key terms.3 lessons
04Word EmbeddingsRepresent meaning with dense vectors: measure distance and similarity with NumPy, explore word vectors, learn embeddings from co-occurrence counts, and see how word2vec trains on context.4 lessons
05Project: Route Support TicketsPut it all together: load labeled tickets from a CSV file, hold out test data, train a TF-IDF and Naive Bayes classifier, measure its accuracy and route new tickets.1 lesson