Skip to content

Add AI engine for spam#11319

Merged
andreslucena merged 134 commits intodecidim:developfrom
i-need-another-coffee:ale-add-spam-detection
Oct 16, 2024
Merged

Add AI engine for spam#11319
andreslucena merged 134 commits intodecidim:developfrom
i-need-another-coffee:ale-add-spam-detection

Conversation

@alecslupu
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu commented Jul 22, 2023

🎩 What? Why?

This PR adds the spam detection mechanism, created in a stand alone bundle that can be installed also in older decidim installations. Please refer to decidim-tools-ai/Readme.md for configuration details.

📌 Related Issues

Link your PR to an issue

Testing

  1. Follow the installation instructions in the readme file
  2. Index the data
  3. Create some content and check to see if it get's marked as spam

📷 Screenshots

Please add screenshots of the changes you're proposing
Description

alecslupu added 26 commits July 13, 2023 19:00
Add Gitlab action workflow

Patch the generator

Running linters

Gemfiles
Add language service
Normalize gems
* Add BayesStrategy

* Add Bayes Analyzer

* Refactor strategy intialization process
* Add BayesStrategy

* Add Bayes Analyzer

* Refactor strategy intialization process
* Add event handlers and spec data

* Fixing failng specs

* Fix Catgeory error in untrain

* fix decidim ai tests
* Add Strategy module

* Add more namespaces
* Add resources to be analyzed

* mend
@ahukkanen
Copy link
Copy Markdown
Contributor

@andreslucena No need on my end. Last time the technical implementation seemed fine.

Only thing to add is that as I have written in some of the previous reviews, I would not feed the classifier constantly with the moderated data as "spam". For example, in the instances we manage, spammers are using actual other people's comments and injecting their spam in those. When the classifier gets fed this data as "spam", it will eventually start to classify genuine content as SPAM with higher probability.

I have written more details in the broader context of solving the SPAM issue at #10038. For content classification engine, this implementation is fine (but would require more pre-training data to actually work well).

@andreslucena
Copy link
Copy Markdown
Member

I have written more details in the broader context of solving the SPAM issue at #10038. For content classification engine, this implementation is fine (but would require more pre-training data to actually work well).

Wow, I actually missed those comments. Great job with researching this topic!

So,for mitigating the problems that Antti found, and to merge this without future issues, we'd need to:

  1. Remove the current datasets, as we don't have the good numbers of contents to this actually be useful
  2. To remove the feature of training with the new moderations, as the spammers are using "good" content, so we will start having lots of false positives

Can you do that @alecslupu? Thanks

Then, after this PR is (finally) merge, we can focus on the other aspects of the "Steps forward" explanation from #10038 (comment)

@alecslupu
Copy link
Copy Markdown
Contributor Author

To remove the feature of training with the new moderations, as the spammers are using "good" content, so we will start having lots of false positives

I am not sure what you mean by this.

@alecslupu
Copy link
Copy Markdown
Contributor Author

Remove the current datasets, as we don't have the good numbers of contents to this actually be useful

Done in f3b8f48

github-actions[bot]
github-actions bot previously approved these changes Oct 15, 2024
@andreslucena
Copy link
Copy Markdown
Member

To remove the feature of training with the new moderations, as the spammers are using "good" content, so we will start having lots of false positives

I am not sure what you mean by this.

I forgot how this actually works to be honest xD

This is a manual task that need to be done by the admin. According to what Antti is mentioning in its comment, spammers are reusing actual contents to "confuse" these kinds of filters. We can leave it in for now, but once we have the new datasets for moderations we can review this approach (i.e. remove this task if it isn't necessary and could be counterproductive)

github-actions[bot]
github-actions bot previously approved these changes Oct 16, 2024
alecslupu and others added 2 commits October 16, 2024 10:13
Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
github-actions[bot]
github-actions bot previously approved these changes Oct 16, 2024
github-actions[bot]
github-actions bot previously approved these changes Oct 16, 2024
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏽 👏🏽

Thanks for your patience on this long standing PR!

@ahukkanen
Copy link
Copy Markdown
Contributor

I forgot how this actually works to be honest xD

This is a manual task that need to be done by the admin.

@andreslucena To me it doesn't seem manual:

Decidim::EventsManager.subscribe("decidim.update_account:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.update_user_group:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.create_user_group:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.admin.block_user:after") do |_event_name, data|
Decidim::Ai::SpamDetection::TrainUserDataJob.perform_later(data[:resource])
end

Decidim::EventsManager.subscribe("decidim.admin.hide_resource:after") do |_event_name, data|
Decidim::Ai::SpamDetection::TrainHiddenResourceDataJob.perform_later(data[:resource])
end

The classifier is always fed the moderated content automatically when it is hidden from the website.

@andreslucena
Copy link
Copy Markdown
Member

@andreslucena To me it doesn't seem manual:

You're right!

@alecslupu can you remove what Antti is mentioning, please?

@alecslupu
Copy link
Copy Markdown
Contributor Author

@ahukkanen the part you initially mentioning:

Decidim::EventsManager.subscribe("decidim.update_account:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.update_user_group:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.create_user_group:after") do |_event_name, data|
Decidim::Ai::SpamDetection::UserSpamAnalyzerJob.perform_later(data[:resource])
end
Decidim::EventsManager.subscribe("decidim.admin.block_user:after") do |_event_name, data|
Decidim::Ai::SpamDetection::TrainUserDataJob.perform_later(data[:resource])
end

Is actually the part that submits the data to be analyzed. It does not do the training of spam / ham.

The following is the one that automatically adds the data hidden by admin to spam base.

Decidim::EventsManager.subscribe("decidim.admin.hide_resource:after") do |_event_name, data|
Decidim::Ai::SpamDetection::TrainHiddenResourceDataJob.perform_later(data[:resource])
end

@alecslupu
Copy link
Copy Markdown
Contributor Author

I will remove only this bit.

Decidim::EventsManager.subscribe("decidim.admin.hide_resource:after") do |_event_name, data|
Decidim::Ai::SpamDetection::TrainHiddenResourceDataJob.perform_later(data[:resource])
end

@ahukkanen
Copy link
Copy Markdown
Contributor

Is actually the part that submits the data to be analyzed. It does not do the training of spam / ham.

Partially correct but at the very bottom of the snippet there is logic that trains the user profile classifier with the blocked user's data.

@alecslupu
Copy link
Copy Markdown
Contributor Author

Is actually the part that submits the data to be analyzed. It does not do the training of spam / ham.

Partially correct but at the very bottom of the snippet there is logic that trains the user profile classifier with the blocked user's data.

tackled here: #13550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration dependencies Pull requests that update a dependency file or issues that talk about updating dependencies module: ai

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Use content classification systems for better SPAM detection

7 participants