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: