Skip to content

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.

2 participants