Open Information Extraction (Open IE)
Open Information Extraction (Open IE) 是一种自然语言处理技术,旨在从文本中自动提取结构化的事实或信息,而不依赖于特定的领域或预定义的关系。它的核心目标是从非结构化的文本中提取出简洁、易于理解的事实三元组(如:subject-predicate-object 结构)。这种方法通常用于从大规模文本中自动抽取信息,并为数据分析、知识图谱构建、问答系统等任务提供支持。
import asyncio
import nest_asyncio
from typing import List
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser, PydanticOutputParser
from langchain_core.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate
nest_asyncio.apply()
llm = ChatOpenAI(
base_url='https://dashscope.aliyuncs.com/compatible-mode/v1',
model_name='llama3.3-70b-instruct',
temperature=0.5,
)
# print(llm.invoke('你是谁').content)
实体提取
class Named_Entity_Output(BaseModel):
named_entities: List[str] = Field(description="A list of named_entities extracted.")
named_entity_output_parser = PydanticOutputParser(pydantic_object=Named_Entity_Output)
example_i = """Radio City
Radio City is India's first private FM radio station and was started on 3 July 2001.
It plays Hindi, English and regional songs.
Radio City recently forayed into New Media in May 2008 with the launch of a music portal - PlanetRadiocity.com that offers music related news, videos, songs, and other music-related features."""
example_o = """{
{"named_entities":
["Radio City", "India", "FM radio station", "3 July 2001", "Hindi songs", "English songs", "regional songs", "New Media", "May 2008", "music portal", "PlanetRadiocity.com", "music related news", "videos", "songs", "music-related features"]
}}"""
system_prompt = SystemMessagePromptTemplate.from_template(
template=(
"Your task is to extract named entities from the given paragraph, in their original language as the paragraph."
"{output_format}"
),
partial_variables={
"output_format":named_entity_output_parser.get_format_instructions()
}
)
user_prompt = HumanMessagePromptTemplate.from_template(
template=(
"Paragraph:\n"
"```\n{content}\n```"
)
)
example_i

最低0.47元/天 解锁文章
1803

被折叠的 条评论
为什么被折叠?



