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










































