# Copyright (c) Togaware Pty Ltd. All rights reserved. # Licensed under the MIT License. # Author: [email protected] # # ml demo azcv # # This demo is based on the Quick Start. # # https://pypi.org/project/azure-cognitiveservices-vision-computervision from mlhub.pkg import mlask, mlcat, mlpreview, get_private mlcat( "Azure Computer Vision API", """\ Welcome to a demo of pre-built models for Computer Vision available as Cognitive Services on Azure. Azure supports various operations related to Computer Vision and this package demonstrates them and provides command line tools for specific tasks, including tag, describe, landmark, ocr, and thumbnail. """) # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- # Import the required libraries. import os import io # Create local image. import sys import time
# -*- coding: utf-8 -*- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # Author: [email protected] # # This demo is based on the Quick Start published on Azure. from mlhub.pkg import azkey, azrequest, mlask, mlcat mlcat( "Azure Anomaly Detector", """\ Welcome to a demo of the pre-built model for Anomaly Detection. This Azure Service supports the identification of anomalies in time series data. """) import os import json import statistics from textwrap import fill # Constants. SERVICE = "Anomaly Detector" KEY_FILE = os.path.join(os.getcwd(), "private.txt") DATA_FILE = "request.json" # URLs for anomaly detection with the Anomaly Detector API. BATCH_URL = "anomalydetector/v1.0/timeseries/entire/detect" LATEST_URL = "anomalydetector/v1.0/timeseries/last/detect"
# # This demo using a pre-built model from # https://github.com/zymlnlp/Tweets-Sentiment-Analysis import torch import warnings from preprocessing import tokenizer from nlp_model import SentimentClassifier from mlhub.pkg import mlask, mlcat mlcat("Zeyu Gao's Sentiment Analysis Pre-Built Model", """\ Welcome to a demo of Zeyu Gao's pre-built model for Sentiment Analysis. Sentiment analysis is an example application of Natural Language Processing (NLP). Sentences are assessed by the model to capture their sentiment. See https://onepager.togaware.com. The model load may take a few seconds. """) warnings.filterwarnings("ignore") sentiment_map = {2: "neutral", 1: "positive", 0: "negative"} device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") MAX_LEN = 256 # Load the model.
# Author: [email protected] # # This demo is based on the Quick Start published on Azure. # # https://docs.microsoft.com/en-us/azure/machine-learning/service/tutorial-train-models-with-aml # https://docs.microsoft.com/en-us/python/api/overview/azure/ml/intro?view=azure-ml-py from mlhub.pkg import azkey, azrequest, mlask, mlcat, mlpreview mlcat( "Azure Machine Learning API", """\ Welcome to a demo of the Azure Machine Learning framework, built to support Data Scientists as they run experiments to build models based on best practice and machine learning algorithms. This demonstration illustrates the following capabilities: * Logging events, particularly experimental model performance; * Display logged information on a web-based dashboard. Note that this demonstration uses a cloud-based workspace which requires you to have an Azure subscription (free or paid). """) # pip3 install azureml-sdk[automl] from azureml.core import VERSION, Workspace, Experiment import time import os import sys import webbrowser
# ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- # Import the required libraries. from mlhub.pkg import mlask, mlcat, get_private from recognise import recognise from translate import translate_speech_to_text import azure.cognitiveservices.speech as speechsdk import os import sys mlcat("Speech Services", """\ Welcome to a demo of the pre-built models for Speech provided through Azure's Cognitive Services. The Speech cloud service supports speech to text, text to speech, speech translation and Speaker Recognition capabilities. """) # ---------------------------------------------------------------------- # Request subscription key and location from user. # ---------------------------------------------------------------------- key, location = get_private() # Recognition is experimental and is only available at present # 20210428 from the westus data centre. RECOGNISE_FLAG = (location == "westus") # ----------------------------------------------------------------------- # Set up a speech recognizer and synthesizer.
# Licensed under the MIT License. # Author: [email protected] from mlhub.pkg import mlask, mlcat MOVIELENS = '100k' # Select Movielens data size: 100k, 1m, 10m, or 20m. TOPK = 10 # Top k items to recommend. TITLEN = 45 # Truncation of titles in printing to screen. SMPLS = 10 # Number of observations to display. MOVDISP = 5 # Number of movies to display for a specific user. mlcat( "Microsoft Recommenders Best Practice", """\ Welcome to a demo of the Microsoft open source Recommendations toolkit. This is a Microsoft open source project though not a supported product. Pull requests are most welcome. This demo runs several recommender algorithms on the traditional MovieLens benchmark dataset which is freely available from https://grouplens.org/datasets/movielens/. """) # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- import sys stderr = sys.stderr stdout = sys.stdout devnull = open('/dev/null', 'w') sys.stderr = devnull
# Author: [email protected] # # A script to demo the computer vision best practice repo. # # ml demo cvbp # # From the Microsoft Best Practices Suite: Computer Vision # https://github.com/microsoft/ComputerVision from mlhub.pkg import mlask, mlcat mlcat( "Microsoft Computer Vision Best Practice", """\ Welcome to a demo of the Microsoft open source Computer Vision toolkit. This is a Microsoft open source project and is not a supported product. Pull requests are most welcome at https://github.com/microsoft/cvbp. This demo runs several examples of computer vision tasks. All of the functionality is also available as command line tools as part of this MLHub package. """) # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- from fastai.vision import models, Image from functools import partial from torchvision.models.detection import fasterrcnn_resnet50_fpn # Until this is pip installable we use a local copy! from utils_cv.classification.data import imagenet_labels
from mlhub.pkg import mlask, mlcat from IPython.display import display from collections import Counter from relm.mechanisms import LaplaceMechanism mlcat("Differentially Private Release Mechanism", """\ This demo is based on the Jupyter Notebook from the RelM package on github. RelM can be readily utilised for the differentially private release of data. In our demo database the records indicate the age group of each patient who received a COVID-19 test on 9 March 2020. Each patient is classified as belonging to one of eight age groups: 0-9, 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, and 70+. One common way to summarise this kind of data is with a histogram. That is, to report the number of patients that were classified as belonging to each age group. For this demonstration we will create a histogram for the actual data and then a histogram for differentially private data. The data is first loaded from a csv file. It simply consists of two columns, the first is the date and the scond is the age group.""") # Read the raw data. data = pd.read_csv("pcr_testing_age_group_2020-03-09.csv") mlask(True, True)
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # Author: [email protected] from mlhub.pkg import mlask, mlcat mlcat( 'Azure Language Understanding', """\ Welcome to a demo of LUIS, a language understanding module provided through Azure's Cognitive Services. This service takes a command string and returns an understanding of the intent of the command in the form of an operation to be performed on specific entities. """) mlask(end="\n") # Import the required libraries. import sys import requests from time import sleep from mlhub.pkg import get_private # ---------------------------------------------------------------------- # Request subscription key, endpoint and App ID from user. # ---------------------------------------------------------------------- subscription_key, endpoint, location, id = get_private() mlcat( "", """\ LUIS includes a set of prebuilt intents from a number of prebuilt domains for quickly adding common intents and utterances to conversational client
# # This demo is based on: # # https://github.com/anu-act-health-covid19-support/patientpaths from mlhub.pkg import mlask, mlcat, mlpreview from mlhub.utils import get_cmd_cwd mlcat( "Patient Pathways", """\ Runs a model of care algorithm to identify outcomes from a configured health care system. The input to the model consists of N cohorts (e.g., age groups, gender, socio-economic, etc.). What the cohort is does not really matter. For each cohort the daily presentations of patients in that cohort (i.e., the number of patients arriving each day to the health facility) is provided as input. These are split into mild and severe cases. For this demo a spreadsheet of daily presentations is loaded. The spreadsheet has two workbooks (tabs), one for the mild presentations and another for the severe presentations. Each column corresponds to a cohort and each row is a successive day. No headers are used in the spreadsheet. """) #---------------------------------------------------------------------- # Setup #---------------------------------------------------------------------- # Import the required libraries. import os
# https://github.com/JaidedAI/EasyOCR # Use the cached models. import os os.environ["MODULE_PATH"] = "cache" from mlhub.pkg import mlask, mlcat, mlpreview mlcat( "Easy OCR", """\ This is a very simple demo of EasyOCR from Jaided.ai. This demo will read an image from Wikipedia and recognise the text in Simplified Chinese and English. Text in both languages is detected. For the first run of the demo the models will be downloaded. This can take a minute or two, depending on your Internet connection. A window will then pop up to display the image. When requested you can press Enter to continue to the analysis without closing the image (making sure the console has focus rather than the image). """) # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- # Import the required libraries. import re import easyocr
import os import sys from geocode import geocode from mlhub.pkg import mlask, mlcat, get_private mlcat( "Bing Maps", """\ Welcome to Bing Maps REST service. This service can identify the latitude and longitude coordinates that correspond to the supplied location/address information. """) mlask(end="\n") # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- key = get_private()[0] mlcat( "GEOCODE", """\ Here's an example. We provide the location Priceline Pharmacy Albany Creek and Bing will attempt to match this using its extensive map data. The result includes the logitude, latitude, and neighbourhood bounding box, how good the match is, the type of the location, and a clean
from mlhub.pkg import azkey, azrequest, mlask, mlcat mlcat( "Text Classification of MultiNLI Sentences Using BERT", """\ To run through the demo quickly the QUICK_RUN flag is set to True and so uses a small subset of the data and a smaller number of epochs. The table below provides some reference running times on two machine configurations for the full dataset. |QUICK_RUN |Machine Configurations |Running time| |----------|----------------------------------------|------------| |False |4 CPUs, 14GB memory | ~19.5 hours| |False |1 NVIDIA Tesla K80 GPUs, 12GB GPU memory| ~ 1.5 hours| To avoid CUDA out-of-memory errors the BATCH_SIZE and MAX_LEN are reduced, resulting in a compromised model performance but one that can be computed on a typcial user's laptop. For best model performance this same script can be run on cloud compute (Azure) with the parameters set to their usual values. The first part of this demo will load a pre-built model, extend it with new data, and then test the performance on the new data. """) QUICK_RUN = True import sys import os import json import pandas as pd
# Licensed under the MIT License. # Author: [email protected] # # Based on the Azure Cognitive Services Text Analytics Quick Starts # # https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/ # quickstarts/python # quickstarts/python-sdk from mlhub.pkg import mlask, mlcat from utils import request_priv_info mlcat( "Azure Text Analytics", """\ Welcome to a demo of the pre-built models for Text Analytics provided through Azure's Cognitive Services. This service extracts information from text that we supply to it, providing information such as the language, key phrases, sentiment (0-1 as negative to positive), and entities. """) # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- # Import the required libraries. from textwrap import fill # pip3 install --upgrade --user azure-cognitiveservices-language-textanalytics from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
# Time-stamp: <Tuesday 2020-07-07 16:26:05 AEST Graham Williams> # # Copyright (c) Togaware Pty Ltd. All rights reserved. # Licensed under the MIT License. # Author: [email protected] # # This demo is based on the Azure Cognitive Services Translator Quick Starts # # https://github.com/MicrosoftTranslator/Text-Translation-API-V3-Python # from mlhub.pkg import mlask, mlcat, get_private mlcat( "Azure Text Translation", """\ Welcome to a demo of the pre-built models for Text Translation provided through Azure's Cognitive Services. This service translates text between multiple languages. """) mlask(end='\n') # ---------------------------------------------------------------------- # Setup # ---------------------------------------------------------------------- # Import the required libraries. import sys import requests # ---------------------------------------------------------------------- # Request subscription key and location from user.
def main(): # ----------------------------------------------------------------------- # Load pre-built models and samples # ----------------------------------------------------------------------- scorer = os.path.join(os.getcwd(), "deepspeech-0.9.3-models.scorer") model = os.path.join(os.getcwd(), "deepspeech-0.9.3-models.pbmm") audio = os.path.join(os.getcwd(), "audio-0.9.3.tar.gz") tar = tarfile.open(audio, "r:gz") tar.extractall() tar.close() audio_path = os.path.join(os.getcwd(), "audio") audio_file_list = [] for filename in os.listdir(audio_path): if not filename.startswith(".") and filename.endswith("wav"): audio_file_list.append( os.path.join(os.getcwd(), "audio/" + filename)) audio_file_list = sorted(audio_file_list) mlcat( "Deepspeech", """\ Welcome to a demo of Mozilla's Deepspeech pre-built model for speech to text. This model is trained by machine learning techniques based on Baidu's Deep Speech research paper (https://arxiv.org/abs/1412.5567), and implemented by Mozilla. In this demo we will play a number of audio files and then transcribe them to text using model. """) mlask(end="\n") msg = """\ The audio will be played and if you listen carefully you should hear: """ # ----------------------------------------------------------------------- # First audio # ----------------------------------------------------------------------- mlcat("Audio Example 1", msg + "\"Experience proves this.\"") mlask(begin="\n", end="\n") os.system(f'aplay {audio_file_list[0]} >/dev/null 2>&1') mlask(end="\n", prompt="Press Enter to transcribe this audio") ds, desired_sample_rate = utils.load(model, scorer, True, "", "", "", "") utils.deepspeech(ds, desired_sample_rate, audio_file_list[0], "demo", True, "", "", "") mlask(end="\n") # ----------------------------------------------------------------------- # Second audio # ----------------------------------------------------------------------- mlcat("Audio Example 2", msg + "\"Why should one halt on the way?\"") mlask(begin="\n", end="\n") os.system(f'aplay {audio_file_list[1]} >/dev/null 2>&1') mlask(end="\n", prompt="Press Enter to transcribe this audio") utils.deepspeech(ds, desired_sample_rate, audio_file_list[1], "demo", True, "", "", "") mlask(end="\n") # ----------------------------------------------------------------------- # Third audio # ----------------------------------------------------------------------- mlcat("Audio Example 3", msg + "\"Your power is sufficient I said.\"") mlask(begin="\n", end="\n") os.system(f'aplay {audio_file_list[2]} >/dev/null 2>&1') mlask(end="\n", prompt="Press Enter to transcribe this audio") utils.deepspeech(ds, desired_sample_rate, audio_file_list[2], "demo", True, "", "", "")