美文网首页
基于mynlp实现文本分类模型训练

基于mynlp实现文本分类模型训练

作者: 菠萝炒鸡蛋 | 来源:发表于2020-08-24 20:13 被阅读0次

代码:

/**
 * mynlp采用fasttext算法提供文本分类功能,你可以训练、评估自己的分类模型。
 *
 * 训练数据是个纯文本文件,每一行一条数据,词之间使用空格分开,每一行必须包含至少一个label标签。默认 情况下,是一个带`label`前缀的字符串。
 */
public class Classify {
    public static void main(String[] args) {

        File trainFile = new File("src\\test\\resources\\train.txt");
        File testFile = new File("src\\test\\resources\\test.txt");

        InputArgs trainArgs = new InputArgs();
        trainArgs.setLoss(LossName.hs);
        trainArgs.setEpoch(10);
        trainArgs.setDim(100);
        trainArgs.setLr(0.2);

        FastText fastText = FastText.trainSupervised(trainFile,trainArgs);
        //FastText qFast = fastText.quantize();

        fastText.test(testFile,1,0.0f,true);
        System.out.println("--------------------");
        //qFast.test(testFile,1,0.0f,true);
    }
}

相关文章

网友评论

      本文标题:基于mynlp实现文本分类模型训练

      本文链接:https://www.haomeiwen.com/subject/gmcojktx.html