Giter VIP home page Giter VIP logo

nlp_parsing_cky's Introduction

NLP_Parsing_CKY

Use CKY algorithm to parse sentences

Introduction

The project aims to use CKY algorithm to parse a sentence into corresponding parsing tree.

The original data is fetched from WSJ treebank.

The raw_input has one sentence per line.

The tree generated follows the json encoding scheme.

For example:

raw_input: I love doggie.

tree: ["S", ["NP", ["NP+PRON" I], ["VP", ["V", love], ["NP", doggie]]]

The file parser.py contains all the code

count_cfg_freq.py is a handy tool to count unary rule, binary rule and nonterms.

Usage

There are two ways to call parser.py

Change Infrequent Words into RARE

''' python parser.py inputFile outputFile '''

By calling parser.py in such a fashion, the program will take a inputFile(which is a file contains trees for training sentences) and a outputFile(modified trees for training sentences) as input.

The program will count the unary rules of the inputFile, and replace the infrequent words(frequency < 5) into "_RARE" and output to outputFile

Actual parsing

''' python parser.py parse train_data test_data predict_file '''

The train_data contains trees for training sentences.

The test_data contains sentences for test purpose.

The predict_file is the directory of the output.

The program will first generate a count file using train_data. Then use the CKY algorithm to parse the test_data into trees, then output to predict_file

The program is compatible with train_data that undergoes markov verticalization. But the run time will be significantly longer.

Performance

Train data without markov verticalization

Trained on 5322 sentences/trees. Test on 244 sentences.

alt text

Train data with markov verticalization

Trained on 5322 sentences/trees. Test on 244 sentences.

alt text

nlp_parsing_cky's People

Contributors

argowang avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.