Skip to content

Instantly share code, notes, and snippets.

View maxbrenner-ai's full-sized avatar

Max Brenner maxbrenner-ai

View GitHub Profile
@maxbrenner-ai
maxbrenner-ai / ajax_aws_model.js
Created August 26, 2020 16:41
call model with ajax
$.ajax({
type: "POST",
url: "https://a3bqc81dv1.execute-api.us-east-2.amazonaws.com/test/myLambdaFunction",
data: JSON.stringify({'hyperparmeter_1': 0, 'hyperparameter_2': 0,'data': csv_text}),
contentType: 'text/plain',
success: function(success){
console.log(success);
},
error: function(error){
console.log(error)
@maxbrenner-ai
maxbrenner-ai / lambda_function.py
Last active August 26, 2020 00:52
lambda function code
import os
import io
import boto3
import json
import csv
# grab environment variables
ENDPOINT_NAME = os.environ['ENDPOINT_NAME']
# grab runtime client
@maxbrenner-ai
maxbrenner-ai / sagemaker_deploy.py
Created August 25, 2020 23:51
sagemaker deploy model - deploy
endpoint_name = 'anomaly-detection-endpoint'
anomaly_detection.deploy(initial_instance_count=1,
instance_type='ml.t2.medium',
endpoint_name=endpoint_name)
# Delete endpoint when you don't need your model deployed
sm.delete_endpoint(EndpointName=endpoint_name)
@maxbrenner-ai
maxbrenner-ai / sagemaker_fit.py
Created August 25, 2020 23:49
sagemaker deploy model - fit
anomaly_detection.fit()
@maxbrenner-ai
maxbrenner-ai / sagemaker_create.py
Last active August 25, 2020 23:49
sagemaker deploy model - estimator
sess = sagemaker.session.Session()
anomaly_detection = sagemaker.estimator.Estimator(image_name=docker_image_name,
role=role,
train_instance_count=1,
train_instance_type='ml.m4.xlarge',
output_path='s3://{}/{}/output'.format(bucket, prefix),
base_job_name="anomaly-detection",
sagemaker_session=sess)
@maxbrenner-ai
maxbrenner-ai / sagemaker_setup.py
Created August 25, 2020 23:47
sagemaker deploy model code - setup
# Install sagemaker (version 1.72)
import sys
!{sys.executable} -m pip install --quiet sagemaker==1.72 -U
# Imports
import io
import os
import sys
import time
import json
@maxbrenner-ai
maxbrenner-ai / train
Created August 25, 2020 18:21
docker model train script
prefix = '/opt/ml/'
input_path = prefix + 'input/data'
output_path = os.path.join(prefix, 'output')
model_path = os.path.join(prefix, 'model')
# The function to execute the training.
def train():
print('\nStarting the training.')
with open(os.path.join(model_path, 'model'), 'w') as f:
@maxbrenner-ai
maxbrenner-ai / dqn_agent.py
Created November 23, 2018 20:04
diagram of rule-based policy
For example, say rule_requests = ['moviename', 'starttime', 'city'], length: 3
Round 1:
rule_current_slot_index = 0 (< 3)
|
[request 'moviename', request 'starttime', request 'city', mach_found, done]
Round 2:
rule_current_slot_index = 1 (< 3)
|
@maxbrenner-ai
maxbrenner-ai / action_examples.txt
Created November 22, 2018 04:16
action examples for agent and user simulator
# Agent action examples:
{'intent': 'request', 'inform_slots': {}, 'request_slots': {'theater': 'UNK'}}
{'intent': 'inform', 'inform_slots': {'moviename': 'the witch'}, 'request_slots': {}}
{'intent': 'done', 'inform_slots': {}, 'request_slots': {}}
# User action examples:
{'intent': 'request', 'inform_slots': {'city': 'seattle'}, 'request_slots': {'theater': 'UNK', 'starttime': 'UNK'}}
{'intent': 'inform', 'inform_slots': {'moviename': 'the witch'}, 'request_slots': {}}
{'intent': 'done', 'inform_slots': {}, 'request_slots': {}}
{'intent': 'request', 'inform_slots': {}, 'request_slots': {'moviename': 'UNK'}}
@maxbrenner-ai
maxbrenner-ai / action_examples.txt
Created November 22, 2018 03:09
examples of actions as semantic frames
{'intent': 'request', 'inform_slots': {'city': 'seattle'}, 'request_slots': {'theater': 'UNK', 'starttime': 'UNK'}}
{'intent': 'inform', 'inform_slots': {'moviename': 'the witch'}, 'request_slots': {}}
{'intent': 'done', 'inform_slots': {}, 'request_slots': {}}
{'intent': 'request', 'inform_slots': {}, 'request_slots': {'moviename': 'UNK'}}
{'intent': 'thanks', 'inform_slots': {}, 'request_slots': {'theater': 'UNK'}}