Spaces:
Runtime error
Runtime error
Commit
Β·
6cfc7f3
1
Parent(s):
f53b36c
XL
Browse files
app.py
CHANGED
|
@@ -7,15 +7,13 @@ device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cp
|
|
| 7 |
|
| 8 |
class Interactive:
|
| 9 |
def __init__(self):
|
| 10 |
-
print('Init invoked')
|
| 11 |
self.tokenizer = transformers.AutoTokenizer.from_pretrained('liujch1998/cd-pi', use_auth_token=os.environ['HF_TOKEN_DOWNLOAD'])
|
| 12 |
-
self.model = transformers.
|
| 13 |
self.linear = torch.nn.Linear(self.model.shared.embedding_dim, 1).to(device)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
self.model.eval()
|
| 17 |
self.t = 2.2247
|
| 18 |
-
print('Init finished')
|
| 19 |
|
| 20 |
def run(self, statement):
|
| 21 |
input_ids = self.tokenizer.batch_encode_plus([statement], return_tensors='pt', padding='longest').input_ids.to(device)
|
|
|
|
| 7 |
|
| 8 |
class Interactive:
|
| 9 |
def __init__(self):
|
|
|
|
| 10 |
self.tokenizer = transformers.AutoTokenizer.from_pretrained('liujch1998/cd-pi', use_auth_token=os.environ['HF_TOKEN_DOWNLOAD'])
|
| 11 |
+
self.model = transformers.T5EncoderModel.from_pretrained('liujch1998/cd-pi', use_auth_token=os.environ['HF_TOKEN_DOWNLOAD']).to(device)
|
| 12 |
self.linear = torch.nn.Linear(self.model.shared.embedding_dim, 1).to(device)
|
| 13 |
+
self.linear.weight = torch.nn.Parameter(self.model.shared.weight[32099, :].unsqueeze(0)) # (1, D)
|
| 14 |
+
self.linear.bias = torch.nn.Parameter(self.model.shared.weight[32098, 0].unsqueeze(0)) # (1)
|
| 15 |
self.model.eval()
|
| 16 |
self.t = 2.2247
|
|
|
|
| 17 |
|
| 18 |
def run(self, statement):
|
| 19 |
input_ids = self.tokenizer.batch_encode_plus([statement], return_tensors='pt', padding='longest').input_ids.to(device)
|