Skip to content

Knowledge Extractor

The knowledge extractor will perform at the same time the extraction and classification of named entities and the extraction of relations among them.

Currently, the is only one Knowledge Extractor available: KnowGL

Bases: ABC

Instantiate the Knowledge Extractor

Parameters:

Name Type Description Default
device Optional[Union[str, device]]

Device to be used for computation

None

__hash__()

Get hash representation of the component

extract_knowledge(docs, batch_size=None)

Perform the relations extraction. Call the predict function and add the mentions to the Spacy Doc

Parameters:

Name Type Description Default
docs Iterator[Doc]

A list of spacy Document

required
batch_size Optional[Union[int, None]]

The batch size

None

Returns:

Type Description

from_disk(path, exclude=()) classmethod

Load component from disk

load_models()

Load the model

Returns:

Type Description

parse_triples(preds)

Parse the triples into lists of entities and relations

Parameters:

Name Type Description Default
preds List[Tuple[Span, RelationSpan, Span]]

Predicted triples

required

Returns:

Type Description
Tuple[List[Span], List[RelationSpan]]

Tuple with list of entities and list of relations

predict(docs, batch_size=None) abstractmethod

Perform the knowledge extraction.

Parameters:

Name Type Description Default
docs Iterator[Doc]

A list of spacy Document

required
batch_size Optional[Union[int, None]]

The batch size

None

Returns:

Type Description
List[List[Tuple[Span, RelationSpan, Span]]]

the predicted triples

set_device(device)

Set the device to use

Parameters:

Name Type Description Default
device Union[str, device]
required

Returns:

Type Description

to_disk(path)

Save component into disk