GithubHelp home page GithubHelp logo

aniruddha-tapas / how-to-use-syntaxnet Goto Github PK

View Code? Open in Web Editor NEW
52.0 4.0 11.0 814 KB

Demo code to use SyntaxNet for basic paraphrasing.

License: MIT License

Python 100.00%
syntaxnet tensorflow pos-tagging nlp-parsing dependency-parsing

how-to-use-syntaxnet's Introduction

How to use SyntaxNet


SyntaxNet is a neural-network Natural Language Processing framework for TensorFlow released by Google. It is one of the most powerful and accurate parsers in the world today.

Courtesy: Google

Syntaxnet Demo

Given a sentence as input, SyntaxNet tags each word with a part-of-speech (POS) tag that describes the word's syntactic function, and it determines the syntactic relationships between words in the sentence, represented in the dependency parse tree. These syntactic relationships are directly related to the underlying meaning of the sentence in question.

Building SyntaxNet

There are two ways to actually build and run SyntaxNet:

  1. Building from source.
  2. Using Docker.

1. Building from source.

You can build SyntaxNet by following the nice guide provided in the main SyntaxNet github branch.

2. Using Docker.

Building from source is doable but its computationally expensive and can result in few bugs while building if we mess up with the steps provided. Hence a clean way to build SyntaxNet is by using Docker. Here's what we are going to require :

Prerequisites:

  • A 64-bit computer with at least 2 GB of RAM
  • The latest version of Docker
  • Ubuntu (I have only tested it on Ubuntu as of yet.)

Steps:

  1. Pulling the Docker Image

There could be other SyntaxNet images, but for demonstration, we'll be pulling an image created by brianlow.

docker pull brianlow/syntaxnet-docker

Depending on the speed of your network connection, you might have to wait for a while because the image is about 1GB.

  1. Once the SyntaxNet image is installed, you can now test it. You need to create a new container using it and run a Bash shell on it.

docker run --name mcparseface --rm -i -t brianlow/syntaxnet-docker bash

  1. Parsey McParseface, the pre-trained model that comes with SyntaxNet is powerful but slightly complicated. Thankfully, we can use the shell script demo.sh provided with SyntaxNet itself. All you need to do is pass an English sentence to it.
echo "I found a website to post AI tutorials ." | syntaxnet/demo.sh

It generates the folling dependency parse tree as output:

Input: I found a website to post AI tutorials .
Parse:
found VBD ROOT
 +-- I PRP nsubj
 +-- website NN dobj
 |   +-- a DT det
 |   +-- post VB infmod
 |       +-- to TO aux
 |       +-- tutorials NNS dobj
 |           +-- AI NNP nn
 +-- . . punct

Using SyntaxNet

Instead of running the shell script, the code in this repo shows you how to use SyntaxNet. I have built a Python wrapper which calls the shell script and runs SyntaxNet.

  • Usage

python main.py '<some-english-text>.'

  • Output :
Dependency tree:
Input: I found a website to post AI tutorials .
Parse:
found VBD ROOT
 +-- I PRP nsubj
 +-- website NN dobj
 |   +-- a DT det
 |   +-- post VB infmod
 |       +-- to TO aux
 |       +-- tutorials NNS dobj
 |           +-- AI NNP nn
 +-- . . punct
 
Paraphrased sentence : 
I established a website to post AI tutorials.

Basically what this script does is:

  • it parses the input sentence
  • finds the root verb from the sentence using the dependency tree created by SyntaxNet
  • finds a synonym of the root verb using the nltk library
  • replaces the original verb with the synonym

You'll have to run pip install nltk to install nltk. The Verb folder contains the code to find out the tense of the root verb so that its synonym can be coded to be the same tense, in order to keep the meaning of the sentence intact.

Conclusion

Thus, this code is a pretty simple approach to use SyntaxNet for basic paraphrasing. It's just a demo and it doesn't always find the paraphrase and hence in such cases returns the same sentence. But our main goal is to run SyntaxNet and leverage its capabilities to find the proper context in a given text and use it to find important pieces of text like the Root Word, Dependent Object etc.

  • To learn more about all the Part of Speech Tags that appear in the SyntaxNet output, please visit here.

  • And to understand the dependencies that SyntaxNet tries to find within a sentence, please visit here.

These links would definitely help you to understand the output of SyntaxNet better. Feel free to improvise!


how-to-use-syntaxnet's People

Contributors

aniruddha-tapas avatar ikishorek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

how-to-use-syntaxnet's Issues

NO LISCNECE

Hello, Thanks for nice usage.
I want to know about LISCENCE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.