code: def test_layoutlm(self):
      activations_path = os.path.join(
          os.path.abspath(os.path.dirname(__file__)),
          "data",
          "test-layoutlm-activations.jl",
      )
  
      def subset_doc(doc):
          """Take approximately the first 512 tokens from just the first page"""
          for page in doc:
              page["tokens"] = page["tokens"][:60]
              page_idx_end = page["tokens"][-1]["page_offset"]["end"]
              page["pages"][0]["text"] = page["pages"][0]["text"][
                  :page_idx_end
              ]
              page["pages"][0]["doc_offset"]["end"] = (
                  page["pages"][0]["doc_offset"]["start"] + page_idx_end
              )
              return [page]
  
      with open("tests/data/test_ocr_documents.json", "rt") as fp:
          documents = json.load(fp)
      documents = [subset_doc(doc) for doc in documents]
      finetune_model = DocumentLabeler(base_model=LayoutLM)
      expected_all = jl.load(activations_path)
      for doc, expected in zip(documents, expected_all):
          finetune_seq_features = finetune_model.featurize_sequence(
              [doc]
          )
          np.testing.assert_array_almost_equal(
              finetune_seq_features,
              expected,
              decimal=1,
          )
  
imports: import os
  import json
  import unittest
  import numpy
  import pytest
  import tensorflow
  import joblib
  from transformers import AutoTokenizer, TFAutoModel, BertTokenizer
  from finetune import SequenceLabeler, DocumentLabeler
  from finetune.base_models import LayoutLM
  from finetune.base_models.huggingface.models import HFBert, HFElectraGen, HFElectraDiscrim, HFXLMRoberta, HFT5, HFAlbert, HFDebertaV3Base
  from finetune.target_models.seq2seq import HFS2S
  from sklearn.model_selection import train_test_split
  from finetune.encoding.sequence_encoder import finetune_to_indico_sequence
label_desc: Use image node_id 12 for calling the TestHuggingFace obj's underlying member method code with example usage: obj.test_layoutlm() and returns: list