Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
This feature is in preview.
With Microsoft Fabric, all business professionals—from developers to analysts—can derive more value from their enterprise data through Generative AI, using experiences like Copilot and Fabric data agents. Thanks to a new set of AI functions for data engineering, Fabric users can now harness the power of industry-leading large language models (LLMs) to transform and enrich data seamlessly.
AI functions harness the power of GenAI for summarization, classification, text generation, and so much more—all with a single line of code:
- Calculate similarity with
ai.similarity
: Compare the meaning of input text with a single common text value, or with corresponding text values in another column. - Categorize text with
ai.classify
: Classify input text values according to labels you choose. - Detect sentiment with
ai.analyze_sentiment
: Identify the emotional state expressed by input text. - Extract entities with
ai.extract
: Find and extract specific types of information from input text, for example locations or names. - Fix grammar with
ai.fix_grammar
: Correct the spelling, grammar, and punctuation of input text. - Summarize text with
ai.summarize
: Get summaries of input text. - Translate text with
ai.translate
: Translate input text into another language. - Answer custom user prompts with
ai.generate_response
: Generate responses based on your own instructions.
It's seamless to incorporate these functions as part of data-science and data-engineering workflows, whether you're working with pandas or Spark. There is no detailed configuration, no complex infrastructure management, and no specific technical expertise needed.
Prerequisites
- To use AI functions with Fabric's built-in AI endpoint, your administrator needs to enable the tenant switch for Copilot and other features powered by Azure OpenAI.
- Depending on your location, you may need to enable a tenant setting for cross-geo processing. Learn more here.
- You also need an F2 or higher SKU or a P SKU. If you use a trial SKU, you can bring your own Azure Open AI resource.
Note
- AI functions are supported in the Fabric 1.3 runtime and higher.
- AI functions use the gpt-4o-mini (2024-07-18) model by default. To learn more about billing and consumption rates, visit this article.
- Most of the AI functions are optimized for use on English-language texts.
Getting started with AI functions
Using AI functions in Fabric notebooks requires certain custom packages, which are preinstalled on the Fabric runtime. For the latest features and bugfixes, you can run the following code to install and import the most up-to-date packages. Afterward, you can use AI functions with pandas or PySpark, depending on your preference.
This code cell installs the AI functions library and its dependencies.
Warning
The PySpark configuration cell takes a few minutes to finish executing. We appreciate your patience.
# Install fixed version of packages
%pip install -q --force-reinstall openai==1.30 httpx==0.27.0
# Install latest version of SynapseML-core
%pip install -q --force-reinstall https://mmlspark.blob.core.windows.net/pip/1.0.11-spark3.5/synapseml_core-1.0.11.dev1-py2.py3-none-any.whl
# Install SynapseML-Internal .whl with AI functions library from blob storage:
%pip install -q --force-reinstall https://mmlspark.blob.core.windows.net/pip/1.0.11.1-spark3.5/synapseml_internal-1.0.11.1.dev1-py2.py3-none-any.whl
This code cell imports the AI functions library and its dependencies. The pandas cell also imports an optional Python library to display progress bars that track the status of every AI function call.
# Required imports
import synapse.ml.aifunc as aifunc
import pandas as pd
import openai
# Optional import for progress bars
from tqdm.auto import tqdm
tqdm.pandas()
Applying AI functions
Each of the following functions allows you to invoke Fabric's built-in AI endpoint to transform and enrich data with a single line of code. You can use AI functions to analyze pandas DataFrames or Spark DataFrames.
Tip
To learn about customizing the configuration of AI functions, visit this article.
Calculate similarity with ai.similarity
The ai.similarity
function invokes AI to compare input text values with a single common text value, or with pairwise text values in another column. The output similarity scores are relative, and they can range from -1 (opposites) to 1 (identical). A score of 0 indicates that the values are completely unrelated in meaning. For more detailed instructions about the use of ai.similarity
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
("Bill Gates", "Microsoft"),
("Satya Nadella", "Toyota"),
("Joan of Arc", "Nike")
], columns=["names", "companies"])
df["similarity"] = df["names"].ai.similarity(df["companies"])
display(df)
Categorize text with ai.classify
The ai.classify
function invokes AI to categorize input text according to custom labels you choose. For more information about the use of ai.classify
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
"This duvet, lovingly hand-crafted from all-natural fabric, is perfect for a good night's sleep.",
"Tired of friends judging your baking? With these handy-dandy measuring cups, you'll create culinary delights.",
"Enjoy this *BRAND NEW CAR!* A compact SUV perfect for the professional commuter!"
], columns=["descriptions"])
df["category"] = df['descriptions'].ai.classify("kitchen", "bedroom", "garage", "other")
display(df)
Detect sentiment with ai.analyze_sentiment
The ai.analyze_sentiment
function invokes AI to identify whether the emotional state expressed by input text is positive, negative, mixed, or neutral. If AI can't make this determination, the output is left blank. For more detailed instructions about the use of ai.analyze_sentiment
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
"The cleaning spray permanently stained my beautiful kitchen counter. Never again!",
"I used this sunscreen on my vacation to Florida, and I didn't get burned at all. Would recommend.",
"I'm torn about this speaker system. The sound was high quality, though it didn't connect to my roommate's phone.",
"The umbrella is OK, I guess."
], columns=["reviews"])
df["sentiment"] = df["reviews"].ai.analyze_sentiment()
display(df)
Extract entities with ai.extract
The ai.extract
function invokes AI to scan input text and extract specific types of information designated by labels you choose—for example, locations or names. For more detailed instructions about the use of ai.extract
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
"MJ Lee lives in Tuscon, AZ, and works as a software engineer for Microsoft.",
"Kris Turner, a nurse at NYU Langone, is a resident of Jersey City, New Jersey."
], columns=["descriptions"])
df_entities = df["descriptions"].ai.extract("name", "profession", "city")
display(df_entities)
Fix grammar with ai.fix_grammar
The ai.fix_grammar
function invokes AI to correct the spelling, grammar, and punctuation of input text. For more detailed instructions about the use of ai.fix_grammar
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
"There are an error here.",
"She and me go weigh back. We used to hang out every weeks.",
"The big picture are right, but you're details is all wrong."
], columns=["text"])
df["corrections"] = df["text"].ai.fix_grammar()
display(df)
Summarize text with ai.summarize
The ai.summarize
function invokes AI to generate summaries of input text (either values from a single column of a DataFrame, or row values across all the columns). For more detailed instructions about the use of ai.summarize
, visit this dedicated article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df= pd.DataFrame([
("Microsoft Teams", "2017",
"""
The ultimate messaging app for your organization—a workspace for real-time
collaboration and communication, meetings, file and app sharing, and even the
occasional emoji! All in one place, all in the open, all accessible to everyone.
"""),
("Microsoft Fabric", "2023",
"""
An enterprise-ready, end-to-end analytics platform that unifies data movement,
data processing, ingestion, transformation, and report building into a seamless,
user-friendly SaaS experience. Transform raw data into actionable insights.
""")
], columns=["product", "release_year", "description"])
df["summaries"] = df["description"].ai.summarize()
display(df)
Translate text with ai.translate
The ai.translate
function invokes AI to translate input text to a new language of your choice. For more detailed instructions about the use of ai.translate
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
"Hello! How are you doing today?",
"Tell me what you'd like to know, and I'll do my best to help.",
"The only thing we have to fear is fear itself."
], columns=["text"])
df["translations"] = df["text"].ai.translate("spanish")
display(df)
Answer custom user prompts with ai.generate_response
The ai.generate_response
function invokes AI to generate custom text based on your own instructions. For more detailed instructions about the use of ai.generate_response
, visit this article.
Sample usage
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/
df = pd.DataFrame([
("Scarves"),
("Snow pants"),
("Ski goggles")
], columns=["product"])
df["response"] = df.ai.generate_response("Write a short, punchy email subject line for a winter sale.")
display(df)
Related content
- Calculate similarity with
ai.similarity
. - Detect sentiment with
ai.analyze_sentiment
. - Categorize text with
ai.classify
. - Extract entities with
ai_extract
. - Fix grammar with
ai.fix_grammar
. - Summarize text with
ai.summarize
. - Translate text with
ai.translate
. - Answer custom user prompts with
ai.generate_response
. - Learn how to customize the configuration of AI functions.
- Did we miss a feature you need? Suggest it on the Fabric Ideas forum.