Case 1. Automatic contract parsing (Legal / CRM)

Token-classification pipeline for legal contract parsing

Install package: composer require codewithkyrian/transformers. This variant uses Xenova/bert-base-NER via TransformersPHP and runs NER over contract text.

 
<?php

include 'code-en.php';

if (
$nerError !== null) {
    echo 
'Warning: ' $nerError PHP_EOL;
    return;
}

echo 
$text;
echo 
PHP_EOL PHP_EOL '-----------' PHP_EOL PHP_EOL;

if (
$entities === []) {
    echo 
'No entities found.' PHP_EOL;
    return;
}

foreach (
$entities as $entity) {
    echo (
$entity['word'] ?? '') . ' -> ' . ($entity['entity'] ?? '') . PHP_EOL;
}
Result: Memory: 0.001 Mb Time running: < 0.001 sec.
This Agreement is made on March 12, 2025 between Apple Inc. and John Smith.
Apple Inc. agrees to provide software development services to the client.
The total amount of the agreement is $3,000,000.
The services will be delivered in London, United Kingdom.
The contract duration starts on March 12, 2025 and expires on March 12, 2027.

The agreement was approved by Michael Brown,
Legal Director of Apple Inc.

-----------

Apple -> B-ORG
Inc -> I-ORG
John -> B-PER
Smith -> I-PER
Apple -> B-ORG
Inc -> I-ORG
London -> B-LOC
United -> B-LOC
Kingdom -> I-LOC
Michael -> B-PER
Brown -> I-PER
Apple -> B-ORG
Inc -> I-ORG