Spaces:
Runtime error
Runtime error
Chidam Gopal commited on
included state and city in NER
Browse files21 unmodified lines222324252627282930313233343536373839404138 unmodified lines80818283848529 unmodified lines11511611711811912012121 unmodified lines# Load the ONNX modelself.ort_session = ort.InferenceSession(model_path)# State abbreviations list for post-processingself.state_abbr = {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY","LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND","OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"}# # Helper function to correct misclassified state abbreviations# def correct_state_abbreviation(self, token, predicted_label):# if token.upper() in self.state_abbr and predicted_label == "I-CITY":# return "I-STATE"# return predicted_labeldef find_location(self, sequence, verbose=False):inputs = self.tokenizer(sequence,return_tensors="np", # ONNX requires inputs in NumPy format38 unmodified linesstate_entities = []org_entities = []city_state_entities = []for i, (token, predicted_id, prob) in enumerate(zip(tokens, predicted_ids[0], predicted_probs[0])):if prob > threshold:if token in ["[CLS]", "[SEP]", "[PAD]"]:29 unmodified linesreturn {'city': city_res,'state': state_res,'organization': org_res,}if __name__ == '__main__':21 unmodified lines22232425262738 unmodified lines666768697071727374757629 unmodified lines10610710810911011121 unmodified lines# Load the ONNX modelself.ort_session = ort.InferenceSession(model_path)def find_location(self, sequence, verbose=False):inputs = self.tokenizer(sequence,return_tensors="np", # ONNX requires inputs in NumPy format38 unmodified linesstate_entities = []org_entities = []city_state_entities = []city_entities = []state_entities = []city_state_entities = []org_entities = []for i, (token, predicted_id, prob) in enumerate(zip(tokens, predicted_ids[0], predicted_probs[0])):if prob > threshold:if token in ["[CLS]", "[SEP]", "[PAD]"]:29 unmodified linesreturn {'city': city_res,'state': state_res,}if __name__ == '__main__':
infer_location.py+5-15