README.md 885 Bytes
Newer Older
Thomas Wolf's avatar
Thomas Wolf committed
1
# pytorch-pretrained-BERT
thomwolf's avatar
thomwolf committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
A PyTorch version of Google's pretrained BERT model as described in

No bells and whitles, just:
- [one class](bert_model.py) with a clean commented version of Google's BERT model that can load the weights pre-trained by Google's authors,
- [another class](data_processor.py) with all you need to pre- and post-process text data for the model (tokenize and encode),
- and [a script](download_weigths.sh) to download Google's pre-trained weights.

Here is how to use these:

```python
from .bert_model import BERT
from .data_processor import DataProcessor

bert_model = BERT(bert_model_path='.')
data_processor = DataProcessor(bert_vocab_path='.')

input_sentence = "We are playing with the BERT model."

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