Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preemptively filter out Rekognition tags #4667

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

AetherUnbound
Copy link
Collaborator

Fixes

Fixes #4644 by @AetherUnbound

Description

This PR adds an additional layer of filtering during the "tags cleanup" step of the (current) ingestion server which filters out tags that correspond to a specific provider. For the time being, only rekognition tags are filtered.

Testing Instructions

I have been having some trouble getting ov to run these commands, but it might just be my desktop.

Running just ingestion_server/test-local should run the tests, which all should pass!

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (ov just catalog/generate-docs media-props
    for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@AetherUnbound AetherUnbound requested a review from a team as a code owner July 29, 2024 22:14
@AetherUnbound AetherUnbound requested review from krysal and obulat and removed request for a team July 29, 2024 22:14
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon 🌟 goal: addition Addition of new feature 💻 aspect: code Concerns the software code in the repository 🧱 stack: ingestion server Related to the ingestion/data refresh server 🧱 stack: catalog Related to the catalog and Airflow DAGs labels Jul 29, 2024
@@ -133,12 +136,14 @@ def cleanup_tags(tags):
if not tags:
return None
for tag in tags:
below_threshold = False
alt_filtered = False
Copy link
Contributor

Choose a reason for hiding this comment

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

This code has been bothering me for a long time because it's difficult to understand all branches. What if we convert it to something like this:

if not isinstance(tag.get("name"), str) or "accuracy" in tag and float(tag["accuracy"]) < TAG_MIN_CONFIDENCE or
tag.get("provider") in TAG_SKIP_PROVIDERS:
    should_filter = True
else:
    lower_tag = tag["name"].lower()
    should_filter = _tag_denylisted(lower_tag)

This will also be a bit better for performance because if the tag is {}, we won't check for it's provider and accuracy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good question - hopefully this code is going away long-term, but I'll try and see if I can simplify/optimize it without spending too much time on it :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking at this again, we log specifically if the tag is malformed based on the current set of conditions, but then don't log anything if it just gets filtered. So I think, given this will eventually be revised, I'll just leave it as-is for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to log that? Malformed in this case means that a tag is either not a dictionary or doesn't have a string name value, right?
I think we've already removed those from the catalog db, haven't we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right that I think we have - that said, I'm already working on #4541 and have altered the logic in these steps anyway for that change. If you have a blocking objection here than I can change it, otherwise I'd rather wait until we have to rework these cleanup steps entirely as part of the data refresh removal!

@@ -55,6 +55,9 @@
# Filter out low-confidence tags, which indicate that the machine-generated tag
# may be inaccurate.
TAG_MIN_CONFIDENCE = 0.90
# Filter out tags that match the following providers (either because they haven't
# been vetted or because they are known to be low-quality).
TAG_SKIP_PROVIDERS = {"rekognition"}
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is kind of confusing to me. Could we change it to something like
EXCLUDED_TAG_PROVIDERS or FILTERED_TAG_PROVIDERS ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had the hardest time naming this 😆 I wanted TAG at the front to match the previous constant, but this fits much better!

Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

I tested faking some recognition tags in the catalog, then ran a data refresh, and they were successfully removed on the API DB 👍 Nice!

@AetherUnbound AetherUnbound merged commit 5ccf7ff into main Aug 12, 2024
48 checks passed
@AetherUnbound AetherUnbound deleted the feature/filter-rekognition branch August 12, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🌟 goal: addition Addition of new feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: catalog Related to the catalog and Airflow DAGs 🧱 stack: ingestion server Related to the ingestion/data refresh server
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Preemptively filter the Rekognition tags
4 participants