Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Jens Albrecht, Sidharth Ramachandran, Christian Winkler

Rating No ratings yet

Turning text into valuable information is essential for businesses looking to gain a competitive advantage. With recent improvements in natural language processing (NLP), users now have many options for solving complex challenges. But it's not always clear which NLP tools or libraries would work for a business's needs, or which techniques you should use and in what order. This practical book provides data scientists and developers with blueprints for best practice solutions to common tasks in text analytics and natural language processing. Authors Jens Albrecht, Sidharth Ramachandran, and Christian Winkler provide real-world case studies and detailed code examples in Python to help you get started quickly. Extract data from APIs and web pages Prepare textual data for statistical analysis and machine learning Use machine learning for classification, topic modeling, and summarization Explain AI models and classification results Explore and visualize semantic similarities with word embeddings Identify customer sentiment in product reviews Create a knowledge graph based on named entities and their relations

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Blueprints for Text Analytics Using Python ## 【One-Line Pitch】 A practical, blueprint-driven guide for data scientists and developers who want to turn raw text into actionable business insights using Python's NLP ecosystem—covering everything from data extraction to advanced machine learning, with real-world case studies and ready-to-adapt code patterns. ## 【Book Arc】 - **Opening (~0%–10%)**: Introduces the core philosophy of text analytics and starts with foundational statistical exploration—word frequencies, n-grams, and visualization techniques using UN General Debate data, establishing the "blueprint" pattern of problem → approach → code → insight. - **Early (~10%–23%)**: Moves into data acquisition, covering API extraction (GitHub, Twitter, Wikipedia) with practical guidance on authentication and rate limits, then web scraping with Beautiful Soup, readability-lxml, and Scrapy—including the trade-offs between structured, density-based, and all-in-one extraction approaches. - **Early (~23%–32%)**: Focuses on text preprocessing and linguistic enrichment—cleaning noisy data with regex, tokenization, part-of-speech tagging, lemmatization, and named entity recognition using spaCy and textacy, with attention to why lemmatization isn't always the right choice. - **Middle (~32%–48%)**: Dives into vectorization and similarity—building custom document vectorizers, understanding one-hot encoding and TF-IDF, managing feature space growth, and then applying these to text classification with supervised learning, feature engineering, and model evaluation using real-world datasets like bug reports. - **Late (~48%–end)**: Covers advanced topics including sentiment analysis (lexicon-based vs. supervised approaches), word embeddings and visualization, topic modeling, summarization, model explainability, and building knowledge graphs from named entities and their relations. ## 【Key Takeaways】 - **Relative frequencies reveal insights** (Early): Absolute word counts are rarely interesting; comparing relative frequencies across groups (e.g., political parties) uncovers meaningful differences—the foundation of exploratory text analysis. - **API extraction requires understanding status codes** (Early): Always check HTTP response codes before processing; a 422 error means the request was understood but malformed (e.g., missing query parameters), and proper developer authentication is mandatory for most APIs. - **Density-based extraction trades precision for scale** (Early): When you need content from many different page layouts, heuristic/statistical extraction (python-readability) beats hand-crafted selectors—but requires more rigorous quality assurance afterward. - **Lemmatization isn't always beneficial** (Early): While lemmas help many tasks, they can hurt sentiment analysis where "good" vs. "best" carry different emotional weight—always consider the downstream task before normalizing. - **Feature space growth leads to overfitting** (Middle): Changing vectorizer parameters like ngram_range can explode feature dimensions, causing RAM issues and model overfitting—always monitor feature count when tuning. - **Feature engineering adds domain knowledge** (Middle): Beyond raw text features, adding metadata (e.g., day-of-week for bug reports) helps models learn better mapping functions—the key to improving classification accuracy. - **Multiple SVM implementations exist** (Middle): LinearSVC is typically fastest for linear kernels, while SVC and other methods are more generic—choose based on your speed vs. flexibility needs. ## 【Reading Tips】 - **Skim Chapters 1–3** if you're already comfortable with basic Python data analysis and web scraping—the core value is in the later chapters on vectorization, classification, and advanced NLP. - **Deep-read the vectorization chapter** (~32%–39%): Understanding how document vectorizers work internally is crucial for appreciating all subsequent machine learning blueprints. - **Pay attention to the "why" behind each blueprint**: The authors explain trade-offs (e.g., structured vs. density-based extraction, lexicon vs. supervised sentiment) that help you choose the right approach for your own projects. - **Note the spaCy version caveat**: Examples use spaCy 2.3.2; if you're on 3.0+, results may differ slightly—check the companion notebooks for updates. - **Focus on the reusable patterns**: Each chapter follows a consistent structure (What You'll Learn → Blueprint → Evaluation), making it easy to adapt the code to your own datasets. ## 【Coverage Limits】 This guide synthesizes the book's core progression from data extraction through classification and advanced NLP, but the excerpts do not cover the full details of later chapters on sentiment analysis implementation, word embedding visualization, topic modeling, summarization, and knowledge graph construction—readers should consult the book for those specifics. ##
Excerpt 1
oaches i. Preparing Data for a Supervised Learning Approach Table P-1. Overview of the chapters Chapter Dataset Libraries Chapter 1, Gaining Ea...
View in text
Excerpt 2
ush the data to us rather than waiting for a get request as Some user agents are not allowed to download anything, but the rest may do that. We can check tha...
View in text
Excerpt 3
f inflected words is often a good idea, but not always. For example, it can have a negative effect on sentiment analysis where “good” and “best” make a diffe...
View in text
Excerpt 4
er we have achieved an automated way of predicting a label. show later in this chapter how we can arrive at the optimal parameter values for these arguments....
View in text
Excerpt 5
(nmf_gensim_para_coherence_score) Out: 0.6505110480127619 These are the weights for their corresponding words. In fact, that’s the only change compared to ...
View in text
Excerpt 6
vocab)) with open(f'{model_path}/{name}_vecs.tsv', 'w', encoding='utf-8') as tsvfile: writer = csv.writer(tsvfile, delimiter='\t',
View in text
Excerpt 7
ed-entity in case it was misidentified. This is done by the function propagate_ent_type. It updates all resolved aliases Blueprint: Creating a Co- Occurrence...
View in text
Excerpt 8
is as specified next and contains the text of the review, a mandatory field along with reviewerID, productID, and sentiment. FastAPI uses “type hints” to gue...
View in text
Tags
AI categories
PythonProgramming LanguageData
python
Publish Year: 2020
Language: English
File Format: PDF
File Size: 18.5 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…