Analyze Documents
A flow that analyzes documents with various language-based Machine Learning models.
This sample flow utilizes Azure AI Language's pre-built and optimized language models to perform various analyses on documents. It performs:
- Translation
- Personally Identifiable Information (PII) detection
- Named Entity Recognition (NER)
- Document Summarization
- Sentiment Analysis & Opinion Mining
See the promptflow-azure-ai-language tool package reference documentation for further information.
Tools used in this flow:
pythontool.translatortool from thepromptflow-azure-ai-languagepackage.pii_entity_recognitiontool from thepromptflow-azure-ai-languagepackage.abstractive_summarizationtool from thepromptflow-azure-ai-languagepackage.extractive_summarizationtool from thepromptflow-azure-ai-languagepackage.entity_recognitiontool from thepromptflow-azure-ai-languagepackage.sentiment_analysistool from thepromptflow-azure-ai-languagepackage.
Connections used in this flow:
Customconnection (Azure AI Language).Customconnection (Azure AI Translator).
Prerequisites
Prompt flow SDK:
Install promptflow sdk and other dependencies:
pip install -r requirements.txt
Note: when using the Prompt flow SDK, it may be useful to also install the Prompt flow for VS Code extension (if using VS Code).
Azure AI/ML Studio:
Start an compute session. Required packages will automatically be installed from the requirements.txt file.
Setup connections
To use the promptflow-azure-ai-language package, you must have an Azure AI Language Resource. Create a Language Resource if necessary. From your Language Resource, obtain its api_key and endpoint.
Create a connection to your Language Resource. The connection uses the CustomConnection schema:
Prompt flow SDK:
# Override keys with --set to avoid yaml file changes
pf connection create -f ./connections/azure_ai_language.yml --set secrets.api_key=<your_api_key> configs.endpoint=<your_endpoint> name=azure_ai_language
Ensure you have created the azure_ai_language connection:
pf connection show -n azure_ai_language
Azure AI/ML Studio:
If using Azure AI Studio, you will need to add two additional custom keys to the connection. Follow these instructions when creating a CustomConnection.
To use the translator tool, you must have an Azure AI Translator resource. Create a Translator resource if necessary. From your Translator Resource, obtain its api_key, endpoint, and region (if applicable).
Create a connection to your Translator Resource. The connection uses the CustomConnection schema:
Prompt flow SDK:
# Override keys with --set to avoid yaml file changes
pf connection create -f ./connections/azure_ai_translator.yml --set secrets.api_key=<your_api_key> configs.endpoint=<your_endpoint> configs.region=<your_region> name=azure_ai_translator
Ensure you have created the azure_ai_translator connection:
pf connection show -n azure_ai_translator
Azure AI/ML Studio:
If using Azure AI Studio, you will need to add two additional custom keys to the connection. Follow these instructions when creating a CustomConnection.
Note: if you already have an Azure AI Language or Azure AI Translator connection, you do not need to create additional connections and may substitute them in.
Run flow
Prompt flow SDK:
Run with single line input
# Test with default input values in flow.dag.yaml:
pf flow test --flow .
# Test with specific input:
pf flow test --flow . --inputs document_path=<path_to_txt_file> language=<document_language_code>
Run with multiple lines of data
pf run create --flow . --data ./data.jsonl --column-mapping document_path='${data.document_path}' language='${data.language}' --stream
You can also skip providing column-mapping if provided data has same column name as the flow. Reference here for default behavior when column-mapping not provided in CLI.
Azure AI/ML Studio:
Run flow.
Flow Description
The flow first reads in a text file and translates it to the input language. PII information is then redacted. From the redacted text, the flow generates summaries (extractive & abstractive) and extracts named entities. Finally, the flow analyzes the sentiment of the abstractive summary.
Note: you may remove all references to Azure AI Translator (connection and tool) if you do not wish to utilize those capabilities.
This flow showcases a variety of analyses to perform on documents. Consider extending it to summarize project documents or press releases, analyze and mine the sentiment of reviews, etc.
Contact
Please reach out to Azure AI Language (taincidents@microsoft.com) with any issues.

