concept Python in category nlp

appears as: Python, Python
Getting Started with Natural Language Processing

This is an excerpt from Manning's book Getting Started with Natural Language Processing.

This book will cover the core topics in NLP, and I hope it will be of a great help in your everyday work as well as in your projects, whichever background you are coming from and whatever primary interest in this field you have. What is even more important than the arguments of utility and potential is that NLP is interesting, intellectually stimulating and fun! And remember that as a natural language speaker, you are already an expert in many of the tasks that NLP addresses, so it is one of those areas in which one can get on easily. This book is written with the lowest entry barrier to learning possible: you don’t need to have any prior knowledge about how language works – the book will walk you through the core concepts and techniques starting from the very beginning. All you need at the beginning is some basic programming skills in Python and basic understanding of mathematical notations, but what you will learn by the end of this book is a whole set of NLP skills and techniques. Let’s begin!

Taking this into account, you might update your algorithm with a splitting strategy by punctuation marks. There are several possible ways to do that, including using Python’s regular expressions module re.[9] However, if you have never used regular expressions before, you may apply a simple iterative algorithm that will consider each character in the text string and decide whether it should be ignored (if it is a whitespace), added to a word list (if it is a punctuation mark), or added to the current word (otherwise). In other words, the algorithm may proceed as follows:

Natural Language Processing in Action: Understanding, analyzing, and generating text with Python

This is an excerpt from Manning's book Natural Language Processing in Action: Understanding, analyzing, and generating text with Python.

Regular expressions use a special kind (class) of formal language grammar called a regular grammar. Regular grammars have predictable, provable behavior, and yet are flexible enough to power some of the most sophisticated dialog engines and chatbots on the market. Amazon Alexa and Google Now are mostly pattern-based engines that rely on regular grammars. Deep, complex regular grammar rules can often be expressed in a single line of code called a regular expression. There are successful chatbot frameworks in Python, like Will, that rely exclusively on this kind of language to produce some useful and interesting behavior. Amazon Echo, Google Home, and similarly complex and useful assistants use this kind of language to encode the logic for most of their user interaction.

>>> from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
>>> sa = SentimentIntensityAnalyzer()
>>> sa.lexicon                                          #1
{ ...
':(': -1.9,                                             #2
':)': 2.0,
...
'pls': 0.3,                                             #3
'plz': 0.3,
...
'great': 3.1,
... }
>>> [(tok, score) for tok, score in sa.lexicon.items()
...   if " " in tok]                                    #4
[("( '}{' )", 1.6),
 ("can't stand", -2.0),
 ('fed up', -1.8),
 ('screwed up', -1.5)]
>>> sa.polarity_scores(text=\
...   "Python is very readable and it's great for NLP.")
{'compound': 0.6249, 'neg': 0.0, 'neu': 0.661,
'pos': 0.339}                                           #5
>>> sa.polarity_scores(text=\
...   "Python is not a bad choice for most applications.")
{'compound': 0.431, 'neg': 0.0, 'neu': 0.711,
'pos': 0.289}                                           #6

To get the most out of this book, you’ll want to get comfortable with Python. You’ll want to be so comfortable that you get playful. When things don’t work, you’ll need to be able to play around and explore to find a way to make Python do what you want.