Skip to content
Jari Björne edited this page May 26, 2014 · 4 revisions

Writing a Detector

The upper level of the TEES system consists of the Detector-classes, which in turn run the ExampleBuilders and other subsystems. The SingleStageDetector handles one-step tasks such as trigger detection or edge detection, and the EventDetector handles the three-step (triggers, edges, unmerging) task of detecting BioNLP Shared Task -style events.

To extend TEES, the most common case would be to define a new Detector. The Detector class itself mostly delegates calls to subcomponents, so defining a new Detector should in most cases consist of simply defining which subcomponents are to be used.

In the following example, TEES is extended with new features which are to be used for detecting some new type of binary relation. We start from the highest level, defining a new Detector:

from ExampleBuilders.MyEdgeExampleBuilder import MyEdgeExampleBuilder

class MyDetector(EdgeDetector):
    def __init__(self):
        EdgeDetector.__init__(self)
        self.exampleBuilder = MyEdgeExampleBuilder

Here a new class is inherited from EdgeDetector, which is one of the SingleStageDetector classes. The default example builder is replaced with MyEdgeExampleBuilder, a new class for constructing custom edge examples.

Writing an ExampleBuilder

In this example we assume that the MyEdgeExampleBuilder class builds edge examples similar to the original EdgeExampleBuilder, so the rest of the MyDetector components can stay as is. If the new examples are going to differ radically from existing ones, you may need to write a new ExampleWriter too. To see how example generation works and how to e.g. add new features, please look at the buildExample method of the relevant ExampleBuilder class.

The FeatureBuilder classes (located in the ExampleBuilders.FeatureBuilders module) contain reusable code for feature generation, and can make writing a new ExampleBuilder easier, but you don't have to use them.

Using the extended TEES

To use the new detector, the train.py program can be told to use it with the "--detector" command line parameter. In this example, the "--detector MyDetector" setting would be used, assuming the new MyDetector class is located in the Detectors module.

Extending the Preprocessor

To use a new external tool with TEES, a new step can be added to the Preprocessor. In Detectors.Preprocessor the getDefaultSteps method shows how to add preprocessing steps. These steps are simply functions, which receive an interaction XML and return it after modification.

In the Tools module are several examples of external programs, wrapped in Python to be used as part of the TEES preprocessing pipeline.

Clone this wiki locally