Giter Club home page Giter Club logo

nlp-postag2's Introduction

NLP - POSTAG Program

@Author: Yulong He
@ver: 1.0.0
@Date: 2020.02.04

This NLP HMM POS tagging program is used to tag the corpus based on the PENN Tree Bank corpus. It is written in javascript and to run this program, you will need to install Node.js

To run this program, type the following in console:

$node postag.js

The traning corpus used in the program is provided by the PENN Tree Bank and is required to put into the root directory where the 'postag.js' is presented. Fail to have the correct corpus name will also result in an error.

Please check if your root directory has the following tree structure:

└── *root
    ├── WSJ_02-21.pos (Training File)
    ├── WSJ_23.words (Corpus that needs to be tagged)
    └── postag.js 

The basic structure of this program is:

  1. Read the traning file and extract the frequency of each word tagged in that tag.
  • (eg. 'CC': 'Apple': 15) this means that Apple is tagged 15 times as CC.
  1. Create a hashtable to record the word frequency from previous extraction.

  2. Calculate proability of the word within that tag and store that in the hash-table.

  • (eg. 'CC':'Apple':0.5 if total count of CC is 30)
  1. Again, read the training file but this time count the frequency of each state occurs after a specific state
  • (eg. 'DT': 'CC': 1000) This means that the frequency of DT followed by CC is 1000
  1. Do the same process as above, calculate the probability and put that into a hash-table.

    Step 1-5 are done within the functions:

    ├── countPOS
    ├── countState
    └── calculateProbability
  1. Now the traning stage calculation is finished and we are ready to use it to tag the corpus.

  2. To tag the sentence, we implement Viterbi Algorithm, but the basic logic is:

    • first we want to look up for the probability that the word exists in different state. (word observation probability)
    • second we want to find the probability of that state follow by the previous state (transition probability)
    • calculate the observation probability and transition probability.
    • choose the highest probability path until that state.
    • do the process recursively until we reach the end of sentence. (the process is tagged word by word)
    • calculate the score for the path, and choose the highest scoring path as the tagging sequence for the sentence.
  3. return the tagged sequence as a 2D-array.

    Step 6-8, including OOV handling, are done within the funcitons:

  ├── tagSequence

OOV Case Handling:

  • Since the training file contains limited words, we may encounter OOV case.
  • This program handles the OOV case by:
    • assume the likelihood probability as 1/1000 for all OOV items.
    • choose the highest previous state as the major criteria to tag the word.
    • for example, if the previous state is DT, and we find CC has the highest probability followed by the DT, we will choose CC as the tag for that word.

nlp-postag2's People

Contributors

yulonghe97 avatar

Watchers

 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.