example.py 569 Bytes
Newer Older
thomwolf's avatar
thomwolf committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""
Show how to use HuggingFace's PyTorch implementation of Google's BERT Model.
"""
from .bert_model import BERT
from .prepare_inputs import DataPreprocessor

bert_model = BERT()
bert_model.load_from('.')
data_processor = DataProcessor(encoder_file_path='.')

input_sentence = "We are playing with the BERT model."
print("BERT inputs: {}".format(input_sentence))

tensor_input = data_processor.encode(input_sentence)
tensor_output = bert_model(prepared_input)
output_sentence = data_processor.decode(tensor_output)

print("BERT predicted: {}".format(output_sentence))