compares with our case!from langchain.llms import OpenAIfrom langchain.prompts import PromptTemplatefrom langchain.output_parsers import PydanticOutputParserfrom langchain.chains import create_extraction_chain_pydantic, SimpleSequentialChainfrom pydantic import BaseModel, Fieldfrom typing import Listclass Actor(BaseModel):    Actor: str = Field(description="name of an actor")    Film: List[str] = Field(description="list of names of films they starred in")Parsers‚Äãllm = OpenAI()parser = PydanticOutputParser(pydantic_object=Actor)prompt = PromptTemplate(    template="Extract fields from a given text.\n{format_instructions}\n{text}\n",    input_variables=["text"],    partial_variables={"format_instructions": parser.get_format_instructions()},)_input = prompt.format_prompt(text=dataset[0]["text"])output = llm(_input.to_string())parsed = parser.parse(output)parsed    Actor(Actor='Tom Hanks', Film=['Forrest Gump', 'Saving Private Ryan', 'The Green Mile', 'Toy Story', 'Catch Me If You Can'])(parsed.Actor == inp[0]["Actor"]) & (parsed.Film == inp[0]["Film"])    TrueExtractors‚Äãextractor = create_extraction_chain_pydantic(pydantic_schema=Actor, llm=model)extracted = extractor.run(dataset[1]["text"])extracted    [Actor(Actor='Tom Hardy', Film=['Inception', 'The Dark Knight Rises', 'Mad Max: Fury Road', 'The Revenant', 'Dunkirk'])](extracted[0].Actor == inp[1]["Actor"]) & (extracted[0].Film == inp[1]["Film"])    TruePreviousWeb scrapingNextGraph queryingUse caseQuickstartSetup1. Define Your Data Model2. Sample Data3. Craft a Prompt Template4. Creating the Data Generator5. Generate Synthetic DataOther implementationsGenerating exemplary dataset for extraction benchmarking purposesExtraction from generated examplesParsersExtractorsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
Open In Colab
Open In Colab ->: compares with our case!from langchain.llms import OpenAIfrom langchain.prompts import PromptTemplatefrom langchain.output_parsers import PydanticOutputParserfrom langchain.chains import create_extraction_chain_pydantic, SimpleSequentialChainfrom pydantic import BaseModel, Fieldfrom typing import Listclass Actor(BaseModel):    Actor: str = Field(description="name of an actor")    Film: List[str] = Field(description="list of names of films they starred in")Parsers‚Äãllm = OpenAI()parser = PydanticOutputParser(pydantic_object=Actor)prompt = PromptTemplate(    template="Extract fields from a given text.\n{format_instructions}\n{text}\n",    input_variables=["text"],    partial_variables={"format_instructions": parser.get_format_instructions()},)_input = prompt.format_prompt(text=dataset[0]["text"])output = llm(_input.to_string())parsed = parser.parse(output)parsed    Actor(Actor='Tom Hanks', Film=['Forrest Gump', 'Saving Private Ryan', 'The Green Mile', 'Toy Story', 'Catch Me If You Can'])(parsed.Actor == inp[0]["Actor"]) & (parsed.Film == inp[0]["Film"])    TrueExtractors‚Äãextractor = create_extraction_chain_pydantic(pydantic_schema=Actor, llm=model)extracted = extractor.run(dataset[1]["text"])extracted    [Actor(Actor='Tom Hardy', Film=['Inception', 'The Dark Knight Rises', 'Mad Max: Fury Road', 'The Revenant', 'Dunkirk'])](extracted[0].Actor == inp[1]["Actor"]) & (extracted[0].Film == inp[1]["Film"])    TruePreviousWeb scrapingNextGraph queryingUse caseQuickstartSetup1. Define Your Data Model2. Sample Data3. Craft a Prompt Template4. Creating the Data Generator5. Generate Synthetic DataOther implementationsGenerating exemplary dataset for extraction benchmarking purposesExtraction from generated examplesParsersExtractorsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.