Input data format for simpletransformers.ai LayoutLM models

Viewed 303

I am working on this demo. The input data is like this:

enter image description here

The model's code is the following:

model = ClassificationModel(
    "layoutlm", 
    "microsoft/layoutlm-base-uncased",
    num_labels=2,
    use_cuda=True,
    cuda_device = 0
)

predictions, raw_outputs = model.predict(['test data abc'])

but it returns this error:

File "/mnt/data/home/tvkhuong/Data/SOFT/anaconda3/envs/classify/lib/python3.7/site-packages/simpletransformers/classification/classification_model.py", line 1708, in load_and_cache_examples
    example.label = self.args.labels_map[example.label]
AttributeError: 'list' object has no attribute 'label'

How can I correctly define the model inputs in order to get the predictions?

1 Answers

LayoutLM model is usually used in cases where one needs to consider the text as well as the layout of the text in the image. Unlike simple Machine Learning models, model.predict() won't get you the desired results here.

The model needs to be trained on your training data comprising of the information of the texts, the labels and the bounding boxes for each image in training dataset first so as to learn the images under mentioned labels. You would also require a tokenizer associated with your model before moving ahead.

Refer the documentation for more info: https://huggingface.co/transformers/model_doc/layoutlm.html

Related