Spaces:
Runtime error
Runtime error
File size: 9,049 Bytes
cfbfc47 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
from Models import Models
class ResumeSegmenter:
def __init__(self, zero_shot_classifier):
self.zero_shot_classifier = zero_shot_classifier
objective = (
'career goal',
'objective',
'career objective',
'employment objective',
'professional objective',
'summary',
'summary of qualifications',
'digital'
)
work_and_employment = (
'employment history',
'employment data',
'career summary',
'work history',
'work experience',
'experience',
'professional experience',
'professional background',
'professional employment',
'additional experience',
'career related experience',
"professional employment history",
'related experience',
'programming experience',
'freelance',
'freelance experience',
'army experience',
'military experience',
'military background',
)
education_and_training = (
'academic background',
'academic experience',
'programs',
'courses',
'related courses',
'education',
'educational background',
'educational qualifications',
'educational training',
'education and training',
'training',
'academic training',
'professional training',
'course project experience',
'related course projects',
'internship experience',
'internships',
'apprenticeships',
'college activities',
'certifications',
'special training',
)
skills_header = (
'credentials',
'qualifications',
'areas of experience',
'areas of expertise',
'areas of knowledge',
'skills',
"other skills",
"other abilities",
'career related skills',
'professional skills',
'specialized skills',
'technical skills',
'computer skills',
'personal skills',
'computer knowledge',
'technologies',
'technical experience',
'proficiencies',
'languages',
'language competencies and skills',
'programming languages',
'competencies'
)
misc = (
'activities and honors',
'activities',
'affiliations',
'professional affiliations',
'associations',
'professional associations',
'memberships',
'professional memberships',
'athletic involvement',
'community involvement',
'refere',
'civic activities',
'extra-Curricular activities',
'professional activities',
'volunteer work',
'volunteer experience',
'additional information',
'interests'
)
accomplishments = (
'achievement',
'awards and achievements',
'licenses',
'presentations',
'conference presentations',
'conventions',
'dissertations',
'exhibits',
'papers',
'publications',
'professional publications',
'research experience',
'research grants',
'project',
'research projects',
'personal projects',
'current research interests',
'thesis',
'theses',
)
def find_segment_indices(self, string_to_search, resume_segments, resume_indices):
for i, line in enumerate(string_to_search):
if line[0].islower():
continue
header = line.lower()
if [o for o in self.objective if header.startswith(o)]:
try:
resume_segments['objective'][header]
except:
resume_indices.append(i)
header = [o for o in self.objective if header.startswith(o)][0]
resume_segments['objective'][header] = i
elif [w for w in self.work_and_employment if header.startswith(w)]:
try:
resume_segments['work_and_employment'][header]
except:
resume_indices.append(i)
header = [w for w in self.work_and_employment if header.startswith(w)][0]
resume_segments['work_and_employment'][header] = i
elif [e for e in self.education_and_training if header.startswith(e)]:
try:
resume_segments['education_and_training'][header]
except:
resume_indices.append(i)
header = [e for e in self.education_and_training if header.startswith(e)][0]
resume_segments['education_and_training'][header] = i
elif [s for s in self.skills_header if header.startswith(s)]:
try:
resume_segments['skills'][header]
except:
resume_indices.append(i)
header = [s for s in self.skills_header if header.startswith(s)][0]
resume_segments['skills'][header] = i
elif [m for m in self.misc if header.startswith(m)]:
try:
resume_segments['misc'][header]
except:
resume_indices.append(i)
header = [m for m in self.misc if header.startswith(m)][0]
resume_segments['misc'][header] = i
elif [a for a in self.accomplishments if header.startswith(a)]:
try:
resume_segments['accomplishments'][header]
except:
resume_indices.append(i)
header = [a for a in self.accomplishments if header.startswith(a)][0]
resume_segments['accomplishments'][header] = i
def slice_segments(self, string_to_search, resume_segments, resume_indices):
resume_segments['contact_info'] = string_to_search[:resume_indices[0]]
sec_idxs = {}
for section, value in resume_segments.items():
if section == 'contact_info':
continue
for sub_section, start_idx in value.items():
end_idx = len(string_to_search)
if (resume_indices.index(start_idx) + 1) != len(resume_indices):
end_idx = resume_indices[resume_indices.index(start_idx) + 1]
sec_idxs[section] = (start_idx, end_idx)
# print(start_idx, end_idx)
resume_segments[section][sub_section] = string_to_search[start_idx:end_idx]
return sec_idxs
def find_true_segment(self, dict_of_segments, segment_name):
segment_classes = {
'objective': ["objective", "other"],
'work_and_employment':["employment history", "other"],
'education_and_training': ["education", "other"],
'skills': ["skills", "other"],
'accomplishments': ["accomplishments", "other"],
'misc': ["misc", "other"],
'contact_info': ["contact information", "other"]
}
classes = segment_classes[segment_name]
scores = []
segs = dict_of_segments.keys()
for seg in segs:
sequence = dict_of_segments[seg]
score = self.zero_shot_classifier(' '.join(sequence), classes)["scores"][0]
scores.append(score)
res = sorted(zip(dict_of_segments.keys(), scores), key=lambda x: x[1], reverse=True)
if len(res):
return res[0][0]
else: return 0
def segment(self, string_to_search):
print("Segmenting the Resume..")
resume_segments = {
'objective': {},
'work_and_employment': {},
'education_and_training': {},
'skills': {},
'accomplishments': {},
'misc': {}
}
resume_indices = []
self.find_segment_indices(string_to_search, resume_segments, resume_indices)
if len(resume_indices) != 0:
sec_idx = self.slice_segments(string_to_search, resume_segments, resume_indices)
else:
resume_segments['contact_info'] = []
for segment in resume_segments:
if segment == "contact_info": continue
if not len(resume_segments[segment]) > 1:
if len(resume_segments[segment]) == 1:
only_key = list(resume_segments[segment].keys())[0]
resume_segments[segment] = resume_segments[segment][only_key][1:]
continue
if segment != "work_and_employment": continue
true_seg = self.find_true_segment(resume_segments[segment], segment)
if not true_seg:
resume_segments[segment] = []
else:
resume_segments[segment] = resume_segments[segment][true_seg][1:]
return resume_segments
|