import sys
import spacy
import numpy as np
from spacy import displacy
from model.model_supervised import ModelSupervised
def loadEmbeddings(path, encoding = "utf-8", ofset=None):
print("Reading embeddings...")
embeddings = []
vocabulary = {}
own_embeddings_append = embeddings.append
if ofset is not None:
for i in range(ofset):
own_embeddings_append([])
with open(path, "r", encoding=encoding) as emb_file:
own_strip = str.strip
own_str_partition = str.partition
emb_file.readline()
for line in emb_file:
fields = own_str_partition(line, " ")
word = own_strip(fields[0])
emb_values = np.array([float(x) for x in own_strip(fields[-1]).split(" ")])
vocabulary[word] = len(embeddings)
own_embeddings_append(emb_values)
return embeddings, vocabulary
embeddings = loadEmbeddings("../../data/embeddings/crawl-300d-2M.vec")
Reading embeddings...
We load our model PulgarNERC.
pulgar_nlp = spacy.load("../../data/model_1sentence_newjson/")
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spacy/util.py:275: UserWarning: [W031] Model 'en_ner_model_ugr' (2.2.5) requires spaCy v2.2 and is incompatible with the current spaCy version (2.3.2). This may lead to unexpected results or runtime errors. To resolve this, download a newer compatible model or retrain your custom model with the current spaCy version. For more details and available updates, run: python -m spacy validate warnings.warn(warn_msg)
We demonstrate the behaviour of our model in two selected testing sentences:
Example texts:
text_1 = "The FP Commander will identify the physical protection requirements for inclusion in the Infrastructure Development Plan (IDP), with specialist advice and planning provided by Military Engineers."
processed_text_1 = pulgar_nlp(text_1)
print(processed_text_1.ents)
displacy.render(processed_text_1, style="ent", jupyter = "True")
(Infrastructure Development Plan,)
text_2 = "Since a COMAO needs thorough planning and considerable planning time, the Air Request (AIRREQ) is not used to request such a bulk mission."
processed_text_2 = pulgar_nlp(text_2)
print(processed_text_2.ents)
displacy.render(processed_text_2, style="ent", jupyter = "True")
(Air Request,)
text_3 = "Once approved by the NAC, the list becomes the Joint Prioritized Defended Assets List (JPDAL), which is sent back to the COM JFC and onward to the JDAWG, which, in turn, sends it to the AMDC AMD Planners to develop the Joint Air Defence Plan for the Operation."
processed_text_3 = pulgar_nlp(text_3)
print(processed_text_3.ents)
displacy.render(processed_text_3, style="ent", jupyter = "True")
(Prioritized Defended Assets List,)