辨識個人識別資訊 (PII) 實體

已完成

個人識別資訊(PII)偵測是 Azure Language 提供的一項功能。 它會在非結構化文字中識別、分類和修訂個人標識資訊(PII)。 PII 包括電子郵件地址、電話號碼、付款資訊等。

有數種方式可以呼叫 PII 偵測 API。 在這裡,您會使用 azure_ai 擴充套件來處理來自文本的 SQL 查詢中的 PII。

先決條件

您需要適用於 PostgreSQL 的 Azure 資料庫彈性伺服器,並azure_ai啟用並設定擴充功能。 您也需要藉由設定語言資源的密鑰和端點,向 Azure 認知服務 授權 它。

案例

針對數個應用程式使用 PII 偵測,包括:

  • 敏感度標籤:根據 PII 類型,依敏感度分類檔或電子郵件。 包含電話號碼的文字可能會標示為機密,而信用卡或銀行帳戶號碼則標示為高度機密。
  • 支援與作業的修訂:許多作業工作 (例如事件分級或支援路由) 不需要個人資訊。 公司可以使用 PII 修訂來篩選員工工作不需要的客戶資訊。
  • 減少個人資訊以減少無意識偏見:公司可以移除名稱、位址和其他資訊,以協助減輕無意識性別或其他偏見。

使用 Azure 認知服務偵測 SQL 中的 PII

適用於 PostgreSQL 的 Azure 資料庫彈性伺服器 azure_ai延伸模組 提供使用者定義的函式 (UDF),以直接從 SQL 內部存取 AI 功能。 PII 偵測 API 是使用 azure_cognitive.recognize_pii_entities 所提供的 azure_ai 函式來存取:

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_ai 適用於 PostgreSQL 的 Azure 資料庫延伸模組會提供 azure_cognitive.recognize_pii_entities API 來直接從 SQL 查詢內偵測和修訂 PII。