Giter Site home page Giter Site logo

toxicdetectorsamplemlnet's Introduction

ML.NET - Toxic Sentiment Sample

This code example shows the use of ML.NET using sentiment detection for toxic or offensive messages. This can be integrated e.g. in chat applications.

Test Data

In this sample we use sample data of Kaggle: https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge/data

Due to licensing requirements, this sample does not contain that training data. These must be downloaded yourself and replaced with the train.csv file.

Usage

After the train.csv has been downloaded, the application can simply be started with dotnet run.

When started, the application is compiled and the model is trained. In my case, this takes around 5 seconds to generate the model; but can vary depending on processing power (especially CPU power).

PS C:\source\ba\ToxicDetectorSampleMLNET> dotnet run
=> create model context...
=> loading test data...
=> parsing test data...
=> create model partitions...
=> create binary classification pipeline...
=> model training...

When the model was created, it will be validated:

=> model validation...
=> metrics for binary classification
┌───────────────────────────────────┬─────────┐
│                              Name │ Value   │
├───────────────────────────────────┼─────────┤
│                          Accuracy │ 95,76 % │
│ Area Under Precision Recall Curve │ 84,38 % │
│              Area Under Roc Curve │ 96,42 % │
│                          F1 Score │ 74,15 % │
│                          Log Loss │ 0,18    │
│                Log Loss Reduction │ 0,61    │
│                Positive Precision │ 0,89    │
│                   Positive Recall │ 0,64    │
│                Negative Precision │ 0,96    │
│                   Negative Recall │ 0,99    │
└───────────────────────────────────┴─────────┘

Then you can enter your text to check for toxic content:

--------------------------------------------------
Text Input: Ben likes you

Predict Results:
┌─────────────┬───────────────┐
│        Name │ Value         │
├─────────────┼───────────────┤
│        Text │ Ben likes you │
│  Prediction │ Friendly :-)  │
│ Probability │ 20,68 %       │
│       Score │ -3,3611276    │
└─────────────┴───────────────┘
--------------------------------------------------

Dependencies

CSVHelper

The ML.NET CSV Reader is very basic and does not support all CSV scenarios. The standard ML NET CSV Reader unfortunately does not work with the CSV files of the Kaggle toxic comment data sample.

Therefore, the CSVHelper (https://github.com/JoshClose/CsvHelper) library is used.

spectre.console

https://github.com/spectreconsole/spectre.console for nicer console output

Thank you!

Please donate - if possible - to necessary institutions of your choice such as child cancer aid, children's hospices etc. Thanks!

toxicdetectorsamplemlnet's People

Contributors

benjaminabt avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

a8962383

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.