title: How to use spaCy to create a new entity and learn only from keyword list
body: <p>I am trying to use <a href="https://spacy.io/" rel="noreferrer">spaCy</a> to create a new entity categorization 'Species' with a list of species names, example can he found <a href="https://a-z-animals.com/animals/scientific/" rel="noreferrer">here</a>.</p>
  <p>I found a tutorial for training new entity type from <a href="https://spacy.io/usage/training#example-new-entity-type" rel="noreferrer">this spaCy tutorial</a> (Github code <a href="https://github.com/explosion/spaCy/blob/master/examples/training/train_new_entity_type.py" rel="noreferrer">here</a>). However, the problem is, I don't want to manually create a sentence for each species name as it would be very time consuming.</p>
  <p>I created below training data, which looks like this:</p>
  <pre><code>TRAIN_DATA = [('Bombina',{'entities':[(0,6,'SPECIES')]}),
   ('Dermaptera',{'entities':[(0,9,'SPECIES')]}),
    .... 
  ]
  </code></pre>
  <p>The way I created the training set is: instead of providing a full sentence and the location of the matched entity, I only provide the name of each species, and the start and end index are programmatically generated:</p>
  <blockquote>
  <p>[( 0, 6, 'SPECIES' )]</p>
  <p>[( 0, 9, 'SPECIES' )]</p>
  </blockquote>
  <p>Below training code is what I used to train the model. (Code copied from above hyperlink)</p>
  <pre><code>nlp = spacy.blank('en')  # create blank Language class
  
   # Add entity recognizer to model if it's not in the pipeline 
   # nlp.create_pipe works for built-ins that are registered with spaCy 
   if 'ner' not in nlp.pipe_names: 
       ner = nlp.create_pipe('ner') 
       nlp.add_pipe(ner) 
   # otherwise, get it, so we can add labels to it 
   else: 
       ner = nlp.get_pipe('ner') 
  
   ner.add_label(LABEL)   # add new entity label to entity recognizer
  
  
    if model is None: 
        optimizer = nlp.begin_training() 
    else: 
        # Note that 'begin_training' initializes the models, so it'll zero out 
        # existing entity types. 
        optimizer = nlp.entity.create_optimizer() 
  
       # get names of other pipes to disable them during training 
       other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner'] 
       with nlp.disable_pipes(*other_pipes):  # only train NER 
           for itn in range(n_iter): 
               random.shuffle(TRAIN_DATA) 
               losses = {} 
               for text, annotations in TRAIN_DATA: 
                   nlp.update([text], [annotations], sgd=optimizer, drop=0.35,  losses=losses) 
               print(losses) 
  </code></pre>
  <p>I'm new to NLP and spaCy please let me know if I did it correctly or not. And why my attempt failed the training (when I ran it, it throws an error).</p>
  <hr />
  <p>[UPDATE]</p>
  <p>The reason I want to feed keyword only to the training model is that, ideally, I would hope the model to learn those key words first, and once it identifies a context which contains the keyword, it will learn the associated context, and therefore, enhance the current model.</p>
  <p>At the first glance, it is more like regex expression. But with more and more data feeding in, the model will continuous learn, and finally being able to identify new species names that previously not exists in the original training set.</p>
  <hr />
  <p>Thanks,
  Katie</p>