Skip to content

Commit c141860

Browse files
authored
Merge pull request #33 from Azure-Samples/delegenz
Updating Service Creation, AML Config, and a few other items
2 parents 1a4b352 + 0910a6f commit c141860

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

AzureML-Custom-Skill/notebook/custom_skill_azureml.ipynb

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"\n",
2222
"To train the aspect-based sentiment model, you will be using the [nlp recipes repository](https://github.com/microsoft/nlp-recipes/tree/master/examples/sentiment_analysis/absa). The model will then be deployed as an endpoint on an Azure Kubernetes cluster. Once deployed, the model is added to the enrichment pipeline as a custom skill for use by the Cognitive Search service.\n",
2323
"\n",
24-
"There are two datasets provided. To train the model the larger of the two datasets, the hotel_reviews_1000.csv, is required. Prefer to skip the training step? Download the hotel_reviews_100.csv.\n",
24+
"There are two datasets provided. To train the model the larger of the two datasets, the `hotel_reviews_1000.csv`, is required. Prefer to skip the training step? Download the `hotel_reviews_100.csv`.\n",
2525
"\n",
2626
"## Prerequisites\n",
2727
"\n",
@@ -177,16 +177,17 @@
177177
"\n",
178178
"headers = {'api-key': api_key, 'Content-Type': content_type}\n",
179179
"# Test out the URLs to ensure that the configuration works\n",
180-
"print(construct_Url(search_service, \"indexes\", \"custom-ner\", \"analyze\", api_version))\n",
181-
"print(construct_Url(search_service, \"indexes\", \"custom-ner\", None, api_version))\n",
180+
"print(construct_Url(search_service, \"indexes\", \"azureml-sentiment\", \"analyze\", api_version))\n",
181+
"print(construct_Url(search_service, \"indexes\", \"azureml-sentiment\", None, api_version))\n",
182182
"print(construct_Url(search_service, \"indexers\", None, None, api_version))"
183183
]
184184
},
185185
{
186186
"cell_type": "markdown",
187187
"metadata": {},
188188
"source": [
189-
"## 1.1 Create datasource"
189+
"## 1.1 Create datasource\n",
190+
"Be sure to upload `hotel_reviews_1000.csv` or `hotel_reviews_100.csv` to your storage account before continuing."
190191
]
191192
},
192193
{
@@ -195,17 +196,15 @@
195196
"metadata": {},
196197
"outputs": [],
197198
"source": [
198-
"# Replace with the container name, storage account name, storage account connection string\n",
199199
"container = datasource_container\n",
200200
"\n",
201-
"\n",
202201
"datsource_def = {\n",
203202
" 'name': f'{datasource_container}-ds',\n",
204-
" 'description': f'km-aml solution accelerator- Datasource to label and extract custom entities from a corpus in STORAGEACCOUNTNAME, container datasource_container',\n",
203+
" 'description': f'Datasource with hotel reviews',\n",
205204
" 'type': 'azureblob',\n",
206205
" 'subtype': None,\n",
207206
" 'credentials': {\n",
208-
" 'connectionString': f'STORAGECONNSTRING'\n",
207+
" 'connectionString': f'{STORAGECONNSTRING}'\n",
209208
" },\n",
210209
" 'container': {\n",
211210
" 'name': f'{datasource_container}'\n",
@@ -233,8 +232,7 @@
233232
"source": [
234233
"skillset_name = f'{datasource_container}-ss'\n",
235234
"skillset_def = {\n",
236-
" '@odata.etag': '\\'0x8D7F6C769AC06B2\\'',\n",
237-
" 'name': f'skillset_name',\n",
235+
" 'name': f'{skillset_name}',\n",
238236
" 'description': 'Skillset to enrich hotel reviews with aspect based sentiment',\n",
239237
" 'skills': [\n",
240238
" {\n",
@@ -482,16 +480,16 @@
482480
" 'cognitiveServices': {\n",
483481
" '@odata.type': '#Microsoft.Azure.Search.CognitiveServicesByKey',\n",
484482
" 'description': '/subscriptions/subscription_id/resourceGroups/resource_group/providers/Microsoft.CognitiveServices/accounts/cog_svcs_acct',\n",
485-
" 'key': f'cog_svcs_key'\n",
483+
" 'key': f'{cog_svcs_key}'\n",
486484
" },\n",
487485
" 'knowledgeStore': {\n",
488-
" 'storageConnectionString': f'STORAGECONNSTRING',\n",
486+
" 'storageConnectionString': f'{STORAGECONNSTRING}',\n",
489487
" 'projections': [\n",
490488
" {\n",
491489
" 'tables': [],\n",
492490
" 'objects': [\n",
493491
" {\n",
494-
" 'storageContainer': f'datasource_container-enriched',\n",
492+
" 'storageContainer': f'{datasource_container}-enriched',\n",
495493
" 'referenceKeyName': None,\n",
496494
" 'generatedKeyName': None,\n",
497495
" 'source': '/document/objectprojection',\n",
@@ -527,7 +525,7 @@
527525
"source": [
528526
"indexname = f'{datasource_container}-idx'\n",
529527
"index_def = {\n",
530-
" \"name\":f'indexname',\n",
528+
" \"name\":f'{indexname}',\n",
531529
" \"defaultScoringProfile\": \"\",\n",
532530
" \"fields\": [\n",
533531
" {\n",
@@ -1024,7 +1022,7 @@
10241022
"source": [
10251023
"indexername = f'{datasource_container}-idxr'\n",
10261024
"indexer_def = {\n",
1027-
" \"name\": f'indexername',\n",
1025+
" \"name\": f'{indexername}',\n",
10281026
" \"description\": \"Indexer to enrich hotel reviews\",\n",
10291027
" \"dataSourceName\": f'{datasource_container}-ds',\n",
10301028
" \"skillsetName\": f'{datasource_container}-ss',\n",
@@ -1076,7 +1074,7 @@
10761074
" ],\n",
10771075
" \"cache\": {\n",
10781076
" \"enableReprocessing\": True,\n",
1079-
" \"storageConnectionString\": f'know_store_cache'\n",
1077+
" \"storageConnectionString\": f'{know_store_cache}'\n",
10801078
" }\n",
10811079
"}\n",
10821080
"r = requests.post(construct_Url(search_service, \"indexers\", None, None, api_version), data=json.dumps(indexer_def), headers=headers)\n",
@@ -1142,8 +1140,8 @@
11421140
},
11431141
"outputs": [],
11441142
"source": [
1145-
"!pip install azure-storage-blob\n",
1146-
"!pip install --upgrade azureml-sdk"
1143+
"%pip install azure-storage-blob\n",
1144+
"%pip install --upgrade azureml-sdk"
11471145
]
11481146
},
11491147
{
@@ -1161,11 +1159,12 @@
11611159
"source": [
11621160
"from azureml.core import Workspace, Datastore\n",
11631161
"try:\n",
1164-
" ws = Workspace.from_config()\n",
1162+
" ws = Workspace(subscription_id, resource_group, workspace_name)\n",
11651163
" print(ws.name, ws.location, ws.resource_group, ws.location, sep='\\t')\n",
11661164
" print('Library configuration succeeded')\n",
11671165
"except:\n",
11681166
" print('Workspace not found')\n",
1167+
" \n",
11691168
"ds = ws.get_default_datastore()"
11701169
]
11711170
},
@@ -1496,8 +1495,22 @@
14961495
"metadata": {},
14971496
"outputs": [],
14981497
"source": [
1499-
"docs = [ \"Great\", \"The bathroom sink splashes water, need to be fixed. The bathtub/shower make loud noises. Other than that, it was a good stay.\" ]\n",
1498+
"%pip install git+https://github.com/NervanaSystems/nlp-architect.git@absa --user"
1499+
]
1500+
},
1501+
{
1502+
"cell_type": "code",
1503+
"execution_count": null,
1504+
"metadata": {},
1505+
"outputs": [],
1506+
"source": [
1507+
"from nlp_architect.models.absa.inference.inference import SentimentInference\n",
15001508
"\n",
1509+
"aspect_lex_path = \"../models/hotel_aspect_lex.csv\"\n",
1510+
"opinion_lex_path = \"../models/hotel_opinion_lex_reranked.csv\"\n",
1511+
"inference = SentimentInference(aspect_lex_path, opinion_lex_path)\n",
1512+
"\n",
1513+
"docs = [ \"Great\", \"The bathroom sink splashes water, need to be fixed. The bathtub/shower make loud noises. Other than that, it was a good stay.\" ]\n",
15011514
"sentiment_docs = []\n",
15021515
"\n",
15031516
"for doc_raw in docs:\n",
@@ -1772,7 +1785,7 @@
17721785
"source": [
17731786
"## Endpoint Deployed!\n",
17741787
"\n",
1775-
"Next, add the endpoint in as a Azure ML skill. Either follow the instructions in (the tutorial)[https://docs.microsoft.com/azure/search/cognitive-search-tutorial-aml-custom-skill] to add the skill in the portal or continue through the notebook for the API experience.\n",
1788+
"Next, add the endpoint in as a Azure ML skill. Either follow the instructions in [the tutorial](https://docs.microsoft.com/azure/search/cognitive-search-tutorial-aml-custom-skill) to add the skill in the portal or continue through the notebook for the API experience.\n",
17761789
"\n",
17771790
"## 4.0 Add AML Skill - Update Skillset"
17781791
]
@@ -1795,7 +1808,6 @@
17951808
"outputs": [],
17961809
"source": [
17971810
"skillset_def = {\n",
1798-
" '@odata.etag': '\\'0x8D7F6C769AC06B2\\'',\n",
17991811
" 'name': f'{skillset_name}',\n",
18001812
" 'description': 'Skillset to enrich hotel reviews with aspect based sentiment',\n",
18011813
" 'skills': [\n",
@@ -2207,7 +2219,7 @@
22072219
"name": "python",
22082220
"nbconvert_exporter": "python",
22092221
"pygments_lexer": "ipython3",
2210-
"version": "3.6.5"
2222+
"version": "3.7.3"
22112223
}
22122224
},
22132225
"nbformat": 4,

AzureML-Custom-Skill/training-data/hotels_train.csv renamed to AzureML-Custom-Skill/notebook/training-data/hotels_train.csv

File renamed without changes.

0 commit comments

Comments
 (0)