Code Monkey home page Code Monkey logo

adfinder's Introduction

Adfinder

Tool to identify Wikipedia articles that might have a promotional bias.

.NET Core

Screenshot of popup

Code overview

There are two main parts to this repository. The first is the backend.

There are 5 projects in the solution:

  • Preprocessor: Get all of the articles for the dataset and store them as JSON files.
  • MLNETFormatter: Merge the JSON files from Preprocessor into one dataset file (TSV format) to use with ML.NET
  • WebService: Run an API where you send the article content to it and get back whether or not it is promotional, along with a confidence score.
  • ModelAccess: Contains all of the logic for getting predictions from the model.
  • MLModel: Contains the ModelInput and ModelOutput classes, as well as the model zip file.

The second part of this repository is a Firefox extension, which has three main parts:

  • A background script that sends a message to the content script when the page finishes loading (it also handles loading the settings)
  • A popup that opens when you click the icon in the browser toolbar and allows you to change the settings
  • A content script that sends a POST to the API to get the score of the article and if necessary add the popup (the notification that the page is promotional, not the above item) to the page

There is also a Chrome extension that is mostly the same as the Firefox extension, there's just a few small tweaks I made to get it working in Chrome.

There is another branch, MLNETFormatter-shorten-articles, that includes a version of MLNETFormatter that saves only the first 3 sections of articles and a trained model using the dataset that this produced. I tried this in hopes that it could improve the accuracy, but it did not help, in some cases making it worse.

Usage

The GitHub repository includes a pre-trained model, but if you would like to re-train it, follow these steps:

  1. Make sure you have .NET Core 3.1 and 2.1 installed, as well as the ML.NET CLI.
  2. cd into the Preprocessor directory, and run dotnet run. This will download all of the articles for the dataset, and it might take a few hours. This will consume about 800 megabytes of storage.
  3. Note the path to the dataset directory that was created. cd into the MLNETFormatter directory, and run dotnet publish. Once that's done, cd into the bin/Debug/netcoreapp3.1 directory, and run ./MLNETFormatter [path to dataset directory]. This will merge all of the JSON files created by Preprocessor into one TSV file, and will consume about 700 megabytes of storage.
  4. Run mlnet auto-train --task binary-classification --dataset "your-dataset-tsv-file.tsv" --label-column-name "Category" --max-exploration-time 3600, replacing 3600 with however much time you have (in seconds) for it to explore different algorithms. This will give you a new directory called "SampleBinaryClassification."
  5. If mlnet chose the LightGBMBinary algorithm, you can just replace the MLModel.zip file in the MLModel project with the new generated model file. However, if it did not choose this algorithm, you will need to update the ModelBuilder.cs file in the ModelAccess project with the new methods from the new ModelBuilder.cs file.
  6. cd to the Adfinder directory and run dotnet publish --configuration Release. To start the API, cd to WebService/bin/Release/netcoreapp3.1 and run ./WebService.

To help with developing the Firefox extension, I use Mozilla's web-ext tool. This will automatically reload the extension whenever you modify a file.

API

By running WebService, you get an API at https://localhost:5001/MLLookup that you can post an articleTitle to. This will send back a score, with a lower value meaning it is more confident that the article is promotional.

adfinder's People

Contributors

merlin04 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.