From c4498f9be7e09ac42fc8c2bbf8c7192cbdf0559b Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 27 Jun 2022 19:29:33 -0500 Subject: [PATCH] ai tags: allow searching for ai:monochrome,0% Allow searching for e.g. `ai:monochrome,0%` to find posts where the AI has 0% confidence the post should be tagged monochrome. This is useful for finding mistagged posts. You can search `monochrome ai:monochrome,0%` to find posts that are potentially mistagged as monochrome, that is, posts that are tagged monochrome but where the AI has 0% confidence that it should be tagged monochrome. Not all cases will be mistags. The majority will be cases where the AI failed to identify the tag. This is also useful for studying the AI's failures. --- app/models/post.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 333609ea5..52014a443 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1315,8 +1315,13 @@ class Post < ApplicationRecord tag = Tag.find_by_name_or_alias(name) return none if tag.nil? - ai_tags = AITag.joins(:media_asset).where(tag: tag).where_numeric_matches(:score, confidence) - where(ai_tags.where("media_assets.md5 = posts.md5").arel.exists) + if confidence == "0" + ai_tags = AITag.joins(:media_asset).where(tag: tag) + where.not(ai_tags.where("media_assets.md5 = posts.md5").arel.exists) + else + ai_tags = AITag.joins(:media_asset).where(tag: tag).where_numeric_matches(:score, confidence) + where(ai_tags.where("media_assets.md5 = posts.md5").arel.exists) + end end def uploader_matches(username)