
CONTENTS iii
3 Promise of Deep Learning for Natural Language 16
3.1 Promise of Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Promise of Drop-in Replacement Models . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Promise of New NLP Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Promise of Feature Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5 Promise of Continued Improvement . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.6 Promise of End-to-End Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4 How to Develop Deep Learning Models With Keras 21
4.1 Keras Model Life-Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Keras Functional Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3 Standard Network Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
III Data Preparation 34
5 How to Clean Text Manually and with NLTK 35
5.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.2 Metamorphosis by Franz Kafka . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.3 Text Cleaning Is Task Specific . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.4 Manual Tokenization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.5 Tokenization and Cleaning with NLTK . . . . . . . . . . . . . . . . . . . . . . . 41
5.6 Additional Text Cleaning Considerations . . . . . . . . . . . . . . . . . . . . . . 46
5.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6 How to Prepare Text Data with scikit-learn 48
6.1 The Bag-of-Words Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.2 Word Counts with CountVectorizer . . . . . . . . . . . . . . . . . . . . . . . . 49
6.3 Word Frequencies with TfidfVectorizer . . . . . . . . . . . . . . . . . . . . . . 50
6.4 Hashing with HashingVectorizer . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6.5 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
6.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7 How to Prepare Text Data With Keras 54
7.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.2 Split Words with text to word sequence . . . . . . . . . . . . . . . . . . . . . 54
7.3 Encoding with one hot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.4 Hash Encoding with hashing trick . . . . . . . . . . . . . . . . . . . . . . . . 56
7.5 Tokenizer API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
评论0