Complete the code to detect PII entities in the text using a pre-trained model.
entities = model.[1](text)The predict method is used to get the PII entities detected by the model from the input text.
Complete the code to replace detected PII entities with a redaction token.
redacted_text = text.replace(entity.value, [1])We replace the value of the detected PII entity with the string '[REDACTED]' to hide sensitive information.
Fix the error in the code to correctly iterate over detected PII entities.
for entity in [1]: print(entity)
The variable entities holds the list of detected PII entities to iterate over.
Fill both blanks to create a dictionary mapping PII types to their counts.
pii_counts = {entity.[1]: pii_entities.[2](entity) for entity in pii_entities}We use entity.type as the key and count how many times each entity appears with pii_entities.count(entity).
Fill all three blanks to filter PII entities by confidence score and redact them.
for entity in entities: if entity.[1] > [2]: text = text.replace(entity.[3], '[REDACTED]')
We check if the entity's confidence is above 0.8 and replace the entity's value in the text with '[REDACTED]'.