Git Product home page Git Product logo

linear-crf's Introduction

Linear-CRF

An simple implemention of Linear CRF to Chinese Word Segmentaion.

Introdution

We implemented a simple linear chain CRF(conditional random field), which can be used for Chinese word segmentation tasks. Also you can used it for other tagging tasks, such as POS(part of speech) Tagging, NER(name entity recognition) and so on.

Author

Jiang Xin(姜鑫) [email protected]
Li Bo(李博)
Li Zhenlong(栗正隆)

Performance

$$F1 = 2 * P * R / (P + R)$$

Corpus P R F1
msr 76.84263691915065 80.16949059509177 78.47081821412925
pku 89.23635340814322 88.86412962515287 89.04985254930146
weibo 71.06637402558087 72.00920245398773 71.53468175065706

License

This project is released under the MIT.

Preparation

First of all, clone the code

git clone https://github.com/VictorJiangXin/Linear-CRF.git

Then install all the python dependencies using pip:

pip install -r requirements.txt

How to use

root@:path$ python demo.py
>>> from segmentation import *
>>> ucas_seg = Segmentation() # also you can load your model ucas_seg = Segmentation('your_model')
>>> sentence = '今晚的月色真美呀。'
>>> ucas_seg.seg(sentence)

How to test

$ python test.py

You can change the test file by altering the path in test.py.

How to eval

$ cd utils
$ python eval.py

How to train

First, you need transform the corpus into this format.

今   B
晚   E
月   B
色   E
真   B
美   E
。   S


You can use src/utils/make_crf_trainset.py to convert your corpus.

Then, you have two kinds of ways to train your model.
You can use python to train your model. Python don't support multithreading, so this way will cost lots of time to train your model.

cd 'src'
python train.py # you can change the file path in train.py to change the corpus

Also you can use crf++ to train your model.

$ crf_learn -c 2 template ../data/pku_training.data -t crfpp.pku.model
$ python
>>> from crf import *
>>> model = LinearCRF()
>>> model.load_crfpp_model('crfpp.pku.model')

Others

Welcome to see myblog

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.