liveBook · Manning

Machine learning

As explained in Natural Language Processing in Action, Second Edition

Machine learning is a computational approach in which algorithms derive patterns or behavior from data rather than relying solely on explicitly programmed rules.

A chatbot that recognizes greetings could use a long list of handcrafted patterns. Machine learning takes a different approach: it learns patterns from data, reducing the need to anticipate every spelling and expression in advance. In natural language processing (NLP), it can use statistical patterns to respond to text and recognize relationships in meaning, not just spelling. section 1.10 section 1.5.2

For a chatbot, labeled examples can pair user statements with desired responses. The resulting model can be less sensitive to typos than handcrafted patterns, but its responses depend heavily on dataset quality. More domain-specific data can improve a pipeline, while the choice of learning approach also matters. section 1.10 section 1.8

Learning sentiment from examples

A sentiment model can learn to assign a positivity score from labeled statements or documents. A score near +1 could indicate strongly positive text, one near −1 strongly negative text, and one near zero a mostly neutral statement. Twitter hashtags such as #awesome or #happy can help create a self-labeled dataset. By contrast, a rule-based approach might sum scores from a manually composed dictionary of keywords. section 2.6

>>> import re             #1
>>> r = "(hi|hello|hey)[ ,:.!]*([a-z]*)"      #2
>>> re.match(r, 'Hello Rosa', flags=re.IGNORECASE)     #3
<re.Match object; span=(0, 10), match='Hello Rosa'>
>>> re.match(r, "hi ho, hi ho, it's off to work ...", flags=re.IGNORECASE)
<re.Match object; span=(0, 5), match='hi ho'>
>>> re.match(r, "hey, what's up", flags=re.IGNORECASE)
<re.Match object; span=(0, 9), match='hey, what'>

This greeting-matching experiment illustrates the alternative: a regular expression explicitly specifies the character patterns to recognize. Its match on “hi ho” also shows why a match is not necessarily the intended interpretation. section 1.5.2

Machine learning is one part of an NLP system, not a guarantee of reliable understanding. Chatbots may combine feature extraction, information extraction, semantic search, and language generation; a plausible response is not necessarily correct or helpful. Even more complex deep learning pipelines can remain brittle, so dataset design and evaluation matter. section 1.10 section 1.8 section 1.5.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains data-driven learning through comparisons with handcrafted rules, while deferring detailed model implementation.
Examples
Illustrates greeting recognition with regular expressions and sentiment scoring with labeled statements and Twitter hashtags.
What you can do after
Evaluate data-driven NLP against handcrafted rules while recognizing dataset quality and response reliability limitations.
How it connects
Connects machine learning with natural language processing, regular expressions, sentiment analysis, deep learning, and semantic search.

Also explained in

Compare how 43 books explain machine learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.