This GIT repository accompanies the seminar on Deep Learning for Natural Language Processing.
In contrast to other seminars, this seminar focuses on the usage of deep learning methods. As programming infrastructure we use Python in combination with Keras. The published code can be used with Python 2.7 or Python 3.6, Keras 2.0.5, and Theano (0.9.0) or TensorFlow (1.2.1) backend. You should ensure that you have the frameworks installed in the right version (note: they change quickly).
This seminar is structured into 4 sessions:
- Feed-Forward Networks for Sequence Classification (e.g. POS, NER, Chunking)
- Convolutional Neural Network for Sentence / Text Classification (e.g. sentiment classification)
- Convolutional Neural Network for Relation Extraction (e.g. semantic relation extration)
- Long-Short-Term-Memory (LSTM)-Networks for Sequence Classificaiton
The seminar is inspired by an engineering mindset: The beautiful math and complexity of the topic is sometimes neglected to provide instead an easy-to-understand and easy-to-use approach to use Deep Learning for NLP tasks (we use what works without providing a full background on every aspect).
At the end of the seminar you should be able to understand the most important aspect of deep learning for NLP and be able to programm and train your own deep neural networks.
In case of questions, feel free to approach Nils Reimers.
The codes in this folder were developed for Python 2.7 (and Python 3.6), Keras 2.0.5. As backend for Keras you can use Theano 0.9.0 or TensorFlow 1.2.1.
You can setup a virtual environment in the following way:
You can install the required packages in the following way:
pip install -r requirements.txt
Alternatively, it should be sufficient to just install Keras in version 2.0.5 and TensorFlow:
pip install Keras==2.0.5 TensorFlow==1.2.1
It can be useful, to run Python in a virtual environment for this seminar.
Create a virtualenv in the following way:
virtualenv .env
source .env/bin/activate
If you operate in the virtual environment, you can run pip to install the needed packages in the following way:
.env/bin/pip install -r requirements.txt
The folder docker
contains a dockerfile that bundles an environment needed to run the experiments in this folder. It installs Python 3.6, Keras 2.0.5 and Tensorflow 1.2.1.
First, you need to build the docker container:
docker build ./docker -t dl4nlp
Than, in this folder you can start the container and mount files in this container to the docker container:
docker run -it -v ${PWD}:/usr/src/app dl4nlp bash
This will start a bash inside the dl4nlp container, where Python is installed. Through the mounting, you can modify the files in this folder and run them inside the docker container.
The following is a short list with good introductions to different aspects of deep learning.
- 2009, Yoshua Bengio, Learning Deep Architectures for AI by Yoshua Bengio
- 2013, Richard Socher and Christopher Manning, Deep Learning for Natural Language Processing (slides and recording from NAACL 2013)
- 2015, Yoshua Bengio et al., Deep Learning - MIT Press book in preparation
- 2015, Richard Socher, CS224d: Deep Learning for Natural Language Processing
- 2015, Yoav Goldberg, A Primer on Neural Network Models for Natural Language Processing
Slides: pdf
The first theory lesson covers the fundamentals of deep learning.
Slides: pdf
Slides: pdf
The second lesson gives an overview of deep learning frameworks. Hint: Use Keras and have a look at Theano and TensorFlow.
Slides: pdf
Code: See folder Session 1 - SENNA
The first code session is about the SENNA architecture (Collobert et al., 2011, NLP (almost) from scratch). In the folder you can find Python code for the preprocessing as well as Keras code to train and evaluate a deep learning model. The folder contains an example for Part-of-Speech tagging, which require the English word embeddings from either Levy et al. or from Komninos et al..
You can find in this folder also an example for German NER, based on the GermEval 2014 dataset. To run the German NER code, you need the word embeddings for German from our website.
Recommended Readings:
Slides: pdf
This is an introduction to Convolutional Neural Networks.
Recommended Readings:
Slides: pdf
Code: See folder Session 2 - Sentence CNN
This is a Keras implementation of the Kim, 2014, Convolutional Neural Networks for Sentence Classification. We use the same preprocessing as provided by Kim in his github repository but then implement the rest using Keras.
Slides: pdf
Code: See folder Session 3 - Relation CNN
This is an implementation for relation extraction. We use the SemEval 2010 - Task 8 dataset on semantic relations. We model the task as a pairwise classification task.
Recommended Readings:
- Zeng et al., 2014, Relation Classification via Convolutional Deep Neural Network
- dos Santos et al., 2015, Classifying Relations by Ranking with Convolutional Neural Networks
Slides: pdf
Code: See folder Session 4 - LSTM Sequence Classification
Note: An extended version of this LSTM architecture for sequence tagging can be found in the BiLSTM-CNN-CRF repository.
LSTMs are a powerful model and became very popular in 2015 / 2016.
Recommended Readings:
Slides: pdf
The folder contains a Keras implementation to perfrom sequence classification using LSTM. We use the GermEval 2014 dataset for German NER. But you can adapt the code easily to any other sequence classification problem (POS, NER, Chunking etc.). Check the slides for more information.