Skip to content

Instantly share code, notes, and snippets.

# Deserialize the Invoke request body into an object we can perform prediction on
input_object = input_fn(request_body, request_content_type)
# Load the model
model = model_fn(model_dir)
# Perform prediction on the deserialized object, with the loaded model
prediction = predict_fn(input_object, model)
# Serialize the prediction result into the desired response content type
import os
import json
import numpy as np
from joblib import load
import argparse
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score
from joblib import dump, load
from transformers import AutoTokenizer, AutoModel, TFAutoModel
MODEL = "cardiffnlp/twitter-roberta-base"
TOKENIZER_EMB = AutoTokenizer.from_pretrained(MODEL)
MODEL_EMB = AutoModel.from_pretrained(MODEL)
def preprocess(text):
new_text = []
for t in text.split(" "):
t = '@user' if t.startswith('@') and len(t) > 1 else t
sep_sol = [i*j for i,j in itertools.product(sol1.x, sol2.x)]
mse = np.sqrt(np.mean((sol_common.x-sep_sol)**2))
print("Difference:", mse)
bnds = tuple([(0, None)]*(num_sides2*num_sides1))
# remember number of probabilities
lookup_map = {}
for ni, piqj in enumerate(itertools.product(sides1, sides2)):
lookup_map[ni] = piqj
# common guesses
guess_common = np.ones(len(lookup_map))/len(lookup_map)
ini_guess1 = np.array([1/num_sides1]*num_sides1)
ini_guess2 = np.array([1/num_sides2]*num_sides2)
sol1 = minimize(sum_form, ini_guess1,
bounds=bnds1, constraints=[cons01, cons21], options={'maxiter':1001})
sol2 = minimize(sum_form, ini_guess2,
bounds=bnds2, constraints=[cons02, cons22], options={'maxiter':1001})
sides1 = np.arange(0, num_sides1)+1.
sides2 = np.arange(0, num_sides2)+1.
cons21 = ({'type': 'eq', 'fun': lambda p: sides1.dot(p) - mean1})
cons22 = ({'type': 'eq', 'fun': lambda q: sides2.dot(q) - mean2})
cons01 = ({'type': 'eq', 'fun': lambda p: np.sum(p) - 1.})
cons02 = ({'type': 'eq', 'fun': lambda p: np.sum(p) - 1.})
bnds1 = tuple([(0, None)]*(num_sides1))
bnds2 = tuple([(0, None)]*(num_sides2))
import numpy as np
from scipy.optimize import minimize
import pylab as plt
import itertools
num_sides1 = 6
num_sides2 = 10
mean1 = 4.5
mean2 = mean1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.