Tool to identify Wikipedia articles that might have a promotional bias.
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.
The GitHub repository includes a pre-trained model, but if you would like to re-train it, follow these steps:
- Make sure you have .NET Core 3.1 and 2.1 installed, as well as the ML.NET CLI.
cd
into thePreprocessor
directory, and rundotnet 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.- Note the path to the dataset directory that was created.
cd
into theMLNETFormatter
directory, and rundotnet publish
. Once that's done,cd
into thebin/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. - 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." - If
mlnet
chose theLightGBMBinary
algorithm, you can just replace theMLModel.zip
file in theMLModel
project with the new generated model file. However, if it did not choose this algorithm, you will need to update theModelBuilder.cs
file in theModelAccess
project with the new methods from the newModelBuilder.cs
file. cd
to theAdfinder
directory and rundotnet publish --configuration Release
. To start the API,cd
toWebService/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.
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.