matrix-spam-ml

git clone git://archive.git.mtrnord.blog/MTRNord/matrix-spam-ml.git
Log | Files | Refs | Submodules | README | LICENSE

README.md (2574B)


      1 # Matrix-Spam ML
      2 
      3 This project consists of tooling to generate a spam detection model for the Matrix protocol.
      4 
      5 It utilizes Tensorflow and builds the model in python and then provides a Rust server that provides some APIs to interact with the model easily and also extend it.
      6 
      7 The current code base is fast moving. Expect to change rapidly.
      8 
      9 ## Usage
     10 
     11 ### Training
     12 
     13 To train the model, you need to have a set of labeled data.
     14 This data is at `./input/MatrixData`. It is a TSV file.
     15 
     16 To train the model, run `python3 model_v2.py`. This will train the model and save it to `./model/`.
     17 Please make sure you installed tensorflow.
     18 
     19 #### Notes about the data
     20 
     21 Please ensure to remove all urls, html tags and new lines. Also make sure to strip duplicate whitespace.
     22 All of these reduce accuracy easily.
     23 
     24 ### Running the server
     25 
     26 To run the server, run `cargo run --release`. This will start the server on port `3000`.
     27 
     28 If you dont see any log try preprending `RUST_LOG=info` to the command.
     29 
     30 ## API
     31 
     32 ### POST /test
     33 
     34 This endpoint takes a JSON body with the following format:
     35 
     36 ```json
     37 {
     38     "input_data": "This is a message to be classified"
     39 }
     40 ```
     41 
     42 It will return a JSON response with the following format:
     43 
     44 ```json5
     45 {
     46     "input_data": "This is a message to be classified",
     47     "score": 1.1349515e-24, // Note that this is a float
     48 }
     49 ```
     50 
     51 You do not have to strip urls like in the training data. However it might yield better results if you strip the html tags.
     52 
     53 ## Ethical use/How the usage of the model is intended
     54 
     55 The model is trained mainly on SMS and matrix spam.
     56 It is not curently checked for racism or other discrimination factors against other groups.
     57 It is also at this time not checked how exactly it reacts to various scenarios.
     58 Therefor please keep this in mind while using the model.
     59 
     60 Additionally the model was designed as a warning systems for admins and not as an automod.
     61 This is important as a warning system has a lot wider tollerances while an automod should be very certain to take actions against people.
     62 
     63 While following this paragraph isnt mandatory I hope you keep it in mind and use this model ethically and not for discrimination in the network.
     64 
     65 ## Future Plans
     66 
     67 - [ ] Mjolnir plugin/patch for collecting spam and using it to retrain the model.
     68 - [ ] Balancing the sample data
     69 - [ ] Synapse Plugin to use as an automute bot across the whole HS.
     70 - [ ] Mjolnir plugin that allows applying the suggestions
     71 
     72 ## Support
     73 
     74 For support you can join [#matrix-spam-ml:midnightthoughts.space](https://matrix.to/#/#matrix-spam-ml:midnightthoughts.space) on Matrix.