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

Huggingface multi-modal transformers #15

Merged
merged 7 commits into from
Jul 27, 2023
Merged

Huggingface multi-modal transformers #15

merged 7 commits into from
Jul 27, 2023

Conversation

percevalw
Copy link
Member

@percevalw percevalw commented Jul 7, 2023

Description

This PR introduces a new HuggingfaceEmbedding component, which wraps Huggingface models (such as LayoutLM or LILT). Compared with using the raw huggingface model, this wrapper offers a simple mechanism for splitting long documents into sliding windows before sending them to the model (since the maximum number of tokens sent to the transformer is capped at 512, and sending entire sequences all at once can be memory-intensive).

Example

Here is an example of how to define a pipeline with the HuggingfaceEmbedding component:

from edspdf import Pipeline

pipeline = Pipeline()
pipeline.add_pipe("pdfminer-extractor", name="extractor")
pipeline.add_pipe(
    "huggingface-embedding",
    name="embedding",
    config={
        "model": "microsoft/layoutlmv3-base",
        "use_image": False,
        "window": 128,
        "stride": 64,
        "line_pooling": "mean",
    },
)
model.add_pipe(
    "trainable-classifier",
    name="classifier",
    config={
        "embedding": model.get_pipe("embedding"),
        "labels": [],
    },
)

This model can then be trained following the training recipe.

  • If this PR is a bug fix, the bug is documented in the test suite.
  • Changes were documented in the changelog (pending section).
  • If necessary, changes were made to the documentation.

@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@9ca8fd0). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #15   +/-   ##
=======================================
  Coverage        ?   94.78%           
=======================================
  Files           ?       32           
  Lines           ?     1974           
  Branches        ?        0           
=======================================
  Hits            ?     1871           
  Misses          ?      103           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@percevalw percevalw force-pushed the huggingface branch 2 times, most recently from dd51e50 to ac46ac1 Compare July 27, 2023 12:09
@percevalw percevalw merged commit 18d7ace into main Jul 27, 2023
@percevalw percevalw deleted the huggingface branch July 27, 2023 14:03
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.

1 participant