File size: 1,134 Bytes
c96bd62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
This model is based on a custom Transformer model that can be installed with:

```bash
pip install git+https://github.com/lucadiliello/bleurt-pytorch.git
```

Now load the model and make predictions with:

```python
import torch
from bleurt_pytorch import BleurtConfig, BleurtForSequenceClassification, BleurtTokenizer

config = BleurtConfig.from_pretrained('lucadiliello/bleurt-large-512')
model = BleurtForSequenceClassification.from_pretrained('lucadiliello/bleurt-large-512')
tokenizer = BleurtTokenizer.from_pretrained('lucadiliello/bleurt-large-512')

references = ["a bird chirps by the window", "this is a random sentence"]
candidates = ["a bird chirps by the window", "this looks like a random sentence"]

model.eval()
with torch.no_grad():
    inputs = tokenizer(references, candidates, padding='longest', return_tensors='pt')
    res = model(**inputs).logits.flatten().tolist()
print(res)
# [1.0721179246902466, 0.8036927580833435]
```

Take a look at this [repository](https://github.com/lucadiliello/bleurt-pytorch) for the definition of `BleurtConfig`, `BleurtForSequenceClassification` and `BleurtTokenizer` in PyTorch.