识别个人身份信息 (PII) 实体

已完成

PII(个人身份信息)检测是 Azure AI 语言提供的一项功能。 它在非结构化文本中标识、分类和编辑个人身份信息(PII)。 PII 包括电子邮件地址、电话号码、付款信息等。

可通过多种方式调用 PII 检测 API。 在这里,使用 azure_ai 扩展处理 SQL 查询中的文本中的 PII。

先决条件

你需要具有 Azure Database for PostgreSQL 灵活服务器,且azure_ai 扩展。 还需要使用 Azure 认知服务对其进行授权,方法是设置语言资源的密钥和终结点。

方案

对多个应用程序使用 PII 检测,包括:

  • 敏感度标签:根据 PII 的类型按敏感度对文档或电子邮件进行分类。 包含电话号码的文本可能标记为机密,而信用卡或银行帐户号码将标记为高度机密。
  • 支持和操作的修订:许多操作任务(例如事件会审或支持路由)不需要个人信息。 公司可以使用 PII 修订来筛选员工任务中不必要的客户信息。
  • 减少个人信息以减少无意识偏见:公司可以删除姓名、地址和其他信息,以帮助缓解无意识性别或其他偏见。

使用 Azure 认知服务检测 SQL 中的 PII

Azure Database for PostgreSQL 灵活服务器 azure_ai扩展 提供用户定义的函数(UDF),以便直接从 SQL 内部访问 AI 功能。 使用azure_ai提供的azure_cognitive.recognize_pii_entities函数来访问PII检测API。

azure_cognitive.recognize_pii_entities(
 text text,
 language text,
 timeout_ms integer DEFAULT 3600000,
 throw_on_error boolean DEFAULT true,
 domain text DEFAULT 'none'::text,
 disable_service_logs boolean DEFAULT false
)

所需的参数是 text、输入项,以及表示language所使用的语言text。 例如, en-us 美国英语,法语 fr 。 有关可用语言的完整列表,请参阅 语言支持

默认情况下,如果实体识别在 3,600,000 毫秒 = 1 小时内未完成,则会被停止。 您可以更改 timeout_ms以自定义此延迟。

如果发生错误,则默认行为是引发异常,从而导致事务回滚。 可以通过设置为 throw_on_error false 来禁用此行为。

domain 参数可用于自定义标识的个人数据类型。 目前,默认 none 使用常规 PII,域 phi 标识个人健康信息。

有关完整参数文档,请参阅 Azure 认知服务扩展文档

例如,调用此查询:

SELECT azure_cognitive.recognize_pii_entities('My phone number is +1555555555, and the address of my office is 16255 NE 36th Way, Redmond, WA 98052.', 'en-us');

提供以下结果:

("My phone number is ***********, and the address of my office is ************************************.","{""(+1555555555,PhoneNumber,\\""\\"",0.8)"",""(\\""16255 NE 36th Way, Redmond, WA 98052\\"",Address,\\""\\"",1)""}")

PII 服务检测到置信度分数为 0.8 的电话号码,以及置信度分数为 1 的地址。 它还返回了经过编辑,去除两个 PII 数据点的输入。

可以将表列用于输入文本:

SELECT description, azure_cognitive.recognize_pii_entities(description, 'en-us')
FROM listings LIMIT 1;

返回的结果是(\x 启用扩展显示):

recognize_pii_entities | ("New modern house built in 2013. Spectacular sunset/water views, light, rooftop deck and lounge area, hot tub, 5 bedrooms, gourmet kitchen. Perfect for 2-3 families, walk to downtown. Located in highly desirable Queen Anne neighborhood. Our house is modern, light and fresh with a warm simple palette accented with barnwood, steel and concrete. Open living spaces for entertaining, gourmet kitchen, deck off the kitchen, reading nook, half bath and smaller tv room off kitchen. Fireplace with sofa and sitting area. Basement room is great for ****...this room has patio access and a garage door that opens into the space with basketball hoop right outside. A queen bedroom and full bath are in the basement with concrete heated floors. A queen sleeper sofa is in the tv area in the basement. This room has a door if privacy is needed. Great for a second ****** with ****. The 2nd floor has 4 bedrooms (one queen in master, one twin bedroom, another bedroom has twin bunk beds and the last","{""(kids,PersonType,\\""\\"",0.73)"",""(family,PersonType,\\""\\"",0.71)"",""(kids,PersonType,\\""\\"",0.65)""}")

概要

PII 检测在非结构化输入文本中识别和分类个人身份信息。 Azure 认知服务语言模型执行繁重的工作,并且 Azure Database for PostgreSQL 的 azure_ai 扩展提供了 azure_cognitive.recognize_pii_entities API 来用于直接从 SQL 查询中检测并修正 PII。