Syntaxnet Parsey McParseface wrapper for POS tagging and dependency parsing
Note: This syntaxnet build contains The Great Models Move change.
When Google declared that The World’s Most Accurate Parser i.e., SyntaxNet goes open-source, it grabbed widespread attention from machine-learning developers and researchers who were interested in core applications of NLU like automatic extraction of information, translation etc. Following gif shows how syntaxnet internally builds the dependency tree:
Predominantly one will find two approaches to use SyntaxNet:
import subprocess
import os
os.chdir(r"../models/syntaxnet")
subprocess.call([
"echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh"
], shell = True)
+ I wanted a proper scalable python application where one can do `import syntaxnet`
+ and use it as shown below:
import syntaxnet
from syntaxnet import gen_parser_ops...
+ I could manage to get this done and hence sharing my project here. Please find below as to how I got this!!
Apart from having high struggles in installation and huge learning curve, no official support and lack of clear documentation
led forums talking about myraid of issues on SyntaxNet without proper solutions. Some of them were as basic as:
This endevour addresses to make the life of SyntaxNet enthusiasts easier. It primarily saves all those hours to get Google's SyntaxNet Parsey McParseface
up and running in a way it should be. For this, am providing two things as part of this project:
Iam sharing the osx syntaxnet package distribution i.e., syntaxnet-0.2-cp27-cp27m-macosx_10_6_intel.whl file
in this git repo that I've got successfully built using bazel
build tool with all tests passing after pulling the latest code from syntaxnet git repository. This will setup syntaxnet 0.2 version
with a simple command in barely 5 minutes as shown below:
git clone https://github.com/spoddutur/syntaxnet.git
cd <CLONED_SYNTAXNET_PROJ_DIR>
sudo pip install syntaxnet-0.2-cp27-cp27m-macosx_10_6_intel.whl
my_parser_eval.py
is the file that contains the python-wrapper which I implemented to wrap SyntaxNet. The list of API's exposed in this wrapper are listed below:
1. Api to initialise parser:
`tagger = my_parser_eval.SyntaxNetProcess("brain_tagger")`
("brain_tagger" will initialise pos tagger. change it to "brain_parser" for dependency parsing)
2. Api to input data to parser:
`my_parser_eval._write_input("<YOUR_ENGLISH_SENTENCE_INPUT>")`
3. Api to invoke parser:
`tagger.eval()`
3. Api to read parser's output in conll format:
`my_parser_eval._read_output()`
4. Api to pretty print parser's output as tree:
`my_parser_eval.pretty_print()`
main.py
(a sample python code) to demo this wrapper. It performs syntaxnet's dependency parsing
.1. git clone https://github.com/spoddutur/syntaxnet.git
2. cd <syntaxnet-git-clone-directory>
3. python main.py
4. That's it!! It prints syntaxnet dependency parser output for given input english sentence
syntaxnet 0.2 version
in barely 5 minutes