extract_entity_attribute_mapper¶
Extracts attributes for given entities from the text and stores them in the sample’s metadata.
This operator uses an API model to extract specified attributes for given entities from the input text. It constructs prompts based on provided templates and parses the model’s output to extract attribute descriptions and supporting text. The extracted data is stored in the sample’s metadata under the specified keys. If the required metadata fields already exist, the operator skips processing for that sample. The operator retries the API call and parsing up to a specified number of times in case of errors. The default system prompt, input template, and parsing patterns are used if not provided.
从文本中提取给定实体的属性,并将其存储在样本的元数据中。
该算子使用API模型从输入文本中提取给定实体的指定属性。它基于提供的模板构建提示,并解析模型的输出以提取属性描述和支持文本。提取的数据存储在样本的元数据中指定的键下。如果所需的元数据字段已经存在,该算子将跳过对该样本的处理。该算子在出现错误时最多重试指定次数的API调用和解析。如果没有提供默认系统提示、输入模板和解析模式,则使用默认值。
Type 算子类型: mapper
Tags 标签: cpu, api, text
🔧 Parameter Configuration 参数配置¶
name 参数名 |
type 类型 |
default 默认值 |
desc 说明 |
---|---|---|---|
|
<class ‘str’> |
|
API model name. |
|
typing.List[str] |
|
Entity list to be queried. |
|
typing.List[str] |
|
Attribute list to be queried. |
|
<class ‘str’> |
|
The key name in the meta field to store the given main entity for attribute extraction. It’s “entity” in default. |
|
<class ‘str’> |
|
The key name in the meta field to store the given attribute to be extracted. It’s “attribute” in default. |
|
<class ‘str’> |
|
The key name in the meta field to store the extracted attribute description. It’s “attribute_description” in default. |
|
<class ‘str’> |
|
The key name in the meta field to store the attribute support text extracted from the raw text. It’s “support_text” in default. |
|
typing.Optional[str] |
|
URL endpoint for the API. |
|
typing.Optional[str] |
|
Path to extract content from the API response. Defaults to ‘choices.0.message.content’. |
|
typing.Optional[str] |
|
System prompt template for the task. Need to be specified by given entity and attribute. |
|
typing.Optional[str] |
|
Template for building the model input. |
|
typing.Optional[str] |
|
Pattern for parsing the attribute from output. Need to be specified by given attribute. |
|
typing.Optional[str] |
|
Pattern for parsing the demonstration from output to support the attribute. |
|
typing.Annotated[int, Gt(gt=0)] |
|
The number of retry attempts when there is an API call error or output parsing error. |
|
<class ‘bool’> |
|
If drop the text in the output. |
|
typing.Dict |
|
Parameters for initializing the API model. |
|
typing.Dict |
|
Extra parameters passed to the API call. e.g {‘temperature’: 0.9, ‘top_p’: 0.95} |
|
|
Extra keyword arguments. |
📊 Effect demonstration 效果演示¶
test¶
ExtractEntityAttributeMapper(api_model='qwen2.5-72b-instruct', query_entities=['李莲花', '方多病'], query_attributes=['语言风格', '角色性格'], response_path=None)
📥 input data 输入数据¶
△笛飞声独自坐在莲花楼屋顶上。李莲花边走边悠闲地给马喂草。方多病则走在一侧,却总不时带着怀疑地盯向楼顶的笛飞声。 方多病走到李莲花身侧:我昨日分明看到阿飞神神秘秘地见了一人,我肯定他有什么瞒着我们。阿飞的来历我必须去查清楚! 李莲花继续悠然地喂草:放心吧,我认识他十几年了,对他一清二楚。 方多病:认识十几年?你上次才说是一面之缘? 李莲花忙圆谎:见得不多,但知根知底。哎,这老马吃得也太多了。 方多病一把夺过李莲花手中的草料:别转移话题!——快说! 李莲花:阿飞啊,脾气不太好,他......这十年也没出过几次门,所以见识短,你不要和他计较。还有他是个武痴,武功深藏不露,你平时别惹他。 方多病:呵...
Show more 展开更多 (352 more chars)
△笛飞声独自坐在莲花楼屋顶上。李莲花边走边悠闲地给马喂草。方多病则走在一侧,却总不时带着怀疑地盯向楼顶的笛飞声。 方多病走到李莲花身侧:我昨日分明看到阿飞神神秘秘地见了一人,我肯定他有什么瞒着我们。阿飞的来历我必须去查清楚! 李莲花继续悠然地喂草:放心吧,我认识他十几年了,对他一清二楚。 方多病:认识十几年?你上次才说是一面之缘? 李莲花忙圆谎:见得不多,但知根知底。哎,这老马吃得也太多了。 方多病一把夺过李莲花手中的草料:别转移话题!——快说! 李莲花:阿飞啊,脾气不太好,他......这十年也没出过几次门,所以见识短,你不要和他计较。还有他是个武痴,武功深藏不露,你平时别惹他。 方多病:呵,阿飞武功高?编瞎话能不能用心点? 李莲花:可都是大实话啊。反正,我和他彼此了解得很。你就别瞎操心了。 方多病很是质疑:(突然反应过来)等等!你说你和他认识十几年?你们彼此了解?!这么说,就我什么都不知道?! △李莲花一愣,意外方多病是如此反应。 方多病很是不爽:不行,你们现在投奔我,我必须对我的手下都了解清楚。现在换我来问你,你,李莲花究竟籍贯何处?今年多大?家里还有什么人?平时都有些什么喜好?还有,可曾婚配? △此时的笛飞声正坐在屋顶,从他的位置远远地向李莲花和方多病二人看去,二人声音渐弱。 李莲花:鄙人李莲花,有个兄弟叫李莲蓬,莲花山莲花镇莲花村人,曾经订过亲,但媳妇跟人跑子。这一辈子呢,没什么抱负理想,只想种种萝卜、逗逗狗,平时豆花爱吃甜的,粽子要肉的...... 方多病:没一句实话。
📤 output data 输出数据¶
△笛飞声独自坐在莲花楼屋顶上。李莲花边走边悠闲地给马喂草。方多病则走在一侧,却总不时带着怀疑地盯向楼顶的笛飞声。 方多病走到李莲花身侧:我昨日分明看到阿飞神神秘秘地见了一人,我肯定他有什么瞒着我们。阿飞的来历我必须去查清楚! 李莲花继续悠然地喂草:放心吧,我认识他十几年了,对他一清二楚。 方多病:认识十几年?你上次才说是一面之缘? 李莲花忙圆谎:见得不多,但知根知底。哎,这老马吃得也太多了。 方多病一把夺过李莲花手中的草料:别转移话题!——快说! 李莲花:阿飞啊,脾气不太好,他......这十年也没出过几次门,所以见识短,你不要和他计较。还有他是个武痴,武功深藏不露,你平时别惹他。 方多病:呵...
Show more 展开更多 (352 more chars)
△笛飞声独自坐在莲花楼屋顶上。李莲花边走边悠闲地给马喂草。方多病则走在一侧,却总不时带着怀疑地盯向楼顶的笛飞声。 方多病走到李莲花身侧:我昨日分明看到阿飞神神秘秘地见了一人,我肯定他有什么瞒着我们。阿飞的来历我必须去查清楚! 李莲花继续悠然地喂草:放心吧,我认识他十几年了,对他一清二楚。 方多病:认识十几年?你上次才说是一面之缘? 李莲花忙圆谎:见得不多,但知根知底。哎,这老马吃得也太多了。 方多病一把夺过李莲花手中的草料:别转移话题!——快说! 李莲花:阿飞啊,脾气不太好,他......这十年也没出过几次门,所以见识短,你不要和他计较。还有他是个武痴,武功深藏不露,你平时别惹他。 方多病:呵,阿飞武功高?编瞎话能不能用心点? 李莲花:可都是大实话啊。反正,我和他彼此了解得很。你就别瞎操心了。 方多病很是质疑:(突然反应过来)等等!你说你和他认识十几年?你们彼此了解?!这么说,就我什么都不知道?! △李莲花一愣,意外方多病是如此反应。 方多病很是不爽:不行,你们现在投奔我,我必须对我的手下都了解清楚。现在换我来问你,你,李莲花究竟籍贯何处?今年多大?家里还有什么人?平时都有些什么喜好?还有,可曾婚配? △此时的笛飞声正坐在屋顶,从他的位置远远地向李莲花和方多病二人看去,二人声音渐弱。 李莲花:鄙人李莲花,有个兄弟叫李莲蓬,莲花山莲花镇莲花村人,曾经订过亲,但媳妇跟人跑子。这一辈子呢,没什么抱负理想,只想种种萝卜、逗逗狗,平时豆花爱吃甜的,粽子要肉的...... 方多病:没一句实话。
✨ explanation 解释¶
This example demonstrates the ExtractEntityAttributeMapper operator’s functionality by extracting attributes for the entities ‘李莲花’ and ‘方多病’ from a given text. The operator uses an API model to identify and extract the specified attributes (such as ‘语言风格’ and ‘角色性格’) for these entities. The extracted information, including attribute descriptions and supporting texts, is then stored in the sample’s metadata. 这个例子展示了ExtractEntityAttributeMapper算子的功能,从给定的文本中提取实体’李莲花’和’方多病’的属性。算子使用一个API模型来识别并抽取这些实体的指定属性(如’语言风格’和’角色性格’)。提取的信息,包括属性描述和支持文本,会被存储在样本的元数据中。