Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deepnl --- Deep Learning for Natural Language Processing

deepnl is a Python library for Natural Language Processing tasks based on a Deep Learning neural network architecture.

The library currently provides tools for performing part-of-speech tagging, Named Entity tagging and Semantic Role Labeling.

deepnl also provides code for creating word embeddings from text, using either the Language Model approach by [Collobert11], or Hellinger PCA, as in [Lebret14].

It can also create sentiment specific word embeddings from a corpus of annotated Tweets.

If you use deepnl, please cite [Attardi] in your publications.

WARNING. There has been a change in file format for models since version 1.3.14. You will have to retrain them to use with later versions.

Installation

Download the code or clone the repository on your machine with:

$ git clone https://github.com/attardi/deepnl.git

Ensure that you have the dependencies mentioned below, then proceed to the build process described below.

Dependencies

deepnl requires numpy and Eigen.

A C++ compiler is also needed for compiling the C++ extensions it uses, produced with Cython. The generated .cpp files are already provided with deepnl, but you will need Cython if you want to develop or modify the C++ extensions.

Build

To compile the library, run:

$ python2 setup.py build

This will invoke the C++ compiler to compile the code on your platform.

You can run the scripts directly from the bin directory, or you can install them by calling:

$ sudo python setup.py install

If Cython gets invoked and raises error, force an update on the file timestamps, with:

$ touch deepnl/*.cpp

Basic usage

deepnl can be used both as a Python library or through command line scripts.

Library usage

You can use deepnl as a library in Python code as follows, where filename is the name of the file containing the model produced through training:

>>>fromdeepnl.taggerimportTagger>>>tagger=Tagger.load(open(filename))
>>>sent='The quick brown fox jumped over the lazy dog .'>>>tagger.tag_sequence(sent.split(), return_tokens=True)
[[(u'The', u'DT'), (u'quick', u'JJ'), (u'brown', u'JJ'), (u'fox', u'NN'), (u'jumped', u'VBD'), (u'over', u'IN'), (u'the', u'DT'), (u'lazy', u'JJ'), (u'dog', u'NN'), (u'.', '.')]]

Class Tagger is a generic interface for sequence taggers and provides a method tag_sequence for tagging a sentence. A sentence is represented as a list of tokens.

Class Tagger can be used directly for performing POS tagging. Two specializations are provided: NerTagger`, for Named Entity tagging and ``SrlTagger for Semantic Role Labeling.

The output of tag_sequence is normally a list of tuples, representing tokens with their associated tags. In the case of POS tagging, the tags are just the POS tags of each token; in case of NerTagger the tags are in IOB notation for representing subsequences, while in the case of SrlTagger the output is more complex.

Standalone scripts

deepnl provides scripts for tagging text or training new models.

They are present in the bin subdirectory where you downloaded the code. If you did not install them, you can invoke them directly from there.

Call them with option -h or --help to obtain details on their usage.

The scripts expect tokenized input, one token per line, with an empty line to separate sentences.

When training, the token attributes are supplied in TSV (tab separated values) format. Here is an example of POS tagging, using a previously trained model from file pos.dnn:

$ dl-pos.py pos.dnn
The
quick
brown
fox
jumped
over
the
lazy
dog
.
The DT
quick JJ
brown JJ
fox NN
jumped VBD
over IN
the DT
lazy JJ
dog NN
..

Word Embeddings

The command dl-words.py allows creating word embeddings from a language model built from a plain text corpus, properly tokenized.

The command dl-words-pca.py allows creating word embeddings from a language model built from a plain text corpus, with the technique of Hellinger PCA.

The command dl-sentiwords.py allows creating sentiment specific word embeddings from a corpus of annotated Tweets.

Benchmarks

The NER tagger replicates the performance of SENNA in the CoNLL 2003 benchmark.

The CoNLL-2003 shared task data can be downloaded from http://www.cnts.ua.ac.be/conll2003/ner/.

The train and test data must be cleaned and converted to the more recent IOB2 notation, by calling:

sed '/-DOCSTART-/,+1d' train | bin/toIOB.py | cut -f 1,2,4 > train.iob
sed '/-DOCSTART-/,+1d' testa | bin/toIOB.py | cut -f 1,2,4 > testa.iob
sed '/-DOCSTART-/,+1d' testb | bin/toIOB.py | cut -f 1,2,4 > testb.iob
cat train.iob testa.iob > train+dev.iob

Assuming that the SENNA distribution is in directory senna, the embeddings and vocabulary from SENNA can be used:

cp -p senna/embeddings/embeddings.txt vectors.txt
cp -p senna/hash/words.lst vocab.txt

The gazetters from SENNA can be used to produce a single entity list as follows:

iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.loc.lst | awk '{printf "LOC\t%s\n", $$0}'> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.misc.lst | awk '{printf "MISC\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.org.lst | awk '{printf "ORG\t%s\n", $$0}'>> eng.list
iconv -f ISO-8859-1 -t UTF-8 < senna/hash/ner.per.lst | awk '{printf "PER\t%s\n", $$0}'>> eng.list

You also need the list of suffixes:

cp -p senna/hash/suffix.lst suffix.lst

The tagger can then be trained as follows:

bin/dl-ner.py ner.dnn -t train+dev.iob \
--vocab vocab.txt --vectors vectors.txt \
--caps --suffix --suffixes suffix.lst --gazetteer eng.list \
-e 40 --variant senna \
-l 0.01 -w 5 -n 300 -v

The benchmark can be run as:

bin/dl-ner.py ner.dnn < testb.iob > testb.out.iob

The results I achieved are:

processed 46435 tokens with 5648 phrases; found: 5640 phrases; correct: 5031.
accuracy: 97.62%; precision: 89.20%; recall: 89.08%; FB1: 89.14
LOC: precision: 93.30%; recall: 91.01%; FB1: 92.14
MISC: precision: 78.24%; recall: 77.35%; FB1: 77.79
ORG: precision: 84.59%; recall: 87.24%; FB1: 85.89
PER: precision: 94.71%; recall: 94.06%; FB1: 94.38

Writing Extensions

You can modify or extend the code just by adding them to the directory deepnl. To compile the extension, use the same build process, but you will also need to have Cython installed. The compiler will issue warnings about NumPy of the type:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

#warning "Using deprecated NumPy API, disable it by "

Simply disregard them, since currently there is no way to fix them, until the maintainers of Cython will decide to upgrade it to use the latest API.

Credits

Erick Fonseca developed nlpnet, a similar library, available at: https://github.com/erickrf/nlpnet, which provided inspiration for deepnl.

References

[Attardi]Giuseppe Attardi. 2015. DeepNL: a Deep Learning NLP pipeline. Workshop on Vector Space Modeling for NLP, NAACL 2015, Denver, Colorado (June 5, 2015).
[Collobert11]Ronan Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa. Natural Language Processing (Almost) from Scratch. Journal of Machine Learning Research, 12:2493-2537, 2011.
[Lebret14]Rémi Lebret and Ronan Collobert. 2014. Word Embeddings through Hellinger PCA. EACL 2014: 482.

About

Deep Learning for Natural Language Processing

Resources

Stars

462 stars

Watchers

42 watching

Forks

Releases

Packages

Used by

Contributors

Languages