2

我正在使用spacy 2.1.8spacy-pytorch-transformers 0.4.0训练一个文本分类器。我的代码受到他们示例的强烈启发,但模型没有学习任何东西,这似乎是由于损失一直为 0 造成的。我的代码的最小(非)工作示例如下:

nlp = spacy.load("en_pytt_xlnetbasecased_lg")
textcategorizer = nlp.create_pipe("pytt_textcat", config={"exclusive_classes": True, "architecture": "softmax_last_hidden"})

for label in labels:
    textcategorizer.add_label(label)
nlp.add_pipe(textcategorizer, last=True)

optimizer = nlp.resume_training()

for epoch in range(num_of_epochs):
    np.random.shuffle(train)
    losses = Counter()

    for step, batch in enumerate(minibatch(train, size=batch_size)):
        optimizer.pytt_lr = 0.005
        texts, cats = zip(*batch)
        _, cats = preprocessed_labels_to_categories_for_training_and_eval(cats)

        nlp.update(texts, cats, sgd=optimizer, losses=losses, drop=0.1)

我已经两次和三次检查了相关变量,例如catsand texts,是否包含有效和正确的值。

有什么我想念的吗?

4

0 回答 0