sentenceClassifer.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ai-chatbot-framework 作者: alfredfrancis 项目源码 文件源码
def train(X, y, outpath=None, verbose=True):
    def build(X, y=None):
        """
        Inner build function that builds a single model.
        """
        model = Pipeline([
            ('preprocessor', NLTKPreprocessor()),
            ('vectorizer', TfidfVectorizer(
                tokenizer=identity, preprocessor=None, lowercase=False)),
            ('clf', OneVsRestClassifier(LinearSVC()))])

        model.fit(X, y)
        return model

    # Label encode the targets
    labels = preprocessing.MultiLabelBinarizer()
    y = labels.fit_transform(y)

    model = build(X, y)
    model.labels_ = labels

    if outpath:
        with open(outpath, 'wb') as f:
            pickle.dump(model, f)

            if verbose:
                print("Model written out to {}".format(outpath))

    return model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号