PeteBleackley commited on
Commit
cce945c
1 Parent(s): 3340c72

Created HuggingFace Space

Browse files
Files changed (3) hide show
  1. app.py +15 -0
  2. qarac/corpora/CombinedCorpus.py +4 -3
  3. scripts.py +2 -0
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Oct 11 10:26:15 2023
5
+
6
+ @author: peter
7
+ """
8
+
9
+ import gradio as gr
10
+
11
+ def greet(name):
12
+ return "Hello " + name + "!!"
13
+
14
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
15
+ iface.launch()
qarac/corpora/CombinedCorpus.py CHANGED
@@ -145,11 +145,11 @@ class CombinedCorpus(torch.utils.data.IterableDataset):
145
 
146
  X={key:self.pad(value,self.max_lengths[key])
147
  for (key,value) in X.items()}
148
- Y={key:torch.tensor(value).float() if key=='consistency' else self.pad(value,
149
  self.max_lengths[key],
150
  False)
151
  for (key,value) in Y.items()}
152
- Y['question_answering'] = torch.zeros((n,768))
153
  return (X,
154
  tuple([Y[key]
155
  for key in ('encode_decode',
@@ -175,7 +175,8 @@ class CombinedCorpus(torch.utils.data.IterableDataset):
175
  for sample in batch:
176
  sample.pad(maxlen,pad_id=self.pad_token)
177
  input_ids = torch.tensor([sample.ids
178
- for sample in batch])
 
179
  result = input_ids
180
  if inputs:
181
  attention_mask = torch.not_equal(input_ids,
 
145
 
146
  X={key:self.pad(value,self.max_lengths[key])
147
  for (key,value) in X.items()}
148
+ Y={key:torch.tensor(value,device='cuda').float() if key=='consistency' else self.pad(value,
149
  self.max_lengths[key],
150
  False)
151
  for (key,value) in Y.items()}
152
+ Y['question_answering'] = torch.zeros((n,768),device='cuda')
153
  return (X,
154
  tuple([Y[key]
155
  for key in ('encode_decode',
 
175
  for sample in batch:
176
  sample.pad(maxlen,pad_id=self.pad_token)
177
  input_ids = torch.tensor([sample.ids
178
+ for sample in batch],
179
+ device='cuda')
180
  result = input_ids
181
  if inputs:
182
  attention_mask = torch.not_equal(input_ids,
scripts.py CHANGED
@@ -135,7 +135,9 @@ def train_models(path):
135
  tokenizer = tokenizers.Tokenizer.from_pretrained('roberta-base')
136
  trainer = qarac.models.QaracTrainerModel.QaracTrainerModel('roberta-base',
137
  tokenizer)
 
138
  loss_fn = CombinedLoss()
 
139
  optimizer = torch.optim.NAdam(trainer.parameters(),lr=5.0e-5)
140
  scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer,gamma=0.9)
141
  training_data = qarac.corpora.CombinedCorpus.CombinedCorpus(tokenizer,
 
135
  tokenizer = tokenizers.Tokenizer.from_pretrained('roberta-base')
136
  trainer = qarac.models.QaracTrainerModel.QaracTrainerModel('roberta-base',
137
  tokenizer)
138
+ trainer.cuda()
139
  loss_fn = CombinedLoss()
140
+ loss_fn.cuda()
141
  optimizer = torch.optim.NAdam(trainer.parameters(),lr=5.0e-5)
142
  scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer,gamma=0.9)
143
  training_data = qarac.corpora.CombinedCorpus.CombinedCorpus(tokenizer,