Python

Installation

Install the package via the Python package manager pip
1
>> $ pip install lucidtech-las
Copied!

Make a prediction on a document

Suppose we wish to run inference on a document using Lucidtech’s invoice model.
1
from las import Client
2
3
client = Client()
4
document = client.create_document('invoice.pdf', 'application/pdf')
5
prediction = client.create_prediction(document['documentId'], 'las:model:<hex>')
6
7
print(prediction)
Copied!

Set ground truth of document

When uploading data that will be used for training and evaluation, we need to provide a ground truth.
1
from las import Client
2
3
client = Client()
4
ground_truth = [
5
{'label': 'total_amount', 'value': '240.00'},
6
{'label': 'due_date', 'value': '2020-01-31'}
7
]
8
document = client.create_document('invoice.pdf', 'application/pdf', ground_truth=ground_truth)
Copied!

Update an existing document

If for instance a prediction reveals incorrect values in the ground truth of a document, we can update the existing document with new ground truth values.
1
document = client.update_document('las:document:<hex-uuid>', ground_truth=ground_truth)
Copied!
Providing ground truth is a necessary to re-train a model whether the model got it right or wrong. So always provide the ground truth if it is available.

Create a document with consent id

Consent ID is an identifier you can assign to documents to keep track of document ownership for your customers.
1
from las import Client
2
3
client = Client()
4
document = client.create_document('invoice.pdf', 'application/pdf', consent_id='las:consent:<hex>')
Copied!

Revoking consent and deleting documents

Suppose we wish to delete all documents associated with a customer in our ERP database or other systems. We need to provide a consent_id to the prediction method that uniquely identifies the customer and use that consent_id to delete documents.
1
from las import Client
2
3
client = Client()
4
consent_id = 'las:consent:<hex>'
5
document = client.create_document('invoice.pdf', 'application/pdf', consent_id=consent_id)
6
client.delete_documents(consent_id=consent_id)
Copied!

Create a batch and associate a few documents with it

Creating a batch is a way to group documents. This is useful for specifying batches of documents to use in improving the model later.
1
from las import Client
2
3
client = Client()
4
batch = client.create_batch(name='Invoices2020F', description='invoices from fall 2020')
5
client.create_document('invoice.pdf', 'application/pdf', batch_id=batch['batchId'])
6
client.create_document('invoice2.jpeg', 'application/pdf', batch_id=batch['batchId'])
Copied!
Last modified 5mo ago