INNER CODE UNIT · Python

load_model

graviraja/100-Days-of-NLP · applications/generation/utterance_generation/app/app.py:13

def load_model():
    model.load_state_dict(torch.load(os.path.join("model", 'model.pt'), map_location=torch.device('cpu')))

bpe_model = youtokentome.BPE(model=os.path.join("model", "bpe.model"))
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

def bpe_tokenizer(sentence):
    encoded_ids = bpe_model.encode(sentence.lower(), output_type=youtokentome.OutputType.ID, bos=True, eos=True)
    return encoded_ids


def generate_utterance_greedy(sentence, bpe_model, model, device, max_len=50):
    model.eval()

    if isinstance(sentence, str):
        tokens = bpe_tokenizer(sentence)
    else:
        tokens = [int(token) for token in sentence]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…