Skip to content

Commit

Permalink
docs: use the new AnalyzeText API in docs(#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaXYWang committed Nov 10, 2023
1 parent 5cd78c9 commit 90ded80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
},
"outputs": [],
"source": [
"from synapse.ml.services.text import TextSentiment\n",
"from synapse.ml.services.language import AnalyzeText\n",
"\n",
"# Create a dataframe\n",
"text_df = spark.createDataFrame(\n",
Expand All @@ -314,7 +314,8 @@
")\n",
"\n",
"sentiment = (\n",
" TextSentiment()\n",
" AnalyzeText()\n",
" .setKind(\"SentimentAnalysis\")\n",
" .setTextCol(\"text\")\n",
" .setLocation(service_loc)\n",
" .setSubscriptionKey(service_key)\n",
Expand All @@ -324,7 +325,7 @@
")\n",
"\n",
"# Show the results of your text query\n",
"display(sentiment.transform(text_df).select(\"text\", \"sentiment.document.sentiment\"))"
"display(sentiment.transform(text_df).select(\"text\", \"sentiment.documents.sentiment\"))"
]
},
{
Expand Down Expand Up @@ -356,7 +357,6 @@
},
"outputs": [],
"source": [
"from synapse.ml.services.text import TextSentiment\n",
"from pyspark.sql.functions import udf\n",
"import random\n",
"\n",
Expand Down
9 changes: 5 additions & 4 deletions docs/Explore Algorithms/AI Services/Overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"\n",
"\n",
"### Language\n",
"[**Text Analytics**](https://azure.microsoft.com/services/cognitive-services/text-analytics/)\n",
"[**AI Language**](https://azure.microsoft.com/products/ai-services/ai-language)\n",
"- Language detection: detects language of the input text ([Scala](https://mmlspark.blob.core.windows.net/docs/1.0.1/scala/com/microsoft/azure/synapse/ml/services/text/LanguageDetector.html), [Python](https://mmlspark.blob.core.windows.net/docs/1.0.1/pyspark/synapse.ml.services.text.html#module-synapse.ml.services.text.LanguageDetector))\n",
"- Key phrase extraction: identifies the key talking points in the input text ([Scala](https://mmlspark.blob.core.windows.net/docs/1.0.1/scala/com/microsoft/azure/synapse/ml/services/text/KeyPhraseExtractor.html), [Python](https://mmlspark.blob.core.windows.net/docs/1.0.1/pyspark/synapse.ml.services.text.html#module-synapse.ml.services.text.KeyPhraseExtractor))\n",
"- Named entity recognition: identifies known entities and general named entities in the input text ([Scala](https://mmlspark.blob.core.windows.net/docs/1.0.1/scala/com/microsoft/azure/synapse/ml/services/text/NER.html), [Python](https://mmlspark.blob.core.windows.net/docs/1.0.1/pyspark/synapse.ml.services.text.html#module-synapse.ml.services.text.NER))\n",
Expand Down Expand Up @@ -194,7 +194,7 @@
"source": [
"## Perform sentiment analysis on text\n",
"\n",
"The [Text Analytics](https://azure.microsoft.com/services/ai-services/text-analytics/) service provides several algorithms for extracting intelligent insights from text. For example, we can find the sentiment of given input text. The service will return a score between 0.0 and 1.0 where low scores indicate negative sentiment and high score indicates positive sentiment. This sample uses three simple sentences and returns the sentiment for each."
"The [AI Language](https://azure.microsoft.com/products/ai-services/ai-language/) service provides several algorithms for extracting intelligent insights from text. For example, we can find the sentiment of given input text. The service will return a score between 0.0 and 1.0 where low scores indicate negative sentiment and high score indicates positive sentiment. This sample uses three simple sentences and returns the sentiment for each."
]
},
{
Expand All @@ -215,7 +215,8 @@
"\n",
"# Run the Text Analytics service with options\n",
"sentiment = (\n",
" TextSentiment()\n",
" AnalyzeText()\n",
" .setKind(\"SentimentAnalysis\")\n",
" .setTextCol(\"text\")\n",
" .setLocation(service_loc)\n",
" .setSubscriptionKey(service_key)\n",
Expand All @@ -227,7 +228,7 @@
"# Show the results of your text query in a table format\n",
"display(\n",
" sentiment.transform(df).select(\n",
" \"text\", col(\"sentiment.document.sentiment\").alias(\"sentiment\")\n",
" \"text\", col(\"sentiment.documents.sentiment\").alias(\"sentiment\")\n",
" )\n",
")"
]
Expand Down
17 changes: 4 additions & 13 deletions docs/Get Started/Quickstart - Your First Models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,16 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"application/vnd.databricks.v1+cell": {
"inputWidgets": {},
"nuid": "f22b1c1a-b0c9-43e9-bcb0-b29624b4a76a",
"showTitle": false,
"title": ""
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"from synapse.ml.services.text import TextSentiment\n",
"from synapse.ml.services.language import AnalyzeText\n",
"from synapse.ml.core.platform import find_secret\n",
"\n",
"model = TextSentiment(\n",
"model = AnalyzeText(\n",
" textCol=\"text\",\n",
" outputCol=\"sentiment\",\n",
" kind=\"SentimentAnalysis\",\n",
" subscriptionKey=find_secret(\n",
" secret_name=\"ai-services-api-key\", keyvault=\"mmlspark-build-keys\"\n",
" ), # Replace the call to find_secret with your key as a python string.\n",
Expand Down

0 comments on commit 90ded80

Please sign in to comment.