File size: 701 Bytes
4c14fe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
West et al.'s model from their "reflective decoding" paper. 

Sample usage: 

```python
import torch
from modeling_opengpt2 import OpenGPT2LMHeadModel
from padded_encoder import Encoder

path_to_backward = 'danyaljj/opengpt2_pytorch_backward'

encoder = Encoder()
model_backward = OpenGPT2LMHeadModel.from_pretrained(path_to_backward)

input = "until she finally won."
input_ids = encoder.encode(input)
input_ids = torch.tensor([input_ids[::-1] ], dtype=torch.int)
print(input_ids)

output = model_backward.generate(input_ids)

output_text = encoder.decode(output.tolist()[0][::-1])

print(output_text)
```

Download the additional files from here: https://github.com/peterwestuw/GPT2ForwardBackward