Попытка создать собственную модель NER, но все они попадают в одну категорию - PullRequest
0 голосов
/ 07 августа 2020

Я пробовал этот код так же, как показано на

https://medium.com/swlh/stanford-corenlp-training-your-own-custom-ner-tagger-8119cc7dfc06

public class Testmodel {
    public static void trainAndWrite(String modelOutPath, String prop, String trainingFilepath) {
        Properties props = StringUtils.propFileToProperties(prop);
        props.setProperty("serializeTo", modelOutPath);
        //if input use that, else use from properties file.
        if (trainingFilepath != null) {
            props.setProperty("trainFile", trainingFilepath);
        }
        SeqClassifierFlags flags = new SeqClassifierFlags(props);
        CRFClassifier<CoreLabel> crf = new CRFClassifier<>(flags);
        crf.train();
        System.out.println(crf.labels());
        crf.serializeClassifier(modelOutPath);
    }
    public static void doTagging(String modelPath, String input) {
        CRFClassifier model1 = CRFClassifier.getClassifierNoExceptions(modelPath);
        input = input.trim();
        System.out.println(model1.labels());


        System.out.println(input + "=>"+model1.classify(input));
        
        System.out.println(input + "=>"  +  model1.classifyToString(input.trim()));
        //System.out.println(input + "=>"  +  model.classifyToString(input));
    }
    public static void main(String[] args){
        /*Testmodel.trainAndWrite("/home/akhilav/ner-model.ser.gz",
                "/home/akhilav/Downloads/props.prop","/home/akhilav/Downloads/traningfile.tsv");*/
        Testmodel.doTagging("/home/akhilav/ner-model.ser.gz",
                "samsung mobile phones");
    }
}

это мой код, и я использовал файл свойств для создания пользовательской модели

# location of the training file
trainFile = /home/akhilav/Downloads/traningfile.tsv
# location where you would like to save (serialize) your
# classifier; adding .gz at the end automatically gzips the file,
# making it smaller, and faster to load
serializeTo = /home/akhilav/ner-model.ser.gz
# structure of your training file; this tells the classifier that
# the word is in column 0 and the correct answer is in column 1
map = word=0,answer=1
# This specifies the order of the CRF: order 1 means that features
# apply at most to a class pair of previous class and current class
# or current class and next class.
maxLeft=1
# these are the features we'd like to train with
# some are discussed below, the rest can be
# understood by looking at NERFeatureFactory
useClassFeature=true
useWord=true
# word character ngrams will be included up to length 6 as prefixes
# and suffixes only
useNGrams=true
noMidNGrams=true
maxNGramLeng=6
usePrev=true
useNext=true
useDisjunctive=true
useSequences=true
usePrevSequences=true
# the last 4 properties deal with word shape features
useTypeSeqs=true
useTypeSeqs2=true
useTypeySequences=true
#wordShape=chris2useLC
wordShape=none
#useBoundarySequences=true
#useNeighborNGrams=true
#useTaggySequences=true
#printFeatures=true
#saveFeatureIndexToDisk = true
#useObservedSequencesOnly = true
#useWordPairs = true

И я получил неправильный вывод, все идет под этим именем модели, что не так в этом коде. Пожалуйста, помогите мне решить эту проблему !!

мобильные телефоны samsung => samsung / имя модели мобильного телефона / имя модели телефона / имя модели

Ожидаемый результат

мобильные телефоны samsung => samsung / марка мобильных телефонов / категория телефонов / категория

обучающий файл

hp  Brand
spectre ModelName
x360    ModelName

home    Category
theater Category
system  0

horizon ModelName
zero    ModelName
dawn    ModelName
ps4 0

hoverboard  Category
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...