<jupyter_start><jupyter_text>Test Model Deployment  Load Data for Testing<jupyter_code>from azureml.core import Workspace

#TODO: Load workspace from configuration file and print the workspace variable, ws. 


print('Workspace configuration succeeded')
import numpy as np
import pandas as pd
from azureml.core.dataset import Dataset
from azureml.core import Workspace

# Load the car components labeled data from registered dataset
cardata_ds_name = 'connected_car_components'
cardata_ds = Dataset.get_by_name(workspace=ws, name=cardata_ds_name)

car_components_df = cardata_ds.to_pandas_dataframe()
data = car_components_df["text"].tolist()
labels = car_components_df["label"].tolist()

#TODO: Convert data and labels into arrays with np.asarray()

indices = np.arange(data.shape[0])                     
np.random.shuffle(indices)
data = data[indices]
labels = labels[indices]<jupyter_output><empty_output><jupyter_text>Prepare Test Data<jupyter_code>test_size = 10

x_test = data[0:test_size]
y_test = labels[0:test_size]

#TODO: Print the shape of the test sets<jupyter_output><empty_output><jupyter_text>Test DeploymentProvide the **Scoring URI** for the deployed ACI webservice<jupyter_code># provide the scoring URI
web_service_url = ''<jupyter_output><empty_output><jupyter_text>Make HTTP calls to test the deployed Webservice<jupyter_code>import requests
import json

headers = {'Content-Type':'application/json'}
response = requests.post(web_service_url, json.dumps(x_test.tolist()), headers=headers)
print('Predictions')
print(response.text)
print('Labels')
print(y_test)<jupyter_output><empty_output><jupyter_text>Use built-in Jupyter renderer for the Datasheet based on custom tags<jupyter_code>from IPython.core.display import display, Markdown
from markdown import markdown

def get_tag(tags, tagname):
    text = ''
    try:
        text = tags[tagname]
    except:
        print('Missing tag ' + tagname)
    finally:
        return text

    return text

def get_datasheet(tags):
    
    title = get_tag(tags, 'title')
    description = get_tag(tags, 'datasheet_description')
    details = get_tag(tags, 'details')
    date = get_tag(tags, 'date')
    modeltype = get_tag(tags, 'type')
    version = get_tag(tags, 'version')
    buildnumber = get_tag(tags, 'build_number')
    runid = get_tag(tags, 'run_id')
    helpresources = get_tag(tags, 'help')
    helpurl = get_tag(tags, 'help_url')
    usecase_primary = get_tag(tags, 'usecase_primary')
    usecase_secondary = get_tag(tags, 'usecase_secondary')
    usecase_outofscope = get_tag(tags, 'usecase_outofscope')
    dataset_description = get_tag(tags, 'dataset_description')
    motivation = get_tag(tags, 'motivation')
    caveats = get_tag(tags, 'caveats')

    datasheet = ''
    datasheet+=markdown(f'# {title} \n {description} \n')
    datasheet+=markdown(f'## Model Details \n {details} \n')
    datasheet+=markdown(f'### Model date \n {date} \n')
    datasheet+=markdown(f'### Model type \n {modeltype} \n')
    datasheet+=markdown(f'### Model version \n {version} \n')
    datasheet+=markdown(f'### Release build number \n {buildnumber} \n')
    datasheet+=markdown(f'### Training run id \n {runid} \n')
    datasheet+=markdown(f'### Where to send questions or comments about the model \n Please send questions or concerns using [{helpresources}]({helpurl}) \n')
    datasheet+=markdown('## Intended Uses:\n')
    datasheet+=markdown(f'### Primary use case \n {usecase_primary} \n')
    datasheet+=markdown(f'### Secondary use case \n {usecase_secondary} \n')
    datasheet+=markdown(f'### Out of scope \n {usecase_outofscope} \n')
    datasheet+=markdown('## Evaluation Data:\n')
    datasheet+=markdown(f'### Datasets \n {dataset_description} \n')
    datasheet+=markdown(f'### Motivation \n {motivation} \n')
    datasheet+=markdown(f'### Caveats \n {caveats} \n')

    return datasheet<jupyter_output><empty_output><jupyter_text>Get the deployed Model<jupyter_code>import azureml.core
from azureml.core.experiment import Experiment
from azureml.core.workspace import Workspace
from azureml.core.model import Model
from azureml.core.webservice import Webservice

model_name = 'compliance-classifier'
model_version = None

ws = Workspace.from_config()

#TODO: List the webservices by workspace and model_name

webservice = None
if(len(ws_list) > 0):
    webservice = ws_list[0]

if model_version != None:
    model = Model(ws, name=model_name, version=model_version)
    print('Model version:', model.version)
else:
    model = Model(ws, name=model_name)
    print('Model version:', model.version)<jupyter_output><empty_output><jupyter_text>Display the Datasheet for deployed Model<jupyter_code>display(Markdown(get_datasheet(model.tags)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.001473063973063973, 'mean_word_length': 5.40566037735849, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '20789', 'license': 'MIT', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1563, 'n_words': 380, 'path': 'Hands-on lab/notebooks/Test Deployment.ipynb', 'repo_name': 'tgokal/MCW-ML-Ops', 'size': '4752'}