6
$\begingroup$

I think about a system which gets XML documents in various structures but with essentially the same data structure in it. For the example, let's assume each document contains data about one or more persons. So the AI would recognize a name. Somewhere else in the document there is the post address of our fictional person. The AI should now "see" the address and conclude, it belongs to our person. Anywhere else, there is a phone number in the document. Again, our AI should see the connection between our person and this phone number.

This wouldn't be a job for an AI if there wasn't a catch. If the task was merely to find and map strings like addresses and phone numbers, we could simply use a regex to match our "target strings". The catch in this scenario would be this: the XML document might contain other data, which does not belong to our person but is a valid phone number for example and thus will match an regex.

Would it be possible for an AI to learn this? If yes, with which framework would someone create such an AI?


Sample XML document:

<?xml version="1.0" encoding="utf-8" ?>
<document>
    <data>
        <foo>
            <bar>
                <person>
                    <name>John Doe</name>
                </person>
            </bar>
            <address>
                <street>Main street 1</street>
                <city>1111 Twilight town</city>
                <country>sample country</country>
            </address>
            <phone>+123 123 123</phone>
        </foo>
        <foo>
            <bar>
                <person>
                    <name>Jane Doe</name>
                </person>
            </bar>
            <address>
                <street>Broadway 42</street>
                <city>4521 Traverse town</city>
                <country>sample country</country>
            </address>
            <phone>+123 412123</phone>
        </foo>
    </data>
    <creator>
        <!-- Note: While this looks like a valid person, -->
        <!-- this data should not be matched by the AI -->
        <name>Sam Smith</name>
        <office>
            <street>Seaside road 5</street>
            <city>4521 Traverse town</city>
            <country>sample country</country>
        </office>
        <phone>+123 555 555</phone>
    </creator>
</document>
$\endgroup$
9
  • 4
    $\begingroup$ The first question I'd ask is "can a human make the distinction you're asking about, and how?" $\endgroup$
    – mindcrime
    Commented Sep 1, 2017 at 18:08
  • $\begingroup$ Welcome to AI! (I very much like mindcrime's comment, b/c I know how I'd go about validating the information, and suspect an AI could do it much more quickly.) $\endgroup$
    – DukeZhou
    Commented Sep 1, 2017 at 18:27
  • 1
    $\begingroup$ I'm guessing that what you really want is an AI that, given an arbitrary XML schema, can guess which elements/attributes the data you want is going to be encoded in. So to train your AI, you would need a large number of different schemas with the correct elements already tagged. $\endgroup$
    – antlersoft
    Commented Sep 1, 2017 at 18:55
  • $\begingroup$ @mindcrime The human can make the distinction between, because the data belonging together would be more or less under the same parent. I updated my question with a sample XML. As you can see, the data about one person is below the <foo> parent. For humans it's clear that each <foo> represents one person. $\endgroup$
    – DBX12
    Commented Sep 2, 2017 at 11:19
  • $\begingroup$ @antlersoft That was my initial idea. I think I have enough XML schemas at hand (otherwise I will generate some via script from sample data). My line of thought was "Humans can learn to differentiate that. AI can learn like humans so AI should be able to learn this too". But then the question "how to start and are there frameworks?" rose, resulting in this question, $\endgroup$
    – DBX12
    Commented Sep 2, 2017 at 11:23

2 Answers 2

6
$\begingroup$

XML, HTML and less formal languages all respond quite nicely to being transformed or interrogated within a graph framework. XML and HTML are particularly useful in that they conform strictly to a tree-structure. That means that any good data components can be measured in terms of tree-distance to any other "good" data components.

If you extract your regex-friendly terms and keep track of where within their tree they are found, you may be able to cast those values into a general document-space vector (it might only need to be one-dimensional), allowing you to identify clusters of "good" vs anomalous sections of "bad" data based on a simple distance metric, or anomaly detection algorithm - say an isolation-forest that runs on information density for example.

This depends on your data, and how much of it you can find, ideally already tagged up containing good vs bad.

If you're looking to scrape reliable address-contents, then yes, you're likely to score hits on names, addresses, postcodes and phone-numbers all appearing as tightly connected clustered groups, all within one or two nodes-distance from one another.

Meanwhile, an annotation containing a phone number lodged somewhere else is less likely to be a match.

Different documents will have different threshold densities, and differing anomaly to conformant ratios, so you'd have a task on your hands to figure out some way to automatically tune your parameters on any given document set.

In the past, I've tried doing this against html by flattening all the content into a single string of text and a similar approach yielded half-decent results, but if you're looking at XML, it's fair to expect the structure to yield more information.

$\endgroup$
2
  • $\begingroup$ Thanks for the answer.Do you have any good graph frameworks as starting point? I'm pretty new to machine learning, so a few pointers into the right direction would be highly appreciated. $\endgroup$
    – DBX12
    Commented Sep 30, 2017 at 12:41
  • $\begingroup$ I use python a lot for things like this, and networkx is a fantastic graph-framework. I might use of of the xml parsing modules discussed here to parse and marshal the content, perhaps pushing that into a networkx graph for the added analytical flexibility that might give you. $\endgroup$ Commented Sep 30, 2017 at 14:34
2
$\begingroup$

You would need to define 'frames', 'templates', or sets of data belonging together to form an address or other kind of data, with typical labels. So phone or tel etc would indicate a phone number, provided that their content also looks like a phone number. That's how you as a human recognise it. So you encode your domain knowledge as entities with possible attributes. Then you try and match the attributes and recognise which entity they belong to. You could have several entities with a shared subset of attributes (like a company or a person, which would both have an address). There would be other clues to tell you which it is. If name ends in "Ltd." or "Co", then it'll be a company, for example.

So you mix heuristics for identifying attributes, templates of which attributes combine to form an entity class you want to identify, and then pick the one that best matches. If you have several entities where all that's filled is phone, then you can't really tell what it is and would discard it. In your example, name matches various entities, but office would not be a valid attribute for a person (unless you decided it was). An oversimplistic heuristic might think "Sam Smith" is a company, which presumably has an office attribute, so you need to be careful with how you design your templates.

A criterion for putting attributes together could be that they are in the same subtree of the data structure. The exact definition really depends on the data and the types of information you want to extract from it.

So yes, it is definitely possible. I'm not really sure which framework, but it should be fairly trivial to code this in a programming language of your choice.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .