NLP | 论文摘要文本分类

基于论文摘要的文本分类与关键词抽取挑战赛
​​​​​​2023 iFLYTEK A.I.开发者大赛-讯飞开放平台

环境需求:Anaconda-JupyterNotebook,或者百度AIStudio

赛题解析:

【文本二分类任务】根据论文摘要等信息理解,将论文划分为0-1两类别之一。

【文本关键词识别任务】从给定的论文中识别和提取出与论文内容相关的关键词。

数据样例:title、author、Abstract、Keywords、[label] 0-1

一键运行的时候先把csv删了(是运行结果)

安装nltk 【更换镜像源避免安装出错】

python 复制代码
!pip install nltk -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
python 复制代码
# 导入pandas用于读取表格数据
import pandas as pd

# 导入BOW(词袋模型)
from sklearn.feature_extraction.text import CountVectorizer
#可以替换为TfidfVectorizer(TF-IDF(词频-逆文档频率))
#注意上下文要同时修改,亲测后者效果更佳

# 导入LogisticRegression回归模型
from sklearn.linear_model import LogisticRegression

# 过滤警告消息
from warnings import simplefilter
from sklearn.exceptions import ConvergenceWarning
simplefilter("ignore", category=ConvergenceWarning)


# 读取数据集
train = pd.read_csv('/home/aistudio/data/data231041/train.csv')
train['title'] = train['title'].fillna('')
train['abstract'] = train['abstract'].fillna('')

test = pd.read_csv('/home/aistudio/data/data231041/testB.csv')
test['title'] = test['title'].fillna('')
test['abstract'] = test['abstract'].fillna('')


# 提取文本特征,生成训练集与测试集
train['text'] = train['title'].fillna('') + ' ' +  train['author'].fillna('') + ' ' + train['abstract'].fillna('')+ ' ' + train['Keywords'].fillna('')
test['text'] = test['title'].fillna('') + ' ' +  test['author'].fillna('') + ' ' + test['abstract'].fillna('')

vector = CountVectorizer().fit(train['text'])
train_vector = vector.transform(train['text'])
test_vector = vector.transform(test['text'])


# 引入模型
model = LogisticRegression()

# 开始训练,这里可以考虑修改默认的batch_size与epoch来取得更好的效果
model.fit(train_vector, train['label'])

# 利用模型对测试集label标签进行预测
test['label'] = model.predict(test_vector)
test['Keywords'] = test['title'].fillna('')
test[['uuid','Keywords','label']].to_csv('submit_task1.csv', index=None)

ndarray.finall()方法:填充空值

pandas数据处理常用命令_ndarray fillna_hellosc01的博客-CSDN博客

Basedline的方法:BOW词袋提取特征-LR逻辑回归-进行预测

改进方法:TF-IDF,SVM,epoches

python 复制代码
# TfidfVectorizer(TF-IDF(词频-逆文档频率))
from sklearn.feature_extraction.text import TfidfVectorizer
python 复制代码
# 导入支持向量机分类器
from sklearn.svm import SVC

#创建SVM训练模型 
model = SVC(kernel='linear', C=1)

# 利用模型对测试集label标签进行预测
test['label'] = model.predict(test_vector)
test['Keywords'] = test['title'].fillna('')
test[['uuid','Keywords','label']].to_csv('submit_task2.csv', index=None)

by ライト

相关推荐
d0ublεU0x0017 小时前
task06大模型量化与训练
nlp·transformer
玄同7651 天前
LangChain 核心组件全解析:构建大模型应用的 “乐高积木”
人工智能·python·语言模型·langchain·llm·nlp·知识图谱
玄同7652 天前
大模型生成 Token 的原理:从文本到模型理解的 “翻译官”
人工智能·python·语言模型·自然语言处理·nlp·知识图谱·token
天天代码码天天2 天前
lw.PPOCRSharp_GPU_Test paddle_inference v3.3
人工智能·深度学习·paddle
aiguangyuan3 天前
从零实现循环神经网络:中文情感分析的完整实践指南
人工智能·python·nlp
aiguangyuan3 天前
从词袋到TF-IDF:sklearn文本特征工程实战指南
人工智能·python·nlp
aiguangyuan4 天前
从零构建字符级RNN:用PyTorch实现莎士比亚风格文本生成
人工智能·python·nlp
weixin_462446234 天前
使用 PaddleOCR + 多进程 + GPU 加速实现 PDF 可搜索化(支持中英文、竖排/旋转文字)
pdf·paddle·识别
缘友一世4 天前
ROUGE和困惑度评估指标学习和体验
llm·nlp·模型评估指标
aiguangyuan4 天前
词向量的艺术:从Word2Vec到GloVe的完整实践指南
人工智能·python·nlp