Code Monkey home page Code Monkey logo

Comments (4)

nreimers avatar nreimers commented on August 22, 2024

Hi @Jong-Won
the CoNLL 2003 NER files are in an IOB format, i.e. only the second of directly consecutive named entities starts with a B-tag, all other tags start with an I-tag.

There are two ways to deal with that.
Option 1: Specify IOB Tagging
Line 36-37 from Train_NER.py has to look like this:
dataColumns = {0:'tokens', 3:'NER_IOB'}
labelKey = 'NER_IOB'

Option 2: Convert data files to BIO

As shown in our long publication of arxiv, is the IOB tagging suboptimal, as it has a rather strange structure. I would recommend to convert the files to BIO so that every named entity starts with a B-tag.

This can be with this script:

"""
Converts the IOB encoding from CoNLL 2003 to BIO encoding
"""


filenames = ['train.txt', 'dev.txt', 'test.txt']

for filename in filenames:
    fOut = open(filename, 'w')
    fIn = open(filename+'.iob', 'r')
    
    for line in fIn:
        if line.startswith('-DOCSTART-'):
            lastChunk = 'O'
            lastNER = 'O'
            continue
        
        if len(line.strip()) == 0:
            lastChunk = 'O'
            lastNER = 'O'
            fOut.write("\n")
            continue
            
        
        splits = line.strip().split()
        
        chunk = splits[2]
        ner = splits[3]
        
        if chunk[0] == 'I':
            if chunk[1:] != lastChunk[1:]:
                chunk = 'B'+chunk[1:]
                
        if ner[0] == 'I':
            if ner[1:] != lastNER[1:]:
                ner = 'B'+ner[1:]
                
        splits[2] = chunk 
        splits[3] = ner
        
        fOut.write("\t".join(splits))
        fOut.write("\n")
        
        lastChunk = chunk
        lastNER = ner
        
        
print "--DONE--"

Then, Line 36-37 from Train_NER.py has to look like this:
dataColumns = {0:'tokens', 3:'NER_BIO'}
labelKey = 'NER_BIO'

from emnlp2017-bilstm-cnn-crf.

Jong-Won avatar Jong-Won commented on August 22, 2024

Hi, @nreimers
Really appreciate for your reply. I haved get the correct performance on CONLL 2003 NER data following your instruction .

Another question is that:
Experiments of different seeds is mentioned in the emnlp paper , where to set the seed value in the code ?

Thanks

from emnlp2017-bilstm-cnn-crf.

nreimers avatar nreimers commented on August 22, 2024

Hi,
it is not directly implemented in the code, but you can control it via NumPy:

import numpy as np
np.random.seed(1337)
import keras

Make sure the np.random.seed() is called before keras is imported.

from emnlp2017-bilstm-cnn-crf.

Jong-Won avatar Jong-Won commented on August 22, 2024

Thanks for your reply @nreimers

from emnlp2017-bilstm-cnn-crf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.