CoolFace
Modelpublic

boeing/aviation-ner

sourceHugging Facemitupdated 8mo agoView on Hugging Face
1likes13downloads
README.md193 linesDownload Raw Back to root
1---2license: mit3pipeline_tag: token-classification4tags:5- GLiNER6- entity recognition7- NER8- aviation safety9- aviation-ner10language:11- en12base_model:13- numind/NuNER_Zero14datasets:15- boeing/aviation-ner-BIO16---17 18Aviation-ner is a fine-tuned transformer based model to identify and extract aviation hazards associated with product factors from Service Difficulty Reports.  SDRs are submitted via the [service difficulty reporting system](https://sdrs.faa.gov/) by operators or certified repair stations as a means to document and share information with the aviation community about failures, malfunctions, or defects of aeronautical products. 19The free-form text description field often contains valuable safety related information, however it lacks predictable grammatical structure and is not in any way standardized. 20Additionally, it can contain typographical errors, part numbers, abbreviations, and references to specific sections of maintenance manuals or operating procedures, making it difficult to reliably extract this information with regular expressions or language models designed to take in clean, full sentences as input. 21 22The work is a collaboration between FAA and Boeing data scientist teams. The NER model will enhance searchability and facilitate clustering and trend analysis of safety events.23 24## Entity Definition25 261. Flight Phase (FLT) 27references to the IATA taxonomy that focuses on safety management. IATA includes flight planning and ground servicing phases since these phases can directly impact a flight.28 292. Product Location (LOC) 30A location within the airplane and directional information which disambiguates one Product Factor from another or helps to identify each aircraft component specifically31 323. Crew Action (ACT) 33A task which is/was carried out to attempt to resolve/correct a Product Condition excluding maintenance action.34 35Examples: follow QRH, complied with procedure, run or accomplished procedure, disable/enable systems, turn on/off systems, change state of the airplane or its systems, change flight phase, change flight altitude, etc. Communication related actions such as request, call, notify, and notice are excluded.36 374. Product (PROD) 38Airplane and components/equipment/systems installed on the delivered product. Typically, this means something that you can touch, hold, remove, replace, control or interact with. Examples: tire pressure, software, navigation database, and cabin pressure.39 405. Product Condition (PCON) 41A specific quality, behavior, or situation with regards to a Product Factor or Product Location.42 43Examples: Smoke, Fire, Fumes, Odor, Loss of Aircraft Control, FOD, Fuel Issue, Gear Up Landing, Ground Strike, Jet Blast, Loss of VLOS44 456. Bird strike or Animal strike (BIRD) 46Bird strike or a near miss between an aircraft and wildlife, during high-speed take-off or landing. For animal strike, an impact/collision between an aircraft and wildlife (Deer, elk, coyote, fox), during high-speed take-off or landing 47 487. Emergency or Abnormal Situation (SIT) 49An emergency situation is one in which the safety of the aircraft or of persons on board or on the ground is endangered for any reason. An abnormal situation is one in which it is no longer possible to continue the flight using normal procedures but the safety of the aircraft or persons on board or on the ground is not in danger.50 51Examples: Evacuated, Flight Cancelled/Delayed, Diverted, Executed Go Around / Missed Approach, Inflight Shutdown, Exited Penetrated Airspace, FLC Overrode Automation, FLC Complied with Automation / Advisory, Landed as Precaution, Landed in Emergency Condition, Overcame Equipment Problem, Regained Aircraft Control, Rejected Takeoff, Requested ATC Assistance/Clarification, Returned to Clearance, Returned to Departure Airport, Returned to Gate, Returned to Home, Took Evasive Action52 53 54## Installation & Usage55 56```57!pip install gliner==0.1.1258!pip install git+https://github.com/Boeing/aviation_ner_sdr@main59```60 61**NuZero requires labels to be lower-cased**62 63```python64import pandas as pd65import re66import os67import time68from gliner import GLiNER69from aviation_ner_sdr.ner_tokenization import NerTokenization70 71class NERTagging:72    labels = ["b-prod", "i-prod", "b-loc", "i-loc", "b-pcon", "i-pcon", "b-sit", "i-sit", "b-act", "i-act", "b-bird", "i-bird", "b-flt", "i-flt"]73 74    def __init__(self, model_path):75 76        if (os.path.exists(model_path)): self.model = GLiNER.from_pretrained(model_path, local_files_only=True)77        else: self.model = GLiNER.from_pretrained(model_path)78 79        self.tokenizer = NerTokenization()80 81    def tokenize_with_offsets(self, text):82 83        offsets_d = {}84 85        for match in re.finditer(r'\S+', text):  # \S+ matches any sequence of non-whitespace characters86            start, end = match.start(), match.end()87            offsets_d[(start, end)] = [match.group(), "O"]88 89        return offsets_d90 91    def strip_bi(self, tag):92 93        if tag == "O":94            base_tag = tag95        else:96            base_tag = tag.split("-")[1]97 98        return base_tag99 100    def get_list_of_tokens_with_tags(self, entities, d, strip_bi):101 102        for this_ent in entities:103            start, end, label = this_ent["start"], this_ent["end"], this_ent["label"]104            k = (start, end)105            if k in d:106                d[k][1] = label107            # else:108            #     print("misaligned") # matches currently set to be exact109 110        sorted_text = sorted(d.items(), key = lambda tup : tup[0][0])111 112        if strip_bi:113            tagged_tokens = [(tup[1][0], self.strip_bi(tup[1][1])) for tup in sorted_text]114        else:115            tagged_tokens = [(tup[1][0], (tup[1][1])) for tup in sorted_text]116 117        return tagged_tokens118 119    def ner_label_main(self, text, strip_bi):120 121        text = self.tokenizer.tokenize_string(text)122        entities = self.model.predict_entities(text, NERTagging.labels)123        text_d = self.tokenize_with_offsets(text)124        tups = self.get_list_of_tokens_with_tags(entities, text_d, strip_bi)125        return tups126 127    def parse_out_labels_to_dict(self, tups):128 129        d = {}130 131        temp_tag, temp_entity = None, []132 133        for token, tag in tups:134 135            if tag != "O":  # first check if token is part of entity136 137                if tag.startswith("i"):  # if not new entity, keep appending to current138 139                    if temp_tag is None: # handle mislabels where parts start with I140                        temp_tag, temp_entity = labeler.strip_bi(tag), [token]  # reset141                    else:142                        temp_entity.append(token)143 144                else:  # tag starts with B - new entity145 146                    if temp_tag:  # add old entity to d147                        if temp_tag not in d:148                            d[temp_tag] = []149                        d[temp_tag].append(" ".join(temp_entity))150 151                    temp_tag, temp_entity = labeler.strip_bi(tag), [token]  # reset152 153            else:  # tag is "o"154 155                if temp_tag:  # add old entity to d156                    if temp_tag not in d:157                        d[temp_tag] = []158                    d[temp_tag].append(" ".join(temp_entity))159 160                    temp_tag, temp_entity = None, []  # reset161 162        if temp_entity:163            if temp_tag not in d:164                d[temp_tag] = []165            d[temp_tag].append(" ".join(temp_entity))166 167        return d168 169if __name__ == "__main__":170 171    model_path = "boeing/aviation-ner"172    labeler = NERTagging(model_path)173 174    # list of strings175    all_text = ["A Cargojet Boeing 767-300 on behalf of Amazon Prime Air, registration C-GAZI performing flight W8-2387 (dep Nov 18th) from Hamilton,ON to Vancouver,BC (Canada), had declared PAN PAN prior to landing reporting flaps problems, they would land at a higher speed than normal, prompting emergency services to assume their standby locations. The aircraft landed on Vancouver's runway 08L at 01:28L (09:28Z) at a higher than normal speed (about 175 knots over ground), overran the runway by about 572 meters/1880 feet and suffered the collapse of the nose gear, the crew declared Mayday after coming to a stop. Both runways were closed following the runway excursion, runway 08R had been closed for works, runway 08L needed to be closed due to the occurrence, runway 08R was opened following the occurrence."]176 177    # entity tags178    tags = ["prod", "loc", "pcon", "sit", "act", "bird", "flt"]179    for i, this_text in enumerate(all_text):180 181        # tuples of tokens and tags182        token_tag_tups = labeler.ner_label_main(this_text, strip_bi=False)183        print(token_tag_tups)184 185        # dictionary of tags: mentions from this_text186        entity_dict = labeler.parse_out_labels_to_dict(token_tag_tups)187        entity_dict = {key: ", ".join(value) for key, value in entity_dict.items()}188        print(entity_dict)189 190```191## Output192 193{'sit': 'declared, PAN PAN, declared Mayday', 'flt': 'landing, land, landed', 'prod': 'flaps, nose gear', 'pcon': 'problems, higher speed than normal, higher than normal speed, overran, collapse'}