Spaces:
Build error
Build error
Update Main.py
Browse files
Main.py
CHANGED
|
@@ -8,24 +8,24 @@ from transformers import BertTokenizerFast, BertForTokenClassification
|
|
| 8 |
|
| 9 |
class Main:
|
| 10 |
def __init__(self):
|
| 11 |
-
MAX_LEN = 500
|
| 12 |
-
EPOCHS = 6
|
| 13 |
-
NUM_LABELS = 12
|
| 14 |
-
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
#MODEL_PATH = '../input/bert-base-uncased'
|
| 16 |
-
STATE_DICT = torch.load('./models/model_e6.tar', map_location=DEVICE)
|
| 17 |
#tokenizer = BertTokenizerFast('../input/bert-base-uncased/vocab.txt', lowercase=True)
|
| 18 |
-
tokenizer = BertTokenizerFast.from_pretrained('bert-base-cased')
|
| 19 |
MODEL = BertForTokenClassification.from_pretrained('bert-base-uncased', num_labels=12)
|
| 20 |
|
| 21 |
-
tags_vals = ["UNKNOWN", "O", "Name", "Degree","Skills","College Name","Email Address","Designation","Companies worked at","Graduation Year","Years of Experience","Location"]
|
| 22 |
-
tag2idx = {t: i for i, t in enumerate(tags_vals)}
|
| 23 |
-
idx2tag = {i:t for i, t in enumerate(tags_vals)}
|
| 24 |
|
| 25 |
-
data = self.trim_entity_spans(self.convert_dataturks_to_spacy('./data/annotated_resumes.json'))
|
| 26 |
|
| 27 |
-
model = MODEL
|
| 28 |
-
model.to(DEVICE);
|
| 29 |
|
| 30 |
|
| 31 |
def convert_dataturks_to_spacy(self,dataturks_JSON_FilePath):
|
|
@@ -117,7 +117,7 @@ class Main:
|
|
| 117 |
return final_data
|
| 118 |
|
| 119 |
def predict(self,test_resume):
|
| 120 |
-
model.eval()
|
| 121 |
data = self.process_resume(test_resume)
|
| 122 |
input_ids, input_mask = self.data['input_ids'].unsqueeze(0), self.data['attention_mask'].unsqueeze(0)
|
| 123 |
labels = torch.tensor([1] * input_ids.size(0), dtype=torch.long).unsqueeze(0)
|
|
|
|
| 8 |
|
| 9 |
class Main:
|
| 10 |
def __init__(self):
|
| 11 |
+
self.MAX_LEN = 500
|
| 12 |
+
self.EPOCHS = 6
|
| 13 |
+
self.NUM_LABELS = 12
|
| 14 |
+
self.DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
#MODEL_PATH = '../input/bert-base-uncased'
|
| 16 |
+
self.STATE_DICT = torch.load('./models/model_e6.tar', map_location=DEVICE)
|
| 17 |
#tokenizer = BertTokenizerFast('../input/bert-base-uncased/vocab.txt', lowercase=True)
|
| 18 |
+
self.tokenizer = BertTokenizerFast.from_pretrained('bert-base-cased')
|
| 19 |
MODEL = BertForTokenClassification.from_pretrained('bert-base-uncased', num_labels=12)
|
| 20 |
|
| 21 |
+
self.tags_vals = ["UNKNOWN", "O", "Name", "Degree","Skills","College Name","Email Address","Designation","Companies worked at","Graduation Year","Years of Experience","Location"]
|
| 22 |
+
self.tag2idx = {t: i for i, t in enumerate(tags_vals)}
|
| 23 |
+
self.idx2tag = {i:t for i, t in enumerate(tags_vals)}
|
| 24 |
|
| 25 |
+
self.data = self.trim_entity_spans(self.convert_dataturks_to_spacy('./data/annotated_resumes.json'))
|
| 26 |
|
| 27 |
+
self.model = MODEL
|
| 28 |
+
self.model.to(DEVICE);
|
| 29 |
|
| 30 |
|
| 31 |
def convert_dataturks_to_spacy(self,dataturks_JSON_FilePath):
|
|
|
|
| 117 |
return final_data
|
| 118 |
|
| 119 |
def predict(self,test_resume):
|
| 120 |
+
self.model.eval()
|
| 121 |
data = self.process_resume(test_resume)
|
| 122 |
input_ids, input_mask = self.data['input_ids'].unsqueeze(0), self.data['attention_mask'].unsqueeze(0)
|
| 123 |
labels = torch.tensor([1] * input_ids.size(0), dtype=torch.long).unsqueeze(0)
|