Azure认知服务:Python SDK中文本分析PII端点的问题



我正在尝试执行一些更深入的PII检测,作为标准代码,可以在这里找到:https://learn.microsoft.com/en-us/azure/cognitive-services/language-service/personally-identifiable-information/quickstart?pivots=programming-languagepython无法找到一些更详细的实体(例如法语车牌号(。

当我使用标准端点时,一切都很好:'https://whatever.cognitiveservices.azure.com/'

但是,当我切换到https://whatever.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/pii?piiCategories=default,FRDriversLicenseNumber";(示例如下:https://learn.microsoft.com/en-us/azure/cognitive-services/language-service/personally-identifiable-information/how-to-call(我得到一个404错误。

我相信这可能是Python SDK问题,因为当我尝试API控制台时,它工作得很好。https://westus2.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-1/operations/EntitiesRecognitionPii

代码:

key = "key"
endpoint = "https://whatever.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/pii?piiCategories=default,FRDriversLicenseNumber/"
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
# Authenticate the client using your key and endpoint 
def authenticate_client():
ta_credential = AzureKeyCredential(key)
text_analytics_client = TextAnalyticsClient(
endpoint=endpoint, 
credential=ta_credential)
return text_analytics_client
client = authenticate_client()
# Example method for detecting sensitive information (PII) from text 
def pii_recognition_example(client):
documents = [
"The employee's SSN is 859-98-0987.",
"The employee's phone number is 555-555-5555."
]
response = client.recognize_pii_entities(documents, language="en")
result = [doc for doc in response if not doc.is_error]
for doc in result:
print("Redacted Text: {}".format(doc.redacted_text))
for entity in doc.entities:
print("Entity: {}".format(entity.text))
print("tCategory: {}".format(entity.category))
print("tConfidence Score: {}".format(entity.confidence_score))
print("tOffset: {}".format(entity.offset))
print("tLength: {}".format(entity.length))
pii_recognition_example(client)

由于MS文档中还没有说明,端点应该保持简单:

端点=";https://.cognitiveservices.azure.com">

以及传递给响应的详细信息=client.arecogize_pii_enties((.

下面的代码工作得很好:

key = "key"
endpoint = "https://<name>.cognitiveservices.azure.com"

from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

# Authenticate the client using your key and endpoint 
def authenticate_client():
ta_credential = AzureKeyCredential(key)
text_analytics_client = TextAnalyticsClient(
endpoint=endpoint, 
credential=ta_credential)
return text_analytics_client

client = authenticate_client()

# Example method for detecting sensitive information (PII) from text 
def pii_recognition_example(client):
documents = [
"The employee's SSN is 859-98-0987.",
"The employee's phone number is 555-555-5555."
]
response = client.recognize_pii_entities(documents, language="en", categories_filter=["default", "FRDriversLicenseNumber"])
result = [doc for doc in response if not doc.is_error]
for doc in result:
print("Redacted Text: {}".format(doc.redacted_text))
for entity in doc.entities:
print("Entity: {}".format(entity.text))
print("tCategory: {}".format(entity.category))
print("tConfidence Score: {}".format(entity.confidence_score))
print("tOffset: {}".format(entity.offset))
print("tLength: {}".format(entity.length))
pii_recognition_example(client)

相关内容

  • 没有找到相关文章

最新更新