GlinerGraphTransformer#

class langchain_experimental.graph_transformers.gliner.GlinerGraphTransformer(allowed_nodes: List[str], allowed_relationships: List[str] | Dict[str, Any], gliner_model: str = 'urchade/gliner_mediumv2.1', glirel_model: str = 'jackboyla/glirel_beta', entity_confidence_threshold: float = 0.1, relationship_confidence_threshold: float = 0.1, device: str = 'cpu', ignore_self_loops: bool = True)[source]#

A transformer class for converting documents into graph structures using the GLiNER and GLiREL models.

This class leverages GLiNER for named entity recognition and GLiREL for relationship extraction from text documents, converting them into a graph format. The extracted entities and relationships are filtered based on specified confidence thresholds and allowed types.

For more details on GLiNER and GLiREL, visit their respective repositories:

GLiNER: urchade/GLiNER GLiREL: jackboyla/GLiREL

Parameters:
  • allowed_nodes (List[str]) – A list of allowed node types for entity extraction.

  • allowed_relationships (Union[List[str], Dict[str, Any]]) – A list of allowed relationship types or a dictionary with additional configuration for relationship extraction.

  • gliner_model (str) – The name of the pretrained GLiNER model to use. Default is β€œurchade/gliner_mediumv2.1”.

  • glirel_model (str) – The name of the pretrained GLiREL model to use. Default is β€œjackboyla/glirel_beta”.

  • entity_confidence_threshold (float) – The confidence threshold for filtering extracted entities. Default is 0.1.

  • relationship_confidence_threshold (float) – The confidence threshold for filtering extracted relationships. Default is 0.1.

  • device (str) – The device to use for model inference (β€˜cpu’ or β€˜cuda’). Default is β€œcpu”.

  • ignore_self_loops (bool) – Whether to ignore relationships where the source and target nodes are the same. Default is True.

Methods

__init__(allowed_nodes,Β allowed_relationships)

convert_to_graph_documents(documents)

Convert a sequence of documents into graph documents.

process_document(document)

__init__(allowed_nodes: List[str], allowed_relationships: List[str] | Dict[str, Any], gliner_model: str = 'urchade/gliner_mediumv2.1', glirel_model: str = 'jackboyla/glirel_beta', entity_confidence_threshold: float = 0.1, relationship_confidence_threshold: float = 0.1, device: str = 'cpu', ignore_self_loops: bool = True) β†’ None[source]#
Parameters:
  • allowed_nodes (List[str]) –

  • allowed_relationships (List[str] | Dict[str, Any]) –

  • gliner_model (str) –

  • glirel_model (str) –

  • entity_confidence_threshold (float) –

  • relationship_confidence_threshold (float) –

  • device (str) –

  • ignore_self_loops (bool) –

Return type:

None

convert_to_graph_documents(documents: Sequence[Document]) β†’ List[GraphDocument][source]#

Convert a sequence of documents into graph documents.

Parameters:
  • documents (Sequence[Document]) – The original documents.

  • kwargs – Additional keyword arguments.

Returns:

The transformed documents as graphs.

Return type:

Sequence[GraphDocument]

process_document(document: Document) β†’ GraphDocument[source]#
Parameters:

document (Document) –

Return type:

GraphDocument