Coder Social home page Coder Social logo

pttrend's Introduction

Introduction

This project uses scikit Bayesian algorithms to determine if a particular PTT article is politics-related.

We first use the Python Jieba library to separate Chinese words (斷詞) , and extract words as features for Bayesian algorithm. (Each word is a feature.)

Basically, with Bayesian algorithm, we can know that if a feature likely indicates the entire article (which contains a lot of features) is politics-related. For instance, a article containing the word "民進黨" is somewhat likely to be politics-related, even further, if the article also contains words like "行政院", "立法院", "立委", "法條", it becomes highly likely that the article is politics-related.

We can know the degree of indication of each feature by extracting features and counting them in the training set. In the training set, there are lots of articles already labelled as politics-related or non politics-related. For example, in all politics-related articles in the training set, 90% of them contains "民進黨", then we know that "民進黨" is probably a political word, which means if an un-labelled article contains "民進黨", the article is likely to be politics related. But for words like "你們", it is likely that all articles, whether political or not, have about the same probablity of containing the word "你們", so it is a neutral word, we cannot infer from the word that if the article containing it is political.

Demo

http://pttrend.nctu.me:3000

Installation

On Ubuntu:

sudo apt install python3-pip python3-scipy python3-numpy
sudo pip3 install jieba sklearn

sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

Run

You can directly use our scraped PTT Gossiping articles, from ptt.db, if you would like to scrape the latest data, please run parser.rb.

Follow the steps to predict if a article is politics-related:

Hand-pick the training set

In ptt.db we have already labelled a small part of articles as politics-related or non-politics-related, so you can skip this step, but if you would like to make a bigger training set, you can use the script handpick_trainingset.py to manually label them.

Predict

Use pttrend.py to predict if you content is political. There are two ways to make predictions:

  1. Use -i command line option to read content from stdin and make prediction, for example:
echo "民進黨" | python3 pttrend.py -i
  1. Use -p [id] to read existing articles from the database and make prediction:
python3 pttrend.py -p 1000

pttrend's People

Contributors

yysung1123 avatar brycetsao avatar pellaeon avatar

Stargazers

Bill Cheng avatar

Watchers

 avatar  avatar Peter avatar

Forkers

yysung1123

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.