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.
This commit is contained in:
evazion
2022-06-27 19:29:33 -05:00
parent fb926a1bd2
commit c4498f9be7

View File

@@ -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)