Package: promptedgraphs
PromptedGraphsFrom Dataset Labeling to Deployment: The Power of NLP and LLMs Combined.DescriptionPromptedGraphs is a Python library that aims to seamlessly integrate traditional NLP methods with the capabilities of modern Large Language Models (LLMs) in the realm of knowledge graphs. Our library offers tools tailored for dataset labeling, model training, and smooth deployment to production environments. We leverage the strengths ofspacyfor core NLP tasks,snorkelfor effective data labeling, andasyncto ensure enhanced performance. Our mission is to provide a harmonized solution to knowledge graph development when you have to merge traditional and LLM-driven approaches, squarely addressing the challenges associated with accuracy, efficiency, and affordability.✨ FeaturesNamed Entity Recognition (NER): Customize ER labels based on your domain.Structured Data Extraction: Extract structured data from unstructured text.Entity Resolution: Deduplication and normalizationRelationship Extraction: Either open ended labels or constrain to your domainEntity Linking: Link references in text to entities in a graphGraph Construction: Create or update knowledge graphsCore FunctionsDataset Labeling: Efficient tools for labeling datasets, powered byhaystack.Model Training: Combine the reliability of NLP and the prowess of LLMs.Deployment: Streamlined processes to ensure smooth transition to production.RequirementsPython 3.10 or newer.📦 InstallationTo installPromptedGraphsvia pip:pipinstallpromptedgraphs# orpoetryaddpromptedgraphsUsageEntity Recognitionfromexamples/er_reviews.ipynbfromspacyimportdisplacyfrompromptedgraphs.configimportConfigfrompromptedgraphs.entity_recognitionimportextract_entitieslabels={"POSITIVE":"A postive review of a product or service.","NEGATIVE":"A negative review of a product or service.","NEUTRAL":"A neutral review of a product or service.",}text_of_reviews="""1. "I absolutely love this product. It's been a game changer!"2. "The service was quite poor and the staff was rude."3. "The item is okay. Nothing special, but it gets the job done."""".strip()# Label Sentimentents=[]asyncformsginextract_entities(name="sentiment",description="Sentiment Analysis of Customer Reviews",text=text_of_reviews,labels=labels,config=Config(),# Reads `OPENAI_API_KEY` from .env file or environment):ents.append(msg)# Show Results using spacy.displacydisplacy.render({"text":text_of_reviews,"ents":[e.to_dict()foreinents],},style="ent",jupyter=True,manual=True,options={"colors":{"POSITIVE":"#7aecec","NEGATIVE":"#f44336","NEUTRAL":"#f4f442"}},)Brainstorming DataGenerate a list of data that fits a given data model.fromexamples/er_reviews.ipynbfrompydanticimportBaseModel,Fieldfrompromptedgraphs.configimportConfigfrompromptedgraphs.ideationimportbrainstormfrompromptedgraphs.visimportrender_entitiesclassBusinessIdea(BaseModel):"""A business idea generated using the Jobs-to-be-done frameworkFor example "We help [adj] [target_audience] [action] so they can [benefit or do something else]""""target_audience:str=Field(title="Target Audience")action:str=Field(title="Action")benefit:str=Field(title="Benefit or next action")adj:str|None=Field(title="Adjective",description="Optional adjective describing the target audience's condition",)ideas=[]asyncforideainbrainstorm(text=BusinessIdea.__doc__,output_type=list[BusinessIdea],config=Config(),n=10,max_workers=2,):ideas.append(idea)render_entities(f"We help{idea.adj}{idea.target_audience}{idea.action}so they can{idea.benefit}",idea,)Structured Data Extractionfromexamples/de_chatintents.ipynbfrompydanticimportBaseModel,Fieldfrompromptedgraphs.configimportConfigfrompromptedgraphs.data_extractionimportextract_dataclassUserIntent(BaseModel):"""The UserIntent entity, representing the canonical description of what a user desires to achieve in a given conversation."""intent_name:str=Field(title="Intent Name",description="Canonical name of the user's intent",examples=["question","command","clarification","chit_chat","greeting","feedback","nonsensical","closing","harrassment","unknown",],)description:str|None=Field(title="Intent Description",description="A detailed explanation of the user's intent",)msg="""It's a busy day, I need to send an email and to buy groceries"""asyncforintentinextract_data(text=msg,output_type=list[UserIntent],config=Config()):print(intent)intent_name='task'description='User wants to complete a task'intent_name='communication'description='User wants to send an email'intent_name='shopping'description='User wants to buy groceries'📚 ResourcesAwesome-LLM-KGKG-LLM-PapersRelated LibrariesinstructormarvinContributingWe welcome contributions! Please DM me@seankruzelor create issues or pull requests.📝 LicenseThis project is licensed under the terms of theMIT license.Built usingquantreadyusing templatehttps://github.com/closedloop-technologies/quantready-api