|
|
|
|
|
from transformers import pipeline |
|
from transformers import Tool |
|
|
|
class NamedEntityRecognitionTool(Tool): |
|
name = "ner_tool" |
|
description = "Identifies and labels entities such as persons, organizations, and locations in a given text." |
|
inputs = ["text"] |
|
outputs = ["text"] |
|
|
|
def __call__(self, text: str): |
|
|
|
ner_analyzer = pipeline("ner") |
|
|
|
|
|
entities = ner_analyzer(text) |
|
|
|
|
|
print(f"Identified Entities: {entities}") |
|
|
|
|
|
entity_labels = [entity.get("entity", "UNKNOWN") for entity in entities] |
|
|
|
return {"entities": entity_labels} |
|
|