赛事背景
在人工智能领域的学习中,研读有关文献是非常重要的学习途径,而如何在汗牛充栋的论文库中,高效快速的检索到相关重要文献,就成为知识学习首先要解决的难点。
比赛报名链接:http://challenge.xfyun.cn/topic/info?type=abstract&ch=ds22-dw-zmt05
赛事任务
机器通过对论文摘要等信息的理解,划分论文类别。
评估指标
采用准确率Accuracy进行评价:
解题思路
题是一个典型的文本分类任务,因此可以选择常见的文本分类模型。常见的模型包括TFIDF+ 逻辑回归 和 深度学习模型。在实践中我们将先尝试TFIDF思路,然后尝试BERT思路。
导入库
# 导入库
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import cross_val_score
数据读取
#----------------数据探索----------------
#数据预处理
#加载训练集
train_df = pd.read_csv('./基于论文摘要的文本分类与查询性问答公开数据/train.csv', sep=',')
#加载测试集
test_df = pd.read_csv('./基于论文摘要的文本分类与查询性问答公开数据/test.csv', sep=',')
#EDA数据探索性分析
train_df.head()
test_df.head()
生成文本
#----------------特征工程----------------
#将Topic(Label)编码
train_df['Topic(Label)'], lbl = pd.factorize(train_df['Topic(Label)'])
#将论文的标题与摘要组合为 text 特征
train_df['Title'] = train_df['Title'].apply(lambda x: x.strip())
train_df['Abstract'] = train_df['Abstract'].fillna('').apply(lambda x: x.strip())
train_df['text'] = train_df['Title'] + ' ' + train_df['Abstract']
train_df['text'] = train_df['text'].str.lower()
test_df['Title'] = test_df['Title'].apply(lambda x: x.strip())
test_df['Abstract'] = test_df['Abstract'].fillna('').apply(lambda x: x.strip())
test_df['text'] = test_df['Title'] + ' ' + test_df['Abstract']
test_df['text'] = test_df['text'].str.lower()
训练模型
#使用tfidf算法做文本特征提取
tfidf = TfidfVectorizer(max_features=2500)
#----------------模型训练----------------
train_tfidf = tfidf.fit_transform(train_df['text'])
clf = SGDClassifier()
cross_val_score(clf, train_tfidf, train_df['Topic(Label)'], cv=5)
test_tfidf = tfidf.transform(test_df['text'])
clf = SGDClassifier()
clf.fit(train_tfidf, train_df['Topic(Label)'])
test_df['Topic(Label)'] = clf.predict(test_tfidf)
#----------------结果输出----------------
test_df['Topic(Label)'] = test_df['Topic(Label)'].apply(lambda x: lbl[x])
test_df[['Topic(Label)']].to_csv('submit.csv', index=None)
# 竞赛交流群 邀请函 #

每天Kaggle算法竞赛、干货资讯汇总
与 22000+来自竞赛爱好者一起交流~

文章转载自Coggle数据科学,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




