How to create a custom model with my own entities

791 views Asked by At

I have been trying to find some reference material on how to create custom models with my own entities , like if I want to recognize the name of sports from a text.How do I do it?

2

There are 2 answers

0
Vyomkesh On BEST ANSWER
    try {
        propFile = new File(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/propfile.prop");
        properties = new Properties();
        properties.load(new FileInputStream(propFile));

        String to = properties.getProperty("serializeTo");

        properties.setProperty("serializeTo", "ner-customModel.ser.gz");
        properties.setProperty("trainFile",System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/outputTokenized.tsv");
        CRFClassifier crf = new CRFClassifier(properties);
        crf.train();
        String s2 = "apples are apples";

        System.out.println(crf.classifyToString(s2));

        crf.serializeClassifier(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/ner-customModel.ser.gz");

    } catch (IOException e) {
        e.printStackTrace();
    }

and declare the training file and other properties in the properties file. This worked for me :)

0
Igor On

The tools from stanford usually work pretty good for several NLP tasks, but in my experience, training your own models is a lot easier in opennlp. If that's an option for you (you tagged your question "stanford-nlp", but maybe you're not restricted to using only that), you can find some pretty good documentation here: https://opennlp.apache.org/documentation/1.5.3/manual/opennlp.html#tools.namefind.training.tool