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

Add TrafilaturaExtractor class #431

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sarahyurick
Copy link
Collaborator

Closes #400.

Signed-off-by: Sarah Yurick <[email protected]>
Signed-off-by: Sarah Yurick <[email protected]>
Comment on lines +99 to +101
expected = [
"Let's keep this paragraph: either came does last new took taken making became from.",
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Trafilatura has a really bad bug where it is returning the string twice. I can double check all of my logic, but in the case that this is a Trafilatura-specific issue, I am debating whether I should add our own exact deduplication code into this.

(Trafilatura actually has their own deduplicate parameter here, but it did not fix this use case.)

Possible related issue: adbar/trafilatura#634

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 have not scoped to see what conditions cause this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another issue: adbar/trafilatura#768

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Solved by adding support for these extraction and deduplication parameters: https://trafilatura.readthedocs.io/en/latest/settings.html.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like an issue customers might run into. Have you looked in papers and such for good default values? If Trafilatura's defaults aren't good (or aren't used by most researchers), it could be good to substitute our own.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I can look into it. At the very least, I think setting deduplicate=True as the default in NeMo Curator might be a good idea. Otherwise, I think we could make sure to emphasize these parameters in the documentation.

@sarahyurick sarahyurick marked this pull request as ready for review December 13, 2024 23:50
Copy link
Collaborator

@ryantwolf ryantwolf left a comment

Choose a reason for hiding this comment

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

A few minor things, looks good overall.

@@ -128,15 +131,15 @@ You can choose to modify the HTML text extraction algorithm used in ``download_c
if __name__ == "__main__":
main()

Above, we changed the extraction algorithm from the default ``JusTextExtractor``.
Above, we changed the extraction algorithm from the default ``JusTextExtractor``. **Note:** Please see the Trafilatura documentation `here <https://trafilatura.readthedocs.io/en/latest/settings.html>`_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should the user see the Trafilatura documentation?

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 think this was a lingering comment meant to explain what the different Trafilatura-specific parameters mean. I will remove it in favor of the class docstring suggested below.

@@ -200,6 +203,98 @@ def extract_text(self, html, stop_words):
return result


class TrafilaturaExtractor(HTMLExtractorAlgorithm):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a class level docstring explaining what trafilatura is?

Comment on lines +99 to +101
expected = [
"Let's keep this paragraph: either came does last new took taken making became from.",
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like an issue customers might run into. Have you looked in papers and such for good default values? If Trafilatura's defaults aren't good (or aren't used by most researchers), it could be good to substitute our own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Trafilatura text extraction
2 participants