识别实体
命名实体识别是由Azure AI 语言提供的一项功能。 它标识和分类非结构化文本中的实体。 它支持多种 类别 的实体,包括人员、位置、事件、产品、组织等。
可通过多种方式调用 命名实体识别 API。 在此,您使用 azure_ai
扩展从文本中识别 SQL 查询中的实体。
先决条件
你需要具有 Azure Database for PostgreSQL 灵活服务器,且已启用并配置 azure_ai
扩展。 还需要使用 Azure 认知服务对其进行授权,方法是设置语言资源的密钥和终结点。
情境
实体识别在多个域中很有用,例如:
- 搜索和索引:使用标识的实体自动生成知识图和标记目录。
- 流程自动化:自动识别非结构化文本中的产品和位置,并将其路由到客户支持请求。
- 市场分析:衡量社交媒体、客户评论、支持票证等最常见的实体和实体群集,以确定相关主题并预测趋势。
在 SQL 中使用 Azure 认知服务进行命名实体识别
Azure Database for PostgreSQL 灵活服务器 azure_ai扩展 提供用户定义的函数(UDF),以便直接从 SQL 内部访问 AI 功能。 命名实体识别 API 通过 azure_ai
提供的 azure_cognitive.recognize_entities
函数进行访问:
azure_cognitive.recognize_entities(
text text,
language text,
timeout_ms integer DEFAULT 3600000,
throw_on_error boolean DEFAULT true,
disable_service_logs boolean DEFAULT false
)
所需的参数是 text
、输入项,以及表示text
所使用的语言language
。 例如, en-us
美国英语,法语 fr
。 有关可用语言的完整列表,请参阅 语言支持 。
默认情况下,如果实体识别在 3,600,000 毫秒 = 1 小时内未完成,则会被停止。 您可以更改 timeout_ms
以自定义此延迟。
如果发生错误,则默认行为是引发异常,从而导致事务回滚。 可以通过设置为 throw_on_error
false 来禁用此行为。
有关完整参数文档,请参阅 Azure 认知服务扩展文档 。
例如,调用此查询:
SELECT azure_cognitive.recognize_entities('For more information, see Cognitive Services Compliance and Privacy notes.', 'en-us');
提供以下结果:
{"(\"Cognitive Services\",Skill,\"\",0.94)"}
指示实体的名称为“认知服务”,其被标识为置信度分数为 0.94 的技能。
可以将表列用于输入文本:
SELECT description, azure_cognitive.recognize_entities(description, 'en-us')
FROM listings LIMIT 1;
这将返回:
{"(house,Location,\"\",0.77)","(2013.,DateTime,DateRange,1)","(\"rooftop deck\",Location,\"\",0.88)","(\"lounge area\",Location,Structural,0.97)","(tub,Product,\"\",0.52)","
(5,Quantity,Number,0.8)","(bedrooms,Location,\"\",0.92)","(\"gourmet kitchen\",Location,\"\",0.87)","(2-3,Quantity,NumberRange,0.87)","(downtown,Location,Structural,0.8)","(\
"Queen Anne neighborhood\",Location,\"\",0.74)","(house,Location,\"\",0.96)","(barnwood,Product,\"\",0.61)","(steel,Product,\"\",0.73)","(concrete,Product,\"\",0.7)","(living
,Location,Structural,0.53)","(\"gourmet kitchen\",Location,\"\",0.7)","(kitchen,Location,\"\",0.77)","(reading,Skill,\"\",0.54)","(half,Quantity,Number,0.8)","(\"tv room\",Lo
cation,\"\",0.89)","(kitchen,Location,\"\",0.64)","(Fireplace,Product,\"\",0.91)","(sofa,Product,\"\",0.98)","(\"sitting area\",Location,\"\",0.93)","(\"Basement room\",Locat
ion,\"\",0.98)","(kids,PersonType,\"\",0.73)","(room,Location,Structural,0.78)","(patio,Location,Structural,0.75)","(basketball,Product,\"\",0.57)","(bedroom,Location,\"\",0.
8)","(basement,Location,\"\",0.94)","(\"concrete heated floors\",Product,\"\",0.95)","(\"queen sleeper sofa\",Product,\"\",0.86)","(tv,Location,\"\",0.54)","(basement,Locatio
n,\"\",0.92)","(room,Location,Structural,0.9)","(\"a second\",DateTime,Duration,0.85)","(family,PersonType,\"\",0.71)","(kids,PersonType,\"\",0.65)","(\"2nd floor\",Location,
Structural,0.56)","(4,Quantity,Number,0.8)","(bedrooms,Location,\"\",0.66)","(one,Quantity,Number,0.8)","(one,Quantity,Number,0.8)","(bedroom,Location,\"\",0.54)","(\"twin bu
nk beds\",Product,\"\",0.67)"}
概要
命名实体识别识别和分类输入文本中的实体。 Azure 认知服务语言模型执行繁重的自然语言处理。 azure_ai
扩展为 Azure Database for PostgreSQL 提供了 azure_cognitive.recognize_entities
API,以便在 SQL 查询中直接访问命名实体识别功能。