This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from pytorch_pretrained_bert import BertForMaskedLM, BertTokenizer | |
import random | |
# Requires pytorch_pretrained_bert: https://github.com/huggingface/pytorch-pretrained-BERT | |
# returns the probabilities over the vocabulary for the masked words in sent | |
def get_preds(sent): | |
tokenized = bert_tokenizer.tokenize(sent) | |
tokenized = ['[CLS]'] + ['[MASK]' if x == 'mask' else x for x in tokenized] + ['[SEP]'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def rmsle(h, y): | |
""" | |
Compute the Root Mean Squared Log Error for hypthesis h and targets y | |
Args: | |
h - numpy array containing predictions with shape (n_samples, n_targets) | |
y - numpy array containing targets with shape (n_samples, n_targets) | |
""" |