Farm: How to use bert-base-german-cased model to do NER?

Created on 19 Nov 2019  路  2Comments  路  Source: deepset-ai/FARM

Question
https://demos.deepset.ai/ner
is there a source code to this specific problem? how I can achieve this and use the german bert model to recognize entities. very impressed with the performance on my examples.

question NER

All 2 comments

Hi @greg121,

Yes absolutely, I would suggest you to have a look into this example script where you can see the "Building blocks":
https://github.com/deepset-ai/FARM/blob/master/examples/ner.py

Running this script trains a german bert model for NER on CONLL 2003 data.

The one for the demo was trained with slightly different parameters - you can find the exact values here: https://github.com/deepset-ai/FARM/blob/master/experiments/ner/conll2003_de_config.json

You can either adjust the params in the script above or use the "experiment mode" in FARM to replicate this experiment:

from farm.experiment import run_experiment, load_experiments

experiments = load_experiments("experiments/ner/conll2003_de_config.json")
for experiment in experiments:
    run_experiment(experiment)

We haven't optimized for parameters yet, so you might gain some additional performance by experimenting yourself.

Thank you for your quick comment. Since I'm not a NLP Person and also only did a few simple machine learning tasks before I have some problems of understanding.

My understanding was I download your pretrained german model, use it on my data since I was already very happy with the results as stated in my initial post. From what I understand now FARM is used to transfer the model to my specific domain texts. Please correct me if I'm wrong.

I'm currently running https://github.com/deepset-ai/FARM/blob/master/examples/ner.py on a Google's Colab and it takes around 9h to train and to save the model to "harvest my delicious fruits" :-)

Edit:
What I did is I copied the classification model "bert-base-german-cased-GNAD" and the NER model "bert-base-german-cased-CONLL2003" from the docker container to just do

from farm.infer import Inferencer
model = Inferencer.load('bert-base-german-cased-GNAD')
basic_texts = [{"text": "Eintracht Frankfurt hat 1:0 gegen Manchester United am Mittwochabend gewonnen"}, {"text": "Die Aktie von Wirecard geht heute wieder durch die Decke auf XETRA in Frankfurt am Main"}]
result = model.inference_from_dicts(dicts=basic_texts)
print(result)

to find out that the first one is classified as "Sport" and the second one as "Wirtschaft"
Thanks for your work!

Was this page helpful?
0 / 5 - 0 ratings