Coder Social home page Coder Social logo

wanabprgmr / fake-news-detection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aldengolab/fake-news-detection

0.0 0.0 0.0 414 KB

Final Project for CAPP 30255 Advanced Machine Learning for Public Policy

License: MIT License

Python 62.29% Jupyter Notebook 37.17% Shell 0.54%

fake-news-detection's Introduction

fake-news-detection

Final Project for CAPP 30255 Advanced Machine Learning for Public Policy
Lauren Dyson & Alden Golab, Winter 2017

You can find the final summary for this project in the main directory.

Dependencies

  • python 3.x
  • nltk
  • numpy
  • sklearn
  • scipy
  • pandas
  • spacy

We have included a conda environment yaml. To install, run:

    conda env create -f environment.yml

Data

This project is using a dataset published by Signal Media in conjunction with the Recent Trends in News Information Retrieval 2016 conference to facilitate conducting research on news articles. We use OpenSources.co to distinguish between 'legitimate' and 'fake' news sources.

Feature Generation

From the raw article text, we generate the following features:

  1. Vectorized bigram Term Frequency-Inverse Document Frequency, with preprocessing to strip out named entities (people, places etc.) and replace them with anonymous placeholders (e.g. "Donald Trump" --> "-PERSON-"). We use Spacy for tokenization and entity recognition, and SkLearn for TFIDF vectorization.
  2. Normalized frequency of parsed syntacical dependencies. Again, we use Spacy for parsing and SkLearn for vectorization. Here is an excellent interactive visualization of Spacy's dependency parser.

Pipeline

The pipeline contains four sets of python code:

  • model.py: a class for models
  • model_loop.py: a class for running a loop of classifiers; takes test-train data splits and various run params
  • run.py: this code implements the model_loop class; it also implements our re-sampling of the data
  • transform_features.py: this file executes all feature generation

Running the code is done through run.py with the following options:

  1. --models: models to run

  2. --iterations: number of tuning parameter iterations to run per model

  3. --output_dir: a directory name to store the output; system will create the directory

  4. --dedupe: whether to look for and remove duplicate content

  5. --features: which feature set to run with, options include:

    • both_only: runs both PCFG and TFIDF
    • grammar_only: runs only PCFG
    • tfidf_only: runs only TFIDF
    • all: runs all the above

Example Pipeline Run

To execute the pipeline with Logistic Regression and Stochastic Gradient Descent, navigate to the pipeline directory, run:

source activate amlpp
python run.py /path/to/data --models LR SGD --iterations 50 --output_dir run_name --dedupe --reduce 500 --features both_only

This is encapsulated in the run.sh file.

The first argument is the path to the input datafile. The pipeline assumes that the text of each article is unique. If your texts are not unique, use the flag --dedupe to automatically remove duplicated articles during preprocessing. To see a description of all arguments, run:

python run.py --h

A simple report on the models run with basic evaluation metrics will be output to the output/ directory (unless another output directory is specified).

License

MIT License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

fake-news-detection's People

Contributors

aldengolab avatar ladyson avatar ldyson 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.