I'm working on an NLP/NER script using transformers/BERT and I'm having an issue extracting the name of a company from a set of texts.
In all the texts the script will be used on, the company's name will be presented like this:
"COMPANY NAME: the company's name is XXX" or "NAME: the company's name is XXX"
this is my code:
def get_company_info(text, tokenizer_1, model_1, tokenizer_2, model_2):
company_info = {"name": None}
try:
start_company_index = re.search('name', text, re.I).span()[0]
info = NLP_2(
text[start_company_index:start_company_index+100], tokenizer_2, model_2)
for data in info:
if data['entity_group'] == 'ORG':
company_info['name'] = data['word']
break
except:
pass
However, the BERT script returns the word "company" since it finds it in the text and assumes correctly that it is the subject I'm looking for but I want to extract the name of the company instead.
Is there a simple way to avoid this or do I have to fine-tune the model?
I'm using regex to delimit the field of the search but I cannot simply use re.search("company") to start the search after the word company, because sometimes there will be 2 consecutive mentions of the word.