def calculate_perplexity(transactions: List[List[int]], predictor: Predictor) -> float: perplexities = [] for tr in transactions: out = predictor.predict_json( { "transactions": tr, "amounts": tr } ) perp = math.exp(out["loss"]) perplexities.append(perp) return sum(perplexities) / len(perplexities)
def _caching_prediction(model: Predictor, data: str) -> JsonDict: """ Just a wrapper around ``model.predict_json`` that allows us to use a cache decorator. """ return model.predict_json(json.loads(data))
def predict_json(self, input_json: Dict[str, Any], predictor: Predictor): input_json = input_json if input_json else { "sentence": "A good movie!" } output = predictor.predict_json(input_json) return output
def predict_json(input_json: Dict[str, Any], predictor: Predictor): input_json = input_json if input_json else {"sentence": "A good movie!"} output = predictor.predict_json(input_json) print(output)